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 {
16  public function __construct() {
17  $this->Name = "agent_bucket";
18  $this->Title = _("Bucket Analysis");
19  $this->AgentName = "buckets";
20 
21  parent::__construct();
22  }
23 
28  protected function getDefaultBucketPool()
29  {
30  $user_pk = Auth::getUserId();
31  if (empty($user_pk)) {
32  return 0;
33  }
34 
36  $dbManager = $GLOBALS['container']->get('db.manager');
37  $usersRec = $dbManager->getSingleRow('SELECT default_bucketpool_fk FROM users WHERE user_pk=$1', array($user_pk));
38  return $usersRec['default_bucketpool_fk'];
39  }
40 
46  function preInstall()
47  {
48  $bucketPool = $this->getDefaultBucketPool();
49  if (!empty($bucketPool))
50  {
51  menu_insert("Agents::" . $this->Title, 0, $this->Name);
52  }
53  }
54 
59  public function AgentHasResults($uploadId=0)
60  {
61  $default_bucketpool_fk = $this->getDefaultBucketPool();
62  if (empty($default_bucketpool_fk)) {
63  return 0;
64  }
65  /* @var $agentDao AgentDao */
66  $agentDao = $GLOBALS['container']->get('dao.agent');
67  $latestNomosAgentId = $agentDao->getCurrentAgentId("nomos", "Nomos license scanner");
68  if (empty($latestNomosAgentId)) {
69  return 0;
70  }
71  $latestBucketAgentId = $agentDao->getCurrentAgentId($this->AgentName, "Bucket scanner");
72  if (empty($latestBucketAgentId)) {
73  return 0;
74  }
75  /* @var $dbManager DbManager */
76  $dbManager = $GLOBALS['container']->get('db.manager');
77 
78  $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",
79  array($default_bucketpool_fk,$uploadId,$latestNomosAgentId,$latestBucketAgentId,$dbManager->booleanToDb(true)),
80  __METHOD__.'.latestNomosAndBucketScannedThisPool');
81  if (!empty($bucketLatestArsRec)) return 1;
82 
83  $bucketOldArsRec = $dbManager->getSingleRow("SELECT * FROM bucket_ars WHERE bucketpool_fk=$1 AND upload_fk=$2 AND ars_success=$3",
84  array($default_bucketpool_fk,$uploadId,$dbManager->booleanToDb(true)),
85  __METHOD__.'.anyBucketScannedThisPool');
86  if (!empty($bucketOldArsRec)) return 2;
87 
88  return 0;
89  }
90 
95  public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=array(), $arguments=null)
96  {
97  $default_bucketpool_fk = $this->getDefaultBucketPool();
98  if (!$default_bucketpool_fk)
99  {
100  $errorMsg = _("User does not have a default bucketpool. Bucket agent cannot be scheduled without this.");
101  return (-1);
102  }
103 
104  $dependencies[] = "agent_nomos";
105  $dependencies[] = "agent_pkgagent";
106  $jqargs = "bppk=$default_bucketpool_fk, upk=$uploadId";
107  return $this->doAgentAdd($jobId, $uploadId, $errorMsg, $dependencies, $jqargs);
108  }
109 }
110 
111 register_plugin(new BucketAgentPlugin());
AgentHasResults($uploadId=0)
AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=array(), $arguments=null)
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
doAgentAdd($jobId, $uploadId, &$errorMsg, $dependencies, $jqargs="", $jq_cmd_args=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.