14 use Symfony\Component\HttpFoundation\JsonResponse;
15 use Symfony\Component\HttpFoundation\Request;
19 const NAME =
"change-license-bulk";
27 function __construct()
29 parent::__construct(self::NAME, array(
30 self::TITLE => _(
"Private: schedule a bulk scan from post"),
35 $this->licenseDao = $this->
getObject(
'dao.license');
36 $this->uploadDao = $this->
getObject(
'dao.upload');
43 public function handle(Request $request)
45 $uploadTreeId = $request->get(
'uploadTreeId');
46 $uploadTreeId = strpos($uploadTreeId,
',') !==
false
47 ? explode(
',', $uploadTreeId)
48 : intval($uploadTreeId);
50 if (empty($uploadTreeId)) {
51 return new JsonResponse(array(
"error" =>
'bad request'), JsonResponse::HTTP_BAD_REQUEST);
56 }
catch (Exception $ex) {
57 $errorMsg = $ex->getMessage();
58 return new JsonResponse(array(
"error" => $errorMsg), JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
62 return new JsonResponse(array(
"jqid" => $jobQueueId));
73 if (is_array($uploadTreeId)) {
75 foreach ($uploadTreeId as $uploadTreePk) {
76 $jqId[] = $this->getJobQueueId($uploadTreePk, $request);
80 return $this->getJobQueueId($uploadTreeId, $request);
89 private function getJobQueueId($uploadTreeId, Request $request)
91 $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId);
92 $uploadId = intval($uploadEntry[
'upload_fk']);
93 $userId = Auth::getUserId();
94 $groupId = Auth::getGroupId();
96 if ($uploadId <= 0 || !$this->uploadDao->isAccessible($uploadId, $groupId)) {
97 throw new Exception(
'permission denied');
100 $bulkScope = $request->get(
'bulkScope');
101 switch ($bulkScope) {
103 $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
104 $topBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTable);
105 $uploadTreeId = $topBounds->getItemId();
109 if (!
Isdir($uploadEntry[
'ufile_mode']) &&
112 $uploadTreeId = $uploadEntry[
'parent'] ?: $uploadTreeId;
117 throw new InvalidArgumentException(
'bad scope request');
120 $refText = $request->get(
'refText');
121 $actions = $request->get(
'bulkAction');
122 $ignoreIrrelevantFiles = (intval($request->get(
'ignoreIrre')) == 1);
123 $scanFindingsOnly = boolval(intval($request->get(
'scanOnlyFindings')));
124 $delimiters = $request->get(
'delimiters');
126 $licenseRemovals = array();
127 foreach ($actions as $licenseAction) {
128 $licenseRemovals[$licenseAction[
'licenseId']] = array(($licenseAction[
'action']==
'Remove'), $licenseAction[
'comment'], $licenseAction[
'reportinfo'], $licenseAction[
'acknowledgement']);
130 $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId,
131 $uploadTreeId, $licenseRemovals, $refText, $ignoreIrrelevantFiles,
132 $delimiters, $scanFindingsOnly);
135 throw new Exception(
'cannot insert bulk reference');
137 $upload = $this->uploadDao->getUpload($uploadId);
138 $uploadName = $upload->getFilename();
139 $job_pk = JobAddJob($userId, $groupId, $uploadName, $uploadId);
142 $dependecies = array(array(
'name' =>
'agent_monk_bulk',
'args' => $bulkId));
143 $conflictStrategyId = intval($request->get(
'forceDecision'));
145 $jqId =
$deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies, $conflictStrategyId);
147 if (!empty($errorMsg)) {
148 throw new Exception(str_replace(
'<br>',
"\n", $errorMsg));
scheduleBulkScan($uploadTreeId, Request $request)
UI plugin for DeciderJobAgent.
Contains the constants and helpers for authentication of user.
ReportCachePurgeAll()
Purge all records from the report cache.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
#define PERM_WRITE
Read-Write permission.
fo_dbManager * dbManager
fo_dbManager object