FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ajax-upload-agents.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2008-2011 Hewlett-Packard Development Company, L.P.
4  Copyright (C) 2015 Siemens AG
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 ***********************************************************/
19 
25 
36 {
37  const NAME = "upload_agent_options";
38 
39  public function __construct()
40  {
41  parent::__construct(self::NAME, array(
42  self::TITLE => _("List Agents for an Upload as Options"),
43  self::PERMISSION => Auth::PERM_READ
44  ));
45  }
46 
54  function jobNotYetScheduled($agentName, $uploadId)
55  {
56  $sql = "select count(*) from job inner join jobqueue on job_pk=jq_job_fk "
57  . "where job_upload_fk=$1 and jq_endtext is null and jq_type=$2";
58  $queued = $GLOBALS['container']->get('db.manager')->getSingleRow($sql,array($uploadId,$agentName));
59  return $queued['count']==0;
60  }
61 
62  protected function handle(Request $request)
63  {
64  $uploadId = intval($request->get("upload"));
65  if (empty($uploadId)) {
66  throw new Exception('missing upload id');
67  }
68 
69  $parmAgentList = MenuHook::getAgentPluginNames("ParmAgents");
70  $plainAgentList = MenuHook::getAgentPluginNames("Agents");
71  $agentList = array_merge($plainAgentList, $parmAgentList);
72  $skipAgents = array("agent_unpack", "wget_agent");
73  $out = "";
74  $relevantAgents = array();
75  foreach ($agentList as $agent) {
76  if (array_search($agent, $skipAgents) !== false) {
77  continue;
78  }
79  $plugin = plugin_find($agent);
80  if (($plugin->AgentHasResults($uploadId) != 1) &&
81  $this->jobNotYetScheduled($plugin->AgentName, $uploadId)) {
82  $out .= "<option value='" . $agent . "'>";
83  $out .= htmlentities($plugin->Title);
84  $out .= "</option>\n";
85  $relevantAgents[$agent] = $plugin->Title;
86  }
87  }
88 
89  $out = '<select multiple size="10" id="agents" name="agents[]">' .$out. '</select>';
90  return new Response($out, Response::HTTP_OK, array('Content-Type'=>'text/plain'));
91  }
92 }
93 
94 register_plugin(new AjaxUploadAgents());
jobNotYetScheduled($agentName, $uploadId)
This function checks if the current job was not already scheduled, or did already fail (You can resch...
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
#define PERM_READ
Read-only permission.
Definition: libfossology.h:44