FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ajax-schedule-agent.php
1 <?php
2 
4 use Symfony\Component\HttpFoundation\Response;
5 /*
6  SPDX-FileCopyrightText: © 2014 Hewlett-Packard Development Company, L.P.
7 
8  SPDX-License-Identifier: GPL-2.0-only
9 */
10 
18 define("TITLE_AJAX_SCHEDULE_AGENT", _("Schedule agent"));
19 
25 {
26  function __construct()
27  {
28  $this->Name = "schedule_agent";
29  $this->Title = TITLE_AJAX_SCHEDULE_AGENT;
30  $this->DBaccess = PLUGIN_DB_READ;
31  parent::__construct();
32  }
33 
34 
38  public function Output()
39  {
40  global $Plugins;
41  global $PG_CONN;
42  $UploadPk = GetParm("upload",PARM_INTEGER);
43  $Agent = GetParm("agent",PARM_STRING);
44  if (empty($UploadPk) || empty($Agent)) {
45  return new Response('missing parameter', Response::HTTP_BAD_REQUEST,
46  array('Content-type' => 'text/plain'));
47  }
48  $sql = "SELECT upload_pk, upload_filename FROM upload WHERE upload_pk = '$UploadPk'";
49  $result = pg_query($PG_CONN, $sql);
50  DBCheckResult($result, $sql, __FILE__, __LINE__);
51  if (pg_num_rows($result) < 1) {
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  $UploadRow = pg_fetch_assoc($result);
58  $ShortName = $UploadRow['upload_filename'];
59  pg_free_result($result);
60 
61  $user_pk = Auth::getUserId();
62  $group_pk = Auth::getGroupId();
63  $job_pk = JobAddJob($user_pk, $group_pk, $ShortName, $UploadPk);
64 
65  $Dependencies = array();
66  $P = &$Plugins[plugin_find_id($Agent)];
67  $rv = $P->AgentAdd($job_pk, $UploadPk, $ErrorMsg, $Dependencies);
68  if ($rv <= 0) {
69  $text = _("Scheduling of Agent(s) failed: ");
70  return new Response($text . $rv . $ErrorMsg, Response::HTTP_BAD_REQUEST,
71  array('Content-type' => 'text/plain'));
72  }
73 
75  $status = GetRunnableJobList();
76  $scheduler_msg = "";
77  if (empty($status)) {
78  $scheduler_msg .= _("Is the scheduler running? ");
79  }
80 
81  $URL = Traceback_uri() . "?mod=showjobs&upload=$UploadPk";
82  /* Need to refresh the screen */
83  $text = _("Your jobs have been added to job queue.");
84  $LinkText = _("View Jobs");
85  $msg = "$scheduler_msg"."$text <a href=$URL>$LinkText</a>";
86  $this->vars['message'] = $msg;
87  return new Response($msg, Response::HTTP_OK, array('Content-type'=>'text/plain'));
88  }
89 }
90 
91 $NewPlugin = new ajax_schedule_agent;
92 $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.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:187
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
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN