FOSSology  4.4.0
Open Source License Compliance by Open Source Software
agent-bucket.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2010-2013 Hewlett-Packard Development Company, L.P.
4  SPDX-FileCopyrightText: © 2015 Siemens AG
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
13 
15 {
17  private $bucketDesc = "Performs grouping based on different needs. you can group licenses as 'Good Licenses', 'Academic Licenses', 'Copyleft Licenses' etc. One can also group files by copyright holder, or by file-type, or files without my copyright.
18  Note: There is no FOSSology UI to create bucket pools, bucket definitions, scripts, or anything else you need.";
19 
20  public function __construct() {
21  $this->Name = "agent_bucket";
22  $this->Title = _("Bucket Analysis <img src=\"images/info_16.png\" data-toggle=\"tooltip\" title=\"".$this->bucketDesc."\" class=\"info-bullet\"/>");
23  $this->AgentName = "buckets";
24 
25  parent::__construct();
26  }
27 
32  protected function getDefaultBucketPool()
33  {
34  $user_pk = Auth::getUserId();
35  if (empty($user_pk)) {
36  return 0;
37  }
38 
40  $dbManager = $GLOBALS['container']->get('db.manager');
41  $usersRec = $dbManager->getSingleRow('SELECT default_bucketpool_fk FROM users WHERE user_pk=$1', array($user_pk));
42  return $usersRec['default_bucketpool_fk'];
43  }
44 
50  function preInstall()
51  {
52  $bucketPool = $this->getDefaultBucketPool();
53  if (!empty($bucketPool))
54  {
55  menu_insert("Agents::" . $this->Title, 0, $this->Name);
56  }
57  }
58 
63  public function AgentHasResults($uploadId=0)
64  {
65  $default_bucketpool_fk = $this->getDefaultBucketPool();
66  if (empty($default_bucketpool_fk)) {
67  return 0;
68  }
69  /* @var $agentDao AgentDao */
70  $agentDao = $GLOBALS['container']->get('dao.agent');
71  $latestNomosAgentId = $agentDao->getCurrentAgentId("nomos", "Nomos license scanner");
72  if (empty($latestNomosAgentId)) {
73  return 0;
74  }
75  $latestBucketAgentId = $agentDao->getCurrentAgentId($this->AgentName, "Bucket scanner");
76  if (empty($latestBucketAgentId)) {
77  return 0;
78  }
79  /* @var $dbManager DbManager */
80  $dbManager = $GLOBALS['container']->get('db.manager');
81 
82  $bucketLatestArsRec = $dbManager->getSingleRow("SELECT * FROM bucket_ars WHERE bucketpool_fk=$1 AND upload_fk=$2 AND nomosagent_fk=$3 and agent_fk=$4 AND ars_success=$5",
83  array($default_bucketpool_fk,$uploadId,$latestNomosAgentId,$latestBucketAgentId,$dbManager->booleanToDb(true)),
84  __METHOD__.'.latestNomosAndBucketScannedThisPool');
85  if (!empty($bucketLatestArsRec)) return 1;
86 
87  $bucketOldArsRec = $dbManager->getSingleRow("SELECT * FROM bucket_ars WHERE bucketpool_fk=$1 AND upload_fk=$2 AND ars_success=$3",
88  array($default_bucketpool_fk,$uploadId,$dbManager->booleanToDb(true)),
89  __METHOD__.'.anyBucketScannedThisPool');
90  if (!empty($bucketOldArsRec)) return 2;
91 
92  return 0;
93  }
94 
99  public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=[],
100  $arguments=null, $request=null, $unpackArgs=null)
101  {
102  $default_bucketpool_fk = $this->getDefaultBucketPool();
103  if (!$default_bucketpool_fk)
104  {
105  $errorMsg = _("User does not have a default bucketpool. Bucket agent cannot be scheduled without this.");
106  return (-1);
107  }
108 
109  $dependencies[] = "agent_nomos";
110  $dependencies[] = "agent_pkgagent";
111  $jqargs = "bppk=$default_bucketpool_fk, upk=$uploadId";
112  return $this->doAgentAdd($jobId, $uploadId, $errorMsg, $dependencies,
113  $jqargs, null, $request);
114  }
115 }
116 
117 register_plugin(new BucketAgentPlugin());
AgentHasResults($uploadId=0)
AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=[], $arguments=null, $request=null, $unpackArgs=null)
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
doAgentAdd($jobId, $uploadId, &$errorMsg, $dependencies, $jqargs="", $jq_cmd_args=null, $request=null)
menu_insert($Path, $LastOrder=0, $URI=NULL, $Title=NULL, $Target=NULL, $HTML=NULL)
Given a Path, order level for the last item, and optional plugin name, insert the menu item.