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=[],
72  $arguments=null, $request=null, $unpackArgs=null)
73  {
74  if ($this->AgentHasResults($uploadId) == 1)
75  {
76  return 0;
77  }
78 
79  $jobQueueId = \IsAlreadyScheduled($jobId, $this->AgentName, $uploadId);
80  if ($jobQueueId != 0)
81  {
82  return $jobQueueId;
83  }
84 
85  if (!$this->isAgentIncluded($dependencies, 'agent_unpack')) {
86  $dependencies[] = array('name' => "agent_unpack", 'args' => $unpackArgs);
87  }
88  $args = is_array($arguments) ? '' : $arguments;
89  return $this->doAgentAdd($jobId, $uploadId, $errorMsg, $dependencies,
90  $uploadId, $args, $request);
91  }
92 
99  protected function isAgentIncluded($dependencies, $agentName)
100  {
101  foreach($dependencies as $dependency)
102  {
103  if ($dependency == $agentName)
104  {
105  return true;
106  }
107  if (is_array($dependency) && $agentName == $dependency['name'])
108  {
109  return true;
110  }
111  }
112  return false;
113  }
114 }
115 
116 register_plugin(new Adj2nestAgentPlugin());
isAgentIncluded($dependencies, $agentName)
AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=[], $arguments=null, $request=null, $unpackArgs=null)
AgentHasResults($uploadId=0)
doAgentAdd($jobId, $uploadId, &$errorMsg, $dependencies, $jqargs="", $jq_cmd_args=null, $request=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