FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ajax-schedule-agent.php
1 <?php
2 
5 /***********************************************************
6  Copyright (C) 2014 Hewlett-Packard Development Company, L.P.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  version 2 as published by the Free Software Foundation.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 ***********************************************************/
21 
29 define("TITLE_AJAX_SCHEDULE_AGENT", _("Schedule agent"));
30 
36 {
37  function __construct()
38  {
39  $this->Name = "schedule_agent";
40  $this->Title = TITLE_AJAX_SCHEDULE_AGENT;
41  $this->DBaccess = PLUGIN_DB_READ;
42  parent::__construct();
43  }
44 
45 
49  public function Output()
50  {
51  global $Plugins;
52  global $PG_CONN;
53  $UploadPk = GetParm("upload",PARM_INTEGER);
54  $Agent = GetParm("agent",PARM_STRING);
55  if (empty($UploadPk) || empty($Agent)) {
56  return new Response('missing parameter', Response::HTTP_BAD_REQUEST,
57  array('Content-type' => 'text/plain'));
58  }
59  $sql = "SELECT upload_pk, upload_filename FROM upload WHERE upload_pk = '$UploadPk'";
60  $result = pg_query($PG_CONN, $sql);
61  DBCheckResult($result, $sql, __FILE__, __LINE__);
62  if (pg_num_rows($result) < 1) {
63  $errMsg = __FILE__ . ":" . __LINE__ . " " . _("Upload") . " " . $UploadPk .
64  " " . _("not found");
65  return new Response($errMsg, Response::HTTP_BAD_REQUEST,
66  array('Content-type' => 'text/plain'));
67  }
68  $UploadRow = pg_fetch_assoc($result);
69  $ShortName = $UploadRow['upload_filename'];
70  pg_free_result($result);
71 
72  $user_pk = Auth::getUserId();
73  $group_pk = Auth::getGroupId();
74  $job_pk = JobAddJob($user_pk, $group_pk, $ShortName, $UploadPk);
75 
76  $Dependencies = array();
77  $P = &$Plugins[plugin_find_id($Agent)];
78  $rv = $P->AgentAdd($job_pk, $UploadPk, $ErrorMsg, $Dependencies);
79  if ($rv <= 0) {
80  $text = _("Scheduling of Agent(s) failed: ");
81  return new Response($text . $rv . $ErrorMsg, Response::HTTP_BAD_REQUEST,
82  array('Content-type' => 'text/plain'));
83  }
84 
86  $status = GetRunnableJobList();
87  $scheduler_msg = "";
88  if (empty($status)) {
89  $scheduler_msg .= _("Is the scheduler running? ");
90  }
91 
92  $URL = Traceback_uri() . "?mod=showjobs&upload=$UploadPk";
93  /* Need to refresh the screen */
94  $text = _("Your jobs have been added to job queue.");
95  $LinkText = _("View Jobs");
96  $msg = "$scheduler_msg"."$text <a href=$URL>$LinkText</a>";
97  $this->vars['message'] = $msg;
98  return new Response($msg, Response::HTTP_OK, array('Content-type'=>'text/plain'));
99  }
100 }
101 
102 $NewPlugin = new ajax_schedule_agent;
103 $NewPlugin->Initialize();
GetRunnableJobList()
Get runnable job list, the process is below:
Traceback_uri()
Get the URI without query to this location.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
Definition: libfossology.h:49
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
const PARM_STRING
Definition: common-parm.php:29
const PARM_INTEGER
Definition: common-parm.php:25
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67
Output()
Display the loaded menu and plugins.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:198