FOSSology  4.6.0
Open Source License Compliance by Open Source Software
ajax-schedule-agent.php
1 <?php
2 
4 use Symfony\Component\HttpFoundation\Response;
6 /*
7  SPDX-FileCopyrightText: © 2014 Hewlett-Packard Development Company, L.P.
8 
9  SPDX-License-Identifier: GPL-2.0-only
10 */
11 
19 define("TITLE_AJAX_SCHEDULE_AGENT", _("Schedule agent"));
20 
26 {
27  private $uploadDao;
28  function __construct()
29  {
30  $this->Name = "schedule_agent";
31  $this->Title = TITLE_AJAX_SCHEDULE_AGENT;
32  $this->DBaccess = PLUGIN_DB_READ;
33  parent::__construct();
34  $this->uploadDao = $GLOBALS['container']->get('dao.upload');
35  }
36 
37 
41  public function Output()
42  {
43  global $Plugins;
44  $UploadPk = GetParm("upload",PARM_INTEGER);
45  $Agent = GetParm("agent",PARM_STRING);
46  if (empty($UploadPk) || empty($Agent)) {
47  return new Response('missing parameter', Response::HTTP_BAD_REQUEST,
48  array('Content-type' => 'text/plain'));
49  }
50  $upload = $this->uploadDao->getUpload($UploadPk);
51  if ($upload === null) {
52  $errMsg = __FILE__ . ":" . __LINE__ . " " . _("Upload") . " " . $UploadPk .
53  " " . _("not found");
54  return new Response($errMsg, Response::HTTP_BAD_REQUEST,
55  array('Content-type' => 'text/plain'));
56  }
57  $ShortName = $upload->getFilename();
58  $user_pk = Auth::getUserId();
59  $group_pk = Auth::getGroupId();
60  $job_pk = JobAddJob($user_pk, $group_pk, $ShortName, $UploadPk);
61 
62  $Dependencies = array();
63  $P = &$Plugins[plugin_find_id($Agent)];
64  $rv = $P->AgentAdd($job_pk, $UploadPk, $ErrorMsg, $Dependencies);
65  if ($rv <= 0) {
66  $text = _("Scheduling of Agent(s) failed: ");
67  return new Response($text . $rv . $ErrorMsg, Response::HTTP_BAD_REQUEST,
68  array('Content-type' => 'text/plain'));
69  }
70 
72  $status = GetRunnableJobList();
73  $scheduler_msg = "";
74  if (empty($status)) {
75  $scheduler_msg .= _("Is the scheduler running? ");
76  }
77 
78  $URL = Traceback_uri() . "?mod=showjobs&upload=$UploadPk";
79  /* Need to refresh the screen */
80  $text = _("Your jobs have been added to job queue.");
81  $LinkText = _("View Jobs");
82  $msg = "$scheduler_msg"."$text <a href=$URL>$LinkText</a>";
83  $this->vars['message'] = $msg;
84  return new Response($msg, Response::HTTP_OK, array('Content-type'=>'text/plain'));
85  }
86 }
87 
88 $NewPlugin = new ajax_schedule_agent;
89 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:57
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
__construct()
base constructor. Most plugins will just use this
Output()
Display the loaded menu and plugins.
Traceback_uri()
Get the URI without query to this location.
Definition: common-parm.php:97
const PARM_INTEGER
Definition: common-parm.php:14
const PARM_STRING
Definition: common-parm.php:18
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:46
GetRunnableJobList()
Get runnable job list, the process is below:
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
Definition: libfossology.h:37