FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
BulkReuser.php
1 <?php
2 /*
3  Copyright (C) 2015-2018, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
20 
26 
27 include_once(__DIR__ . "/../../lib/php/common-job.php");
28 
34 {
38  private $dbManager;
39 
43  function __construct()
44  {
45  $this->dbManager = $GLOBALS['container']->get('db.manager');
46  }
47 
59  public function rerunBulkAndDeciderOnUpload($uploadId, $groupId, $userId, $bulkId, $dependency)
60  {
64  $uploadDao = $GLOBALS['container']->get('dao.upload');
65  $topItem = $uploadDao->getUploadParent($uploadId);
69  $deciderPlugin = plugin_find("agent_deciderjob");
70  $dependecies = array();
71  $sql = "INSERT INTO license_ref_bulk (user_fk,group_fk,rf_text,upload_fk,uploadtree_fk) "
72  . "SELECT $1 AS user_fk, $2 AS group_fk,rf_text,$3 AS upload_fk, $4 as uploadtree_fk
73  FROM license_ref_bulk WHERE lrb_pk=$5 RETURNING lrb_pk, $5 as lrb_origin";
74  $sqlLic = "INSERT INTO license_set_bulk (lrb_fk, rf_fk, removing, comment, reportinfo, acknowledgement) "
75  ."SELECT $1 as lrb_fk, rf_fk, removing, comment, reportinfo, acknowledgement FROM license_set_bulk WHERE lrb_fk=$2";
76  $this->dbManager->prepare($stmt=__METHOD__.'cloneBulk', $sql);
77  $this->dbManager->prepare($stmtLic=__METHOD__.'cloneBulkLic', $sqlLic);
78  $res = $this->dbManager->execute($stmt,array($userId,$groupId,$uploadId,$topItem, $bulkId));
79  $row = $this->dbManager->fetchArray($res);
80  $this->dbManager->freeResult($res);
81  $resLic = $this->dbManager->execute($stmtLic,array($row['lrb_pk'],$row['lrb_origin']));
82  $this->dbManager->freeResult($resLic);
83  $upload = $uploadDao->getUpload($uploadId);
84  $uploadName = $upload->getFilename();
85  $job_pk = \JobAddJob($userId, $groupId, $uploadName, $uploadId);
86  $dependecies = array(array('name' => 'agent_monk_bulk', 'args' => $row['lrb_pk']));
87  $errorMsg = '';
88  $jqId = $deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies);
89 
90  if (!empty($errorMsg)) {
91  throw new Exception(str_replace('<br>', "\n", $errorMsg));
92  }
93  return $jqId;
94  }
95 }
__construct()
Get Database Manager from containers.
Definition: BulkReuser.php:43
Namespace for decider agent.
Definition: BulkReuser.php:19
plugin_find($x)
Mock function to get decider plugin required by BulkReuser.
$GLOBALS['xyyzzzDeciderJob']
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
Prepares bulk licenses for an upload and run DeciderJob on it.
Definition: BulkReuser.php:33