FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
agent-bucket.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2010-2013 Hewlett-Packard Development Company, L.P.
4  Copyright (C) 2015 Siemens AG
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 ***********************************************************/
19 
24 
26 {
27  public function __construct() {
28  $this->Name = "agent_bucket";
29  $this->Title = _("Bucket Analysis");
30  $this->AgentName = "buckets";
31 
32  parent::__construct();
33  }
34 
39  protected function getDefaultBucketPool()
40  {
41  $user_pk = Auth::getUserId();
42  if (empty($user_pk)) {
43  return 0;
44  }
45 
47  $dbManager = $GLOBALS['container']->get('db.manager');
48  $usersRec = $dbManager->getSingleRow('SELECT default_bucketpool_fk FROM users WHERE user_pk=$1', array($user_pk));
49  return $usersRec['default_bucketpool_fk'];
50  }
51 
57  function preInstall()
58  {
59  $bucketPool = $this->getDefaultBucketPool();
60  if (!empty($bucketPool))
61  {
62  menu_insert("Agents::" . $this->Title, 0, $this->Name);
63  }
64  }
65 
70  public function AgentHasResults($uploadId=0)
71  {
72  $default_bucketpool_fk = $this->getDefaultBucketPool();
73  if (empty($default_bucketpool_fk)) {
74  return 0;
75  }
76  /* @var $agentDao AgentDao */
77  $agentDao = $GLOBALS['container']->get('dao.agent');
78  $latestNomosAgentId = $agentDao->getCurrentAgentId("nomos", "Nomos license scanner");
79  if (empty($latestNomosAgentId)) {
80  return 0;
81  }
82  $latestBucketAgentId = $agentDao->getCurrentAgentId($this->AgentName, "Bucket scanner");
83  if (empty($latestBucketAgentId)) {
84  return 0;
85  }
86  /* @var $dbManager DbManager */
87  $dbManager = $GLOBALS['container']->get('db.manager');
88 
89  $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",
90  array($default_bucketpool_fk,$uploadId,$latestNomosAgentId,$latestBucketAgentId,$dbManager->booleanToDb(true)),
91  __METHOD__.'.latestNomosAndBucketScannedThisPool');
92  if (!empty($bucketLatestArsRec)) return 1;
93 
94  $bucketOldArsRec = $dbManager->getSingleRow("SELECT * FROM bucket_ars WHERE bucketpool_fk=$1 AND upload_fk=$2 AND ars_success=$3",
95  array($default_bucketpool_fk,$uploadId,$dbManager->booleanToDb(true)),
96  __METHOD__.'.anyBucketScannedThisPool');
97  if (!empty($bucketOldArsRec)) return 2;
98 
99  return 0;
100  }
101 
106  public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=array(), $arguments=null)
107  {
108  $default_bucketpool_fk = $this->getDefaultBucketPool();
109  if (!$default_bucketpool_fk)
110  {
111  $errorMsg = _("User does not have a default bucketpool. Bucket agent cannot be scheduled without this.");
112  return (-1);
113  }
114 
115  $dependencies[] = "agent_nomos";
116  $dependencies[] = "agent_pkgagent";
117  $jqargs = "bppk=$default_bucketpool_fk, upk=$uploadId";
118  return $this->doAgentAdd($jobId, $uploadId, $errorMsg, $dependencies, $jqargs);
119  }
120 }
121 
122 register_plugin(new BucketAgentPlugin());
AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=array(), $arguments=null)
AgentHasResults($uploadId=0)
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...
doAgentAdd($jobId, $uploadId, &$errorMsg, $dependencies, $jqargs="", $jq_cmd_args=null)