FOSSology  4.4.0
Open Source License Compliance by Open Source Software
agent-compatibility.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2024 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Compatibility\Ui;
9 
11 use Symfony\Component\HttpFoundation\Request;
12 
13 define("AGENT_COMPATIBILITY_NAME", "compatibility");
14 
16 {
18  private $compDesc = "Checks licenses found in a file and main license and " .
19  "adds red highlight to tree view if licenses fail compatibility rules";
20 
21  public function __construct()
22  {
23  $this->Name = "agent_compatibility";
24  $this->Title = _("Compatibility License Analysis, scanning for licenses " .
25  "compatibility <img src=\"images/info_16.png\" data-toggle=\"tooltip\"" .
26  " title=\"".$this->compDesc."\" class=\"info-bullet\"/>");
27  $this->AgentName = AGENT_COMPATIBILITY_NAME;
28 
29  parent::__construct();
30  }
31 
32  public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies = [],
33  $arguments = null, $request = null, $unpackArgs = null)
34  {
35  if ($this->AgentHasResults($uploadId) == 1) {
36  return 0;
37  }
38 
39  $compatibilityDependencies = array("agent_adj2nest");
40 
41  if ($request == null) {
42  $request = $_POST;
43  }
44  $compatibilityDependencies = array_merge($compatibilityDependencies,
45  $this->getCompatibilityDependencies($request));
46 
47  $jobQueueId = \IsAlreadyScheduled($jobId, $this->AgentName, $uploadId);
48  if ($jobQueueId != 0) {
49  return $jobQueueId;
50  }
51 
52  return $this->doAgentAdd($jobId, $uploadId, $errorMsg,
53  array_unique($compatibilityDependencies), $arguments, null, $request);
54  }
55 
56  function AgentHasResults($uploadId = 0)
57  {
58  return CheckARS($uploadId, $this->AgentName, "compatibility agent", "compatibility_ars");
59  }
60 
65  private function getCompatibilityDependencies($request)
66  {
67  $dependencies = array();
68  if (is_object($request)) {
69  $postEmulate = [];
70  $postEmulate["Check_agent_nomos"] = intval($request->get(
71  "Check_agent_nomos", 0));
72  $postEmulate["Check_agent_monk"] = intval($request->get(
73  "Check_agent_monk", 0));
74  $postEmulate["Check_agent_ojo"] = intval($request->get(
75  "Check_agent_ojo", 0));
76  $postEmulate["Check_agent_ninka"] = intval($request->get(
77  "Check_agent_ninka", 0));
78  $request = $postEmulate;
79  }
80  if (array_key_exists("Check_agent_nomos", $request) && $request["Check_agent_nomos"] == 1) {
81  $dependencies[] = "agent_nomos";
82  }
83  if (array_key_exists("Check_agent_monk", $request) && $request["Check_agent_monk"] == 1) {
84  $dependencies[] = "agent_monk";
85  }
86  if (array_key_exists("Check_agent_ojo", $request) && $request["Check_agent_ojo"] == 1) {
87  $dependencies[] = "agent_ojo";
88  }
89  if (array_key_exists("Check_agent_ninka", $request) && $request["Check_agent_ninka"] == 1) {
90  $dependencies[] = "agent_ninka";
91  }
92 
93  return $dependencies;
94  }
95 }
96 
97 register_plugin(new CompatibilityAgentPlugin());
AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=[], $arguments=null, $request=null, $unpackArgs=null)
doAgentAdd($jobId, $uploadId, &$errorMsg, $dependencies, $jqargs="", $jq_cmd_args=null, $request=null)
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