FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
agent_adj2nest.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2012-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 
21 
32 {
33  public function __construct() {
34  $this->Name = "agent_adj2nest";
35  $this->Title = 'adj2nest';
36  $this->AgentName = "adj2nest";
37 
38  parent::__construct();
39  }
40 
45  function AgentHasResults($uploadId=0)
46  {
47  $dbManager = $GLOBALS['container']->get('db.manager');
48 
49  $uploadtree_tablename = GetUploadtreeTableName($uploadId);
50  if (NULL == $uploadtree_tablename) strcpy($uploadtree_tablename, "uploadtree");
51 
52  /* see if the latest nomos and bucket agents have scaned this upload for this bucketpool */
53  $uploadtreeRec = $dbManager->getSingleRow("SELECT * FROM $uploadtree_tablename WHERE upload_fk=$1 and lft is not null",
54  array($uploadId),__METHOD__.'.lftNotSet');
55  if (empty($uploadtreeRec))
56  {
57  return 0;
58  }
59 
60  $stmt = __METHOD__.$uploadtree_tablename;
61  $sql = "SELECT parent,lft FROM $uploadtree_tablename WHERE upload_fk=$1 ORDER BY parent, ufile_mode&(1<<29) DESC, ufile_name";
62  $dbManager->prepare($stmt,$sql);
63  $res=$dbManager->execute($stmt,array($uploadId));
64  $prevRow = array('parent'=>0,'lft'=>0);
65  $wrongOrder = false;
66  while($row=$dbManager->fetchArray($res))
67  {
68  $wrongOrder = $prevRow['parent']==$row['parent'] && $prevRow['lft']>$row['lft'];
69  if ($wrongOrder) {
70  break;
71  }
72  $prevRow = $row;
73  }
74  $dbManager->freeResult($res);
75  return $wrongOrder ? 2 : 1;
76  }
77 
82  public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=array(), $arguments=null, $unpackArgs=null)
83  {
84  if ($this->AgentHasResults($uploadId) == 1)
85  {
86  return 0;
87  }
88 
89  $jobQueueId = \IsAlreadyScheduled($jobId, $this->AgentName, $uploadId);
90  if ($jobQueueId != 0)
91  {
92  return $jobQueueId;
93  }
94 
95  if (!$this->isAgentIncluded($dependencies, 'agent_unpack')) {
96  $dependencies[] = array('name' => "agent_unpack", 'args' => $unpackArgs);
97  }
98  $args = is_array($arguments) ? '' : $arguments;
99  return $this->doAgentAdd($jobId, $uploadId, $errorMsg, $dependencies, $uploadId, $args);
100  }
101 
108  protected function isAgentIncluded($dependencies, $agentName)
109  {
110  foreach($dependencies as $dependency)
111  {
112  if ($dependency == $agentName)
113  {
114  return true;
115  }
116  if (is_array($dependency) && $agentName == $dependency['name'])
117  {
118  return true;
119  }
120  }
121  return false;
122  }
123 }
124 
125 register_plugin(new Adj2nestAgentPlugin());
FUNCTION char * GetUploadtreeTableName(PGconn *pgConn, int upload_pk)
Get the uploadtree table name for this upload_pk If upload_pk does not exist, return "uploadtree"...
Definition: libfossagent.c:421
IsAlreadyScheduled($job_pk, $AgentName, $upload_pk)
Check if an agent is already scheduled in a job.
Definition: common-job.php:380
isAgentIncluded($dependencies, $agentName)
AgentHasResults($uploadId=0)
AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=array(), $arguments=null, $unpackArgs=null)
doAgentAdd($jobId, $uploadId, &$errorMsg, $dependencies, $jqargs="", $jq_cmd_args=null)