FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
change-license-processPost.php
1 <?php
2 /***********************************************************
3  * Copyright (C) 2014-2018,2020, 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 
25 
26 define("TITLE_CHANGELICPROCPOST", _("Private: Change license file post"));
27 
29 {
31  private $clearingDao;
33  private $uploadDao;
34 
35  function __construct()
36  {
37  $this->Name = "change-license-processPost";
38  $this->Title = TITLE_CHANGELICPROCPOST;
39  $this->DBaccess = PLUGIN_DB_WRITE;
40  $this->OutputType = 'JSON';
41  $this->OutputToStdout = 1;
42  $this->LoginFlag = 0;
43  $this->NoMenu = 0;
44 
45  parent::__construct();
46 
47  global $container;
48  $this->clearingDao = $container->get('dao.clearing');
49  $this->uploadDao = $container->get('dao.upload');
50  }
51 
55  // TODO: Understand Buckets and modify then
56  function ChangeBuckets()
57  {
58  global $SysConf;
59  global $PG_CONN;
60 
61  $uploadId = GetParm("upload", PARM_STRING);
62  $uploadTreeId = GetParm("item", PARM_STRING);
63 
64  $sql = "SELECT bucketpool_fk from bucket_ars where upload_fk = $uploadId;";
65  $result = pg_query($PG_CONN, $sql);
66  DBCheckResult($result, $sql, __FILE__, __LINE__);
67  $bucketpool_array = pg_fetch_all_columns($result, 0);
68  pg_free_result($result);
69  $buckets_dir = $SysConf['DIRECTORIES']['MODDIR'];
71  foreach ($bucketpool_array as $bucketpool) {
72  $command = "$buckets_dir/buckets/agent/buckets -r -t $uploadTreeId -p $bucketpool";
73  exec($command);
74  }
75  }
76 
80  function Output()
81  {
82  if ($this->State != PLUGIN_STATE_READY) {
83  return;
84  }
85  $itemId = @$_POST['uploadTreeId'];
86  if (empty($itemId)) {
87  return $this->errorJson("bad item id");
88  }
89 
90  $userId = Auth::getUserId();
91  $groupId = Auth::getGroupId();
92  $decisionMark = @$_POST['decisionMark'];
93  if (! empty($decisionMark) && ($decisionMark == "irrelevant" || $decisionMark == "doNotUse") ) {
94  if (! is_array($itemId)) {
95  $responseMsg = $this->doMarkDecisionTypes($itemId, $groupId, $userId, $decisionMark);
96  } else {
97  foreach ($itemId as $uploadTreeId) {
98  $responseMsg = $this->doMarkDecisionTypes($uploadTreeId, $groupId,
99  $userId, $decisionMark);
100  if (! empty($responseMsg)) {
101  return $responseMsg;
102  }
103  }
104  }
105  if (!empty($responseMsg)) {
106  return $responseMsg;
107  }
108  return new JsonResponse(array('result'=>'success'));
109  }
110 
111  if (!empty($decisionMark) && ($decisionMark == "deleteIrrelevant" || $decisionMark == "deleteDoNotUse")) {
112  $itemTableName = $this->uploadDao->getUploadtreeTableName($itemId);
114  $itemTreeBounds = $this->uploadDao->getItemTreeBounds($itemId, $itemTableName);
115  $errMsg = $this->clearingDao->deleteDecisionTypeFromDirectory($itemTreeBounds, $groupId, $userId, $decisionMark);
116  if (empty($errMsg)) {
117  return new JsonResponse(array('result'=>'success'));
118  }
119  return $this->errorJson($errMsg,$errMsg);
120  }
121 
122  return $this->doEdit($userId,$groupId,$itemId);
123  }
124 
125  function doMarkDecisionTypes($itemId, $groupId, $userId, $decisionMark)
126  {
127  $itemTableName = $this->uploadDao->getUploadtreeTableName($itemId);
129  $itemTreeBounds = $this->uploadDao->getItemTreeBounds($itemId,$itemTableName);
130  $errMsg = $this->clearingDao->markDirectoryAsDecisionType($itemTreeBounds, $groupId, $userId, $decisionMark);
131  return $errMsg;
132  }
133 
134  function doEdit($userId,$groupId,$itemId)
135  {
136  $licenses = GetParm("licenseNumbersToBeSubmitted", PARM_RAW);
137  $removed = $_POST['removed'] === 't' || $_POST['removed'] === 'true';
138 
139  $itemTreeBounds = $this->uploadDao->getItemTreeBounds($itemId);
140  $uploadId = $itemTreeBounds->getUploadId();
141  $upload = $this->uploadDao->getUpload($uploadId);
142  $uploadName = $upload->getFilename();
143 
144  $jobId = JobAddJob($userId, $groupId, $uploadName, $uploadId);
145 
146  if (isset($licenses)) {
147  if (! is_array($licenses)) {
148  return $this->errorJson("bad license array");
149  }
150  foreach ($licenses as $licenseId) {
151  if (intval($licenseId) <= 0) {
152  return $this->errorJson("bad license");
153  }
154 
155  $this->clearingDao->insertClearingEvent($itemId, $userId, $groupId, $licenseId, $removed,
156  ClearingEventTypes::USER, $reportInfo = '', $comment = '', $acknowledgement = '', $jobId);
157  }
158  }
159 
161  $deciderPlugin = plugin_find("agent_deciderjob");
162 
163  $conflictStrategyId = null;
164  $errorMsg = "";
165  $jq_pk = $deciderPlugin->AgentAdd($jobId, $uploadId, $errorMsg, array(), $conflictStrategyId);
166 
169 
176  if (empty($errorMsg) && ($jq_pk>0)) {
177  return new JsonResponse(array("jqid" => $jq_pk));
178  } else {
179  return $this->errorJson($errorMsg, 500);
180  }
181  }
182 
183  private function errorJson($msg, $code = 404)
184  {
185  return new JsonResponse(array("error" => $msg), $code);
186  }
187 }
188 
189 $NewPlugin = new changeLicenseProcessPost;
190 $NewPlugin->Initialize();
const PARM_RAW
Definition: common-parm.php:33
ChangeBuckets()
change bucket accordingly when change license of one file
Definition: state.hpp:26
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
const PARM_STRING
Definition: common-parm.php:29
ReportCachePurgeAll()
Purge all records from the report cache.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
Definition: libfossology.h:50
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:198
Output()
This function is called when user output is requested. This function is responsible for content...
Definition: FO_Plugin.php:407