FOSSology  4.4.0
Open Source License Compliance by Open Source Software
agent_adj2nest.php
Go to the documentation of this file.
1 <?php
2 /*
3 SPDX-FileCopyrightText: © 2012-2013 Hewlett-Packard Development Company, L.P.
4 SPDX-FileCopyrightText: © 2015 Siemens AG
5 
6 SPDX-License-Identifier: GPL-2.0-only
7 */
8 
10 
21 {
22  public function __construct() {
23  $this->Name = "agent_adj2nest";
24  $this->Title = 'adj2nest';
25  $this->AgentName = "adj2nest";
26 
27  parent::__construct();
28  }
29 
34  function AgentHasResults($uploadId=0)
35  {
36  $dbManager = $GLOBALS['container']->get('db.manager');
37 
38  $uploadtree_tablename = GetUploadtreeTableName($uploadId);
39  if (NULL == $uploadtree_tablename) strcpy($uploadtree_tablename, "uploadtree");
40 
41  /* see if the latest nomos and bucket agents have scaned this upload for this bucketpool */
42  $uploadtreeRec = $dbManager->getSingleRow("SELECT * FROM $uploadtree_tablename WHERE upload_fk=$1 and lft is not null",
43  array($uploadId),__METHOD__.'.lftNotSet');
44  if (empty($uploadtreeRec))
45  {
46  return 0;
47  }
48 
49  $stmt = __METHOD__.$uploadtree_tablename;
50  $sql = "SELECT parent,lft FROM $uploadtree_tablename WHERE upload_fk=$1 ORDER BY parent, ufile_mode&(1<<29) DESC, ufile_name";
51  $dbManager->prepare($stmt,$sql);
52  $res=$dbManager->execute($stmt,array($uploadId));
53  $prevRow = array('parent'=>0,'lft'=>0);
54  $wrongOrder = false;
55  while($row=$dbManager->fetchArray($res))
56  {
57  $wrongOrder = $prevRow['parent']==$row['parent'] && $prevRow['lft']>$row['lft'];
58  if ($wrongOrder) {
59  break;
60  }
61  $prevRow = $row;
62  }
63  $dbManager->freeResult($res);
64  return $wrongOrder ? 2 : 1;
65  }
66 
71  public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=array(), $arguments=null, $unpackArgs=null)
72  {
73  if ($this->AgentHasResults($uploadId) == 1)
74  {
75  return 0;
76  }
77 
78  $jobQueueId = \IsAlreadyScheduled($jobId, $this->AgentName, $uploadId);
79  if ($jobQueueId != 0)
80  {
81  return $jobQueueId;
82  }
83 
84  if (!$this->isAgentIncluded($dependencies, 'agent_unpack')) {
85  $dependencies[] = array('name' => "agent_unpack", 'args' => $unpackArgs);
86  }
87  $args = is_array($arguments) ? '' : $arguments;
88  return $this->doAgentAdd($jobId, $uploadId, $errorMsg, $dependencies, $uploadId, $args);
89  }
90 
97  protected function isAgentIncluded($dependencies, $agentName)
98  {
99  foreach($dependencies as $dependency)
100  {
101  if ($dependency == $agentName)
102  {
103  return true;
104  }
105  if (is_array($dependency) && $agentName == $dependency['name'])
106  {
107  return true;
108  }
109  }
110  return false;
111  }
112 }
113 
114 register_plugin(new Adj2nestAgentPlugin());
AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=array(), $arguments=null, $unpackArgs=null)
isAgentIncluded($dependencies, $agentName)
AgentHasResults($uploadId=0)
doAgentAdd($jobId, $uploadId, &$errorMsg, $dependencies, $jqargs="", $jq_cmd_args=null)
IsAlreadyScheduled($job_pk, $AgentName, $upload_pk)
Check if an agent is already scheduled in a job.
Definition: common-job.php:378
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:414