13 namespace Fossology\ReadmeOSS\UI;
20 use Symfony\Component\HttpFoundation\Request;
28 const NAME =
'ui_readmeoss';
30 function __construct()
32 parent::__construct(self::NAME, array(
33 self::TITLE => _(
"ReadME_OSS generation"),
35 self::REQUIRES_LOGIN => TRUE
45 $text = _(
"Generate ReadMe_OSS");
46 menu_insert(
"Browse-Pfile::Export ReadMe_OSS", 0, self::NAME, $text);
48 menu_insert(
"UploadMulti::Generate ReadMe_OSS", 0, self::NAME, $text);
55 protected function handle(Request $request)
58 $uploadIds = $request->get(
'uploads') ?: array();
59 $uploadIds[] = intval($request->get(
'upload'));
60 $addUploads = array();
61 foreach ($uploadIds as $uploadId) {
62 if (empty($uploadId)) {
66 $addUploads[$uploadId] = $this->getUpload($uploadId, $groupId);
67 }
catch(Exception $e) {
68 return $this->flushContent($e->getMessage());
71 $folderId = $request->get(
'folder');
72 if (!empty($folderId)) {
74 $folderDao = $this->
getObject(
'dao.folder');
75 $folderUploads = $folderDao->getFolderUploads($folderId, $groupId);
76 foreach ($folderUploads as $uploadProgress) {
77 $addUploads[$uploadProgress->getId()] = $uploadProgress;
80 if (empty($addUploads)) {
81 return $this->flushContent(_(
'No upload selected'));
83 $upload = array_pop($addUploads);
86 }
catch (Exception $ex) {
87 return $this->flushContent($ex->getMessage());
90 $vars = array(
'jqPk' => $jobQueueId,
91 'downloadLink' =>
Traceback_uri().
"?mod=download&report=".$jobId,
92 'reportType' =>
"ReadMe_OSS");
93 $text = sprintf(_(
"Generating ReadMe_OSS for '%s'"), $upload->getFilename());
94 $vars[
'content'] =
"<h2>".$text.
"</h2>";
95 $content = $this->renderer->load(
"report.html.twig")->render($vars);
96 $message =
'<h3 id="jobResult"></h3>';
97 $request->duplicate(array(
'injectedMessage'=>$message,
'injectedFoot'=>$content,
'mod'=>
'showjobs'))->overrideGlobals();
99 $showJobsPlugin->OutputOpen();
100 return $showJobsPlugin->getResponse();
113 $uploadId = $upload->getId();
116 $jqCmdArgs = $readMeOssAgent->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($readMeOssAgent->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 if (empty($jqCmdArgs)) {
134 $jobName = $upload->getFilename();
136 $jobName =
"Multi File ReadmeOSS";
138 $jobId = JobAddJob($userId, $groupId, $jobName, $uploadId);
140 $jobQueueId = $readMeOssAgent->AgentAdd($jobId, $uploadId, $error, array(), $jqCmdArgs);
141 if ($jobQueueId < 0) {
142 throw new Exception(_(
"Cannot schedule").
": ".$error);
144 return array($jobId, $jobQueueId, $error);
155 protected function getUpload($uploadId, $groupId)
157 if ($uploadId <= 0) {
158 throw new Exception(_(
"parameter error: $uploadId"));
161 $uploadDao = $this->
getObject(
'dao.upload');
162 if (!$uploadDao->isAccessible($uploadId, $groupId)) {
163 throw new Exception(_(
"permission denied"));
166 $upload = $uploadDao->getUpload($uploadId);
167 if ($upload ===
null) {
168 throw new Exception(_(
'cannot find uploadId'));
188 register_plugin(
new ReadMeOssPlugin());
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.
Agent plugin for Readme_OSS agent.
const NAME
Mod name for the plugin.
getJobAndJobqueue($groupId, $upload, $addUploads)
Get parameters from job queue and schedule them.
scheduleAgent($groupId, $upload, $addUploads=array())
Traceback_uri()
Get the URI without query to this location.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
list_t type structure used to keep various lists. (e.g. there are multiple lists).