40 function __construct()
43 if (strcmp($possibleOutputFormat,
"") !== 0 &&
44 strcmp($possibleOutputFormat,self::DEFAULT_OUTPUT_FORMAT) !== 0 &&
45 ctype_alnum($possibleOutputFormat)) {
46 $this->outputFormat = $possibleOutputFormat;
48 parent::__construct(self::NAME, array(
49 self::TITLE => _(strtoupper($this->outputFormat) .
" generation"),
51 self::REQUIRES_LOGIN =>
true 61 $text = _(
"Generate SPDX report");
62 menu_insert(
"Browse-Pfile::Export SPDX RDF", 0, self::NAME, $text);
63 menu_insert(
"UploadMulti::Generate SPDX", 0, self::NAME, $text);
65 $text = _(
"Generate SPDX report in tag:value format");
66 menu_insert(
"Browse-Pfile::Export SPDX tag:value", 0, self::NAME .
'&outputFormat=spdx2tv', $text);
68 $text = _(
"Generate Debian Copyright file");
69 menu_insert(
"Browse-Pfile::Export DEP5", 0, self::NAME .
'&outputFormat=dep5', $text);
76 protected function handle(Request $request)
80 $uploadIds = $request->get(
'uploads') ?: array();
81 $uploadIds[] = intval($request->get(
'upload'));
82 $addUploads = array();
83 foreach ($uploadIds as $uploadId) {
84 if (empty($uploadId)) {
88 $addUploads[$uploadId] = $this->getUpload($uploadId, $groupId);
89 }
catch(Exception $e) {
90 return $this->flushContent($e->getMessage());
93 $folderId = $request->get(
'folder');
94 if (!empty($folderId)) {
96 $folderDao = $this->
getObject(
'dao.folder');
97 $folderUploads = $folderDao->getFolderUploads($folderId, $groupId);
98 foreach ($folderUploads as $uploadProgress) {
99 $addUploads[$uploadProgress->getId()] = $uploadProgress;
102 if (empty($addUploads)) {
103 return $this->flushContent(_(
'No upload selected'));
105 $upload = array_pop($addUploads);
108 }
catch (\Exception $ex) {
109 return $this->flushContent($ex->getMessage());
112 $vars = array(
'jqPk' => $jobQueueId,
113 'downloadLink' =>
Traceback_uri().
"?mod=download&report=".$jobId,
114 'reportType' => $this->outputFormat);
115 $text = sprintf(_(
"Generating ". $this->outputFormat .
" report for '%s'"), $upload->getFilename());
116 $vars[
'content'] =
"<h2>".$text.
"</h2>";
117 $content = $this->renderer->loadTemplate(
"report.html.twig")->render($vars);
118 $message =
'<h3 id="jobResult"></h3>';
119 $request->duplicate(array(
'injectedMessage'=>$message,
'injectedFoot'=>$content,
'mod'=>
'showjobs'))->overrideGlobals();
121 $showJobsPlugin->OutputOpen();
122 return $showJobsPlugin->getResponse();
132 if (count($uploads) == 0) {
135 return '--uploadsAdd='. implode(
',', array_keys($uploads));
148 $uploadId = $upload->getId();
149 $spdxTwoAgent =
plugin_find(
'agent_'.$this->outputFormat);
153 $dbManager = $this->
getObject(
'db.manager');
154 $sql =
'SELECT jq_pk,job_pk FROM jobqueue, job ' 155 .
'WHERE jq_job_fk=job_pk AND jq_type=$1 AND job_group_fk=$4 AND job_user_fk=$3 AND jq_args=$2 AND jq_endtime IS NULL';
156 $params = array($spdxTwoAgent->AgentName,$uploadId,$userId,$groupId);
159 $sql .=
' AND jq_cmd_args=$5';
160 $params[] = $jqCmdArgs;
163 $sql .=
' AND jq_cmd_args IS NULL';
165 $scheduled = $dbManager->getSingleRow($sql,$params,$log);
166 if (!empty($scheduled)) {
167 return array($scheduled[
'job_pk'],$scheduled[
'jq_pk']);
169 if (empty($jqCmdArgs)) {
170 $jobName = $upload->getFilename();
172 $jobName =
"Multi File SPDX2";
174 $jobId = JobAddJob($userId, $groupId, $jobName, $uploadId);
176 $jobQueueId = $spdxTwoAgent->AgentAdd($jobId, $uploadId, $error, array(), $jqCmdArgs);
177 if ($jobQueueId < 0) {
178 throw new \Exception(_(
"Cannot schedule").
": ".$error);
180 return array($jobId,$jobQueueId, $error);
190 protected function getUpload($uploadId, $groupId)
192 if ($uploadId <= 0) {
193 throw new \Exception(_(
"parameter error: $uploadId"));
196 $uploadDao = $this->
getObject(
'dao.upload');
197 if (!$uploadDao->isAccessible($uploadId, $groupId)) {
198 throw new \Exception(_(
"permission denied"));
201 $upload = $uploadDao->getUpload($uploadId);
202 if ($upload === null) {
203 throw new \Exception(_(
'cannot find uploadId'));
219 $outputFormat = self::DEFAULT_OUTPUT_FORMAT, $addUploads = array())
const DEFAULT_OUTPUT_FORMAT
Default report format.
Traceback_uri()
Get the URI without query to this location.
static getUserId()
Get the current user's id.
getJobAndJobqueue($groupId, $upload, $addUploads)
Get the Job ID and Job queue ID.
const NAME
Mod name of the plugin.
Namespace used by SPDX2 agent.
uploadsAdd($uploads)
Add multiple uploads to the report.
Call SPDX2 agent to generate report from UI.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
scheduleAgent($groupId, $upload, $outputFormat=self::DEFAULT_OUTPUT_FORMAT, $addUploads=array())
list_t type structure used to keep various lists. (e.g. there are multiple lists).
static getGroupId()
Get the current user's group id.
char * trim(char *ptext)
Trimming whitespace.