FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ajax-upload-agents.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008-2011 Hewlett-Packard Development Company, L.P.
4  SPDX-FileCopyrightText: © 2015 Siemens AG
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
12 use Symfony\Component\HttpFoundation\Request;
13 use Symfony\Component\HttpFoundation\Response;
14 
25 {
26  const NAME = "upload_agent_options";
27 
28  public function __construct()
29  {
30  parent::__construct(self::NAME, array(
31  self::TITLE => _("List Agents for an Upload as Options"),
32  self::PERMISSION => Auth::PERM_READ
33  ));
34  }
35 
43  function jobNotYetScheduled($agentName, $uploadId)
44  {
45  $sql = "select count(*) from job inner join jobqueue on job_pk=jq_job_fk "
46  . "where job_upload_fk=$1 and jq_endtext is null and jq_type=$2";
47  $queued = $GLOBALS['container']->get('db.manager')->getSingleRow($sql,array($uploadId,$agentName));
48  return $queued['count']==0;
49  }
50 
51  protected function handle(Request $request)
52  {
53  $uploadId = intval($request->get("upload"));
54  if (empty($uploadId)) {
55  throw new Exception('missing upload id');
56  }
57 
58  $parmAgentList = MenuHook::getAgentPluginNames("ParmAgents");
59  $plainAgentList = MenuHook::getAgentPluginNames("Agents");
60  $agentList = array_merge($plainAgentList, $parmAgentList);
61  $skipAgents = array("agent_unpack", "wget_agent");
62  $out = "";
63  $relevantAgents = array();
64  foreach ($agentList as $agent) {
65  if (array_search($agent, $skipAgents) !== false) {
66  continue;
67  }
68  $plugin = plugin_find($agent);
69  if (($plugin->AgentHasResults($uploadId) != 1) &&
70  $this->jobNotYetScheduled($plugin->AgentName, $uploadId)) {
71  $out .= "<option value='" . $agent . "'>";
72  $out .= htmlentities($plugin->Title);
73  $out .= "</option>\n";
74  $relevantAgents[$agent] = $plugin->Title;
75  }
76  }
77 
78  $out = '<select multiple size="10" id="agents" name="agents[]">' .$out. '</select>';
79  return new Response($out, Response::HTTP_OK, array('Content-Type'=>'text/plain'));
80  }
81 }
82 
83 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...
handle(Request $request)
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
#define PERM_READ
Read-only permission.
Definition: libfossology.h:32