FOSSology  4.4.0
Open Source License Compliance by Open Source Software
agent-ojos.php
1 <?php
2 # SPDX-FileCopyrightText: © 2019 Siemens AG
3 
4 # SPDX-License-Identifier: GPL-2.0-only
5 
6 namespace Fossology\Ojo\Ui;
7 
9 
11 {
13  private $ojoDesc = "Scan files for licenses using SPDX-License-Identifier";
14 
15  public function __construct()
16  {
17  $this->Name = "agent_ojo";
18  $this->Title = _("Ojo License Analysis <img src=\"images/info_16.png\" data-toggle=\"tooltip\" title=\"".$this->ojoDesc."\" class=\"info-bullet\"/>");
19  $this->AgentName = "ojo";
20 
21  parent::__construct();
22  }
23 
24  function AgentHasResults($uploadId=0)
25  {
26  return CheckARS($uploadId, $this->AgentName, "ojo agent", "ojo_ars");
27  }
28 
33  public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=[],
34  $arguments=null, $request=null, $unpackArgs=null)
35  {
36  if ($request != null && !is_array($request)) {
37  $unpackArgs = intval($request->get('scm', 0)) == 1 ? '-I' : '';
38  } else {
39  $unpackArgs = intval(@$_POST['scm']) == 1 ? '-I' : '';
40  }
41  if ($this->AgentHasResults($uploadId) == 1) {
42  return 0;
43  }
44 
45  $jobQueueId = \IsAlreadyScheduled($jobId, $this->AgentName, $uploadId);
46  if ($jobQueueId != 0) {
47  return $jobQueueId;
48  }
49 
50  $args = $unpackArgs;
51  if (!empty($unpackArgs)) {
52  return $this->doAgentAdd($jobId, $uploadId, $errorMsg, array("agent_mimetype"),$uploadId,$args,$request);
53  } else {
54  return $this->doAgentAdd($jobId, $uploadId, $errorMsg, array("agent_adj2nest"), $uploadId, null, $request);
55  }
56  }
57 
64  protected function isAgentIncluded($dependencies, $agentName)
65  {
66  foreach ($dependencies as $dependency) {
67  if ($dependency == $agentName) {
68  return true;
69  }
70  if (is_array($dependency) && $agentName == $dependency['name']) {
71  return true;
72  }
73  }
74  return false;
75  }
76 }
77 register_plugin(new OjosAgentPlugin());
doAgentAdd($jobId, $uploadId, &$errorMsg, $dependencies, $jqargs="", $jq_cmd_args=null, $request=null)
isAgentIncluded($dependencies, $agentName)
Definition: agent-ojos.php:64
AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=[], $arguments=null, $request=null, $unpackArgs=null)
Definition: agent-ojos.php:33
CheckARS($upload_pk, $AgentName, $AgentDesc, $AgentARSTableName)
Check the ARS table to see if an agent has successfully scanned an upload.
IsAlreadyScheduled($job_pk, $AgentName, $upload_pk)
Check if an agent is already scheduled in a job.
Definition: common-job.php:378