FOSSology  4.4.0
Open Source License Compliance by Open Source Software
BulkReuser.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2015-2018 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Decider;
9 
14 use Symfony\Component\Config\Definition\Exception\Exception;
15 
16 include_once(__DIR__ . "/../../lib/php/common-job.php");
17 
23 {
27  private $dbManager;
28 
32  function __construct()
33  {
34  $this->dbManager = $GLOBALS['container']->get('db.manager');
35  }
36 
48  public function rerunBulkAndDeciderOnUpload($uploadId, $groupId, $userId, $bulkId, $dependency)
49  {
53  $uploadDao = $GLOBALS['container']->get('dao.upload');
54  $nTopItem = $uploadDao->getUploadParent($uploadId);
55  $pUTree = $this->dbManager->getSingleRow("SELECT uploadtree_fk FROM license_ref_bulk WHERE lrb_pk=$1",
56  array($bulkId), __METHOD__);
57  $uploadEntry = $uploadDao->getUploadEntry($pUTree['uploadtree_fk']);
58  $pUID = intval($uploadEntry['upload_fk']);
59  $pTopItem = $uploadDao->getUploadParent($pUID);
60  if ($pTopItem == $pUTree['uploadtree_fk']) {
61  $topItem = $nTopItem;
62  } else {
63  $pfUTree = $this->dbManager->getSingleRow("SELECT uploadtree_pk FROM uploadtree WHERE upload_fk=$1 AND ufile_name=$2 AND ufile_mode=$3",
64  array($uploadId, $uploadEntry['ufile_name'], $uploadEntry['ufile_mode']), __METHOD__.'getRealUploadtreeEntry');
65  if (!empty($pfUTree) && count($pfUTree) <= 1) {
66  $topItem = $pfUTree['uploadtree_pk'];
67  } else {
68  $topItem = "";
69  }
70  }
71  if (!empty($topItem)) {
75  $deciderPlugin = plugin_find("agent_deciderjob");
76  $dependecies = array();
77  $sql = "INSERT INTO license_ref_bulk (user_fk,group_fk,rf_text,upload_fk,uploadtree_fk,ignore_irrelevant,bulk_delimiters,scan_findings) "
78  . "SELECT $1 AS user_fk, $2 AS group_fk,rf_text,$3 AS upload_fk, $4 as uploadtree_fk, ignore_irrelevant, bulk_delimiters, scan_findings
79  FROM license_ref_bulk WHERE lrb_pk=$5 RETURNING lrb_pk, $5 as lrb_origin";
80  $sqlLic = "INSERT INTO license_set_bulk (lrb_fk, rf_fk, removing, comment, reportinfo, acknowledgement) "
81  ."SELECT $1 as lrb_fk, rf_fk, removing, comment, reportinfo, acknowledgement FROM license_set_bulk WHERE lrb_fk=$2";
82  $this->dbManager->prepare($stmt=__METHOD__.'cloneBulk', $sql);
83  $this->dbManager->prepare($stmtLic=__METHOD__.'cloneBulkLic', $sqlLic);
84  $res = $this->dbManager->execute($stmt,array($userId,$groupId,$uploadId,$topItem, $bulkId));
85  $row = $this->dbManager->fetchArray($res);
86  $this->dbManager->freeResult($res);
87  $resLic = $this->dbManager->execute($stmtLic,array($row['lrb_pk'],$row['lrb_origin']));
88  $this->dbManager->freeResult($resLic);
89  $upload = $uploadDao->getUpload($uploadId);
90  $uploadName = $upload->getFilename();
91  $job_pk = \JobAddJob($userId, $groupId, $uploadName, $uploadId);
92  $dependecies = array(array('name' => 'agent_monk_bulk', 'args' => $row['lrb_pk']));
93  $errorMsg = '';
94  $jqId = $deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies);
95 
96  if (!empty($errorMsg)) {
97  throw new Exception(str_replace('<br>', "\n", $errorMsg));
98  }
99  return $jqId;
100  } else {
101  return 0;
102  }
103  }
104 }
Prepares bulk licenses for an upload and run DeciderJob on it.
Definition: BulkReuser.php:23
__construct()
Get Database Manager from containers.
Definition: BulkReuser.php:32
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
Namespace for decider agent.
Definition: BulkReuser.php:8
$GLOBALS['xyyzzzDeciderJob']
plugin_find($x)
Mock function to get decider plugin required by BulkReuser.