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 = intval($request->get(
'uploadTreeId'));
46 if ($uploadTreeId <= 0) {
47 return new JsonResponse(array(
"error" =>
'bad request'), JsonResponse::HTTP_BAD_REQUEST);
51 $jobQueueId = $this->getJobQueueId($uploadTreeId, $request);
52 }
catch (Exception $ex) {
53 $errorMsg = $ex->getMessage();
54 return new JsonResponse(array(
"error" => $errorMsg), JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
58 return new JsonResponse(array(
"jqid" => $jobQueueId));
67 private function getJobQueueId($uploadTreeId, Request $request)
69 $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId);
70 $uploadId = intval($uploadEntry[
'upload_fk']);
71 $userId = Auth::getUserId();
72 $groupId = Auth::getGroupId();
74 if ($uploadId <= 0 || !$this->uploadDao->isAccessible($uploadId, $groupId)) {
75 throw new Exception(
'permission denied');
78 $bulkScope = $request->get(
'bulkScope');
81 $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
82 $topBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTable);
83 $uploadTreeId = $topBounds->getItemId();
87 if (!
Isdir($uploadEntry[
'ufile_mode']) &&
90 $uploadTreeId = $uploadEntry[
'parent'] ?: $uploadTreeId;
95 throw new InvalidArgumentException(
'bad scope request');
98 $refText = $request->get(
'refText');
99 $actions = $request->get(
'bulkAction');
100 $ignoreIrrelevantFiles = (intval($request->get(
'ignoreIrre')) == 1);
101 $scanFindingsOnly = boolval(intval($request->get(
'scanOnlyFindings')));
102 $delimiters = $request->get(
'delimiters');
104 $licenseRemovals = array();
105 foreach ($actions as $licenseAction) {
106 $licenseRemovals[$licenseAction[
'licenseId']] = array(($licenseAction[
'action']==
'Remove'), $licenseAction[
'comment'], $licenseAction[
'reportinfo'], $licenseAction[
'acknowledgement']);
108 $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId,
109 $uploadTreeId, $licenseRemovals, $refText, $ignoreIrrelevantFiles,
110 $delimiters, $scanFindingsOnly);
113 throw new Exception(
'cannot insert bulk reference');
115 $upload = $this->uploadDao->getUpload($uploadId);
116 $uploadName = $upload->getFilename();
117 $job_pk = JobAddJob($userId, $groupId, $uploadName, $uploadId);
120 $dependecies = array(array(
'name' =>
'agent_monk_bulk',
'args' => $bulkId));
121 $conflictStrategyId = intval($request->get(
'forceDecision'));
123 $jqId =
$deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies, $conflictStrategyId);
125 if (!empty($errorMsg)) {
126 throw new Exception(str_replace(
'<br>',
"\n", $errorMsg));
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