8 namespace Fossology\CliXml\UI;
16 use Symfony\Component\HttpFoundation\Request;
20 const NAME =
'ui_clixml';
21 const DEFAULT_OUTPUT_FORMAT =
"clixml";
23 protected $outputFormat = self::DEFAULT_OUTPUT_FORMAT;
25 function __construct()
28 if (strcmp($possibleOutputFormat,
"") !== 0 &&
29 strcmp($possibleOutputFormat,self::DEFAULT_OUTPUT_FORMAT) !== 0 &&
30 ctype_alnum($possibleOutputFormat)) {
31 $this->outputFormat = $possibleOutputFormat;
33 parent::__construct(self::NAME, array(
34 self::TITLE => _(
strtoupper($this->outputFormat) .
" generation"),
36 self::REQUIRES_LOGIN =>
true
42 $text = _(
"Generate CLIXML report");
43 menu_insert(
"Browse-Pfile::Export CLIXML", 0, self::NAME, $text);
44 menu_insert(
"UploadMulti::Generate CLIXML", 0, self::NAME, $text);
48 protected function handle(Request $request)
52 $uploadIds = $request->get(
'uploads') ?: array();
53 $uploadIds[] = intval($request->get(
'upload'));
54 $addUploads = array();
55 foreach ($uploadIds as $uploadId) {
56 if (empty($uploadId)) {
61 $addUploads[$uploadId] = $this->getUpload($uploadId, $groupId);
65 return $this->flushContent($e->getMessage());
68 $folderId = $request->get(
'folder');
69 if (!empty($folderId)) {
71 $folderDao = $this->
getObject(
'dao.folder');
72 $folderUploads = $folderDao->getFolderUploads($folderId, $groupId);
73 foreach ($folderUploads as $uploadProgress) {
74 $addUploads[$uploadProgress->getId()] = $uploadProgress;
77 if (empty($addUploads)) {
78 return $this->flushContent(_(
'No upload selected'));
80 $upload = array_pop($addUploads);
83 list($jobId,$jobQueueId) = $this->getJobAndJobqueue($groupId, $upload, $addUploads);
85 catch (Exception $ex) {
86 return $this->flushContent($ex->getMessage());
89 $vars = array(
'jqPk' => $jobQueueId,
90 'downloadLink' =>
Traceback_uri().
"?mod=download&report=".$jobId,
91 'reportType' => $this->outputFormat);
92 $text = sprintf(_(
"Generating ". $this->outputFormat .
" report for '%s'"), $upload->getFilename());
93 $vars[
'content'] =
"<h2>".$text.
"</h2>";
94 $content = $this->renderer->load(
"report.html.twig")->render($vars);
95 $message =
'<h3 id="jobResult"></h3>';
96 $request->duplicate(array(
'injectedMessage'=>$message,
'injectedFoot'=>$content,
'mod'=>
'showjobs'))->overrideGlobals();
98 $showJobsPlugin->OutputOpen();
99 return $showJobsPlugin->getResponse();
102 protected function uploadsAdd($uploads)
104 if (count($uploads) == 0) {
107 return '--uploadsAdd='. implode(
',', array_keys($uploads));
110 protected function getJobAndJobqueue($groupId, $upload, $addUploads)
112 $uploadId = $upload->getId();
113 $clixmlAgent =
plugin_find(
'agent_'.$this->outputFormat);
115 $jqCmdArgs = $this->uploadsAdd($addUploads);
117 $dbManager = $this->
getObject(
'db.manager');
118 $sql =
'SELECT jq_pk,job_pk FROM jobqueue, job '
119 .
'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';
120 $params = array($clixmlAgent->AgentName,$uploadId,$userId,$groupId);
123 $sql .=
' AND jq_cmd_args=$5';
124 $params[] = $jqCmdArgs;
127 $sql .=
' AND jq_cmd_args IS NULL';
129 $scheduled = $dbManager->getSingleRow($sql,$params,$log);
130 if (!empty($scheduled)) {
131 return array($scheduled[
'job_pk'],$scheduled[
'jq_pk']);
133 $jobId = JobAddJob($userId, $groupId, $upload->getFilename(), $uploadId);
135 $jobQueueId = $clixmlAgent->AgentAdd($jobId, $uploadId, $error, array(), $jqCmdArgs);
137 throw new Exception(_(
"Cannot schedule").
": ".$error);
139 return array ($jobId, $jobQueueId);
142 protected function getUpload($uploadId, $groupId)
145 throw new Exception(_(
"parameter error: $uploadId"));
148 $uploadDao = $this->
getObject(
'dao.upload');
149 if (!$uploadDao->isAccessible($uploadId, $groupId)) {
150 throw new Exception(_(
"permission denied"));
153 $upload = $uploadDao->getUpload($uploadId);
154 if ($upload ===
null) {
155 throw new Exception(_(
'cannot find uploadId'));
171 return $this->getJobAndJobqueue($groupId, $upload, $addUploads);
175 register_plugin(
new CliXmlGeneratorUi());
scheduleAgent($groupId, $upload, $addUploads=array())
Contains the constants and helpers for authentication of user.
static getUserId()
Get the current user's id.
static getGroupId()
Get the current user's group id.
Traceback_uri()
Get the URI without query to this location.
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.
char * trim(char *ptext)
Trimming whitespace.
FUNCTION char * strtoupper(char *s)
Helper function to upper case a string.