37 const NAME =
'ui_readmeoss';
39 function __construct()
41 parent::__construct(self::NAME, array(
42 self::TITLE => _(
"ReadME_OSS generation"),
44 self::REQUIRES_LOGIN => TRUE
54 $text = _(
"Generate ReadMe_OSS");
55 menu_insert(
"Browse-Pfile::Export ReadMe_OSS", 0, self::NAME, $text);
57 menu_insert(
"UploadMulti::Generate ReadMe_OSS", 0, self::NAME, $text);
64 protected function handle(Request $request)
66 $groupId = Auth::getGroupId();
67 $uploadIds = $request->get(
'uploads') ?: array();
68 $uploadIds[] = intval($request->get(
'upload'));
69 $addUploads = array();
70 foreach ($uploadIds as $uploadId) {
71 if (empty($uploadId)) {
75 $addUploads[$uploadId] = $this->getUpload($uploadId, $groupId);
76 }
catch(Exception $e) {
77 return $this->flushContent($e->getMessage());
80 $folderId = $request->get(
'folder');
81 if (!empty($folderId)) {
83 $folderDao = $this->
getObject(
'dao.folder');
84 $folderUploads = $folderDao->getFolderUploads($folderId, $groupId);
85 foreach ($folderUploads as $uploadProgress) {
86 $addUploads[$uploadProgress->getId()] = $uploadProgress;
89 if (empty($addUploads)) {
90 return $this->flushContent(_(
'No upload selected'));
92 $upload = array_pop($addUploads);
94 list($jobId,$jobQueueId) = $this->
getJobAndJobqueue($groupId, $upload, $addUploads);
95 }
catch (Exception $ex) {
96 return $this->flushContent($ex->getMessage());
99 $vars = array(
'jqPk' => $jobQueueId,
100 'downloadLink' =>
Traceback_uri().
"?mod=download&report=".$jobId,
101 'reportType' =>
"ReadMe_OSS");
102 $text = sprintf(_(
"Generating ReadMe_OSS for '%s'"), $upload->getFilename());
103 $vars[
'content'] =
"<h2>".$text.
"</h2>";
104 $content = $this->renderer->loadTemplate(
"report.html.twig")->render($vars);
105 $message =
'<h3 id="jobResult"></h3>';
106 $request->duplicate(array(
'injectedMessage'=>$message,
'injectedFoot'=>$content,
'mod'=>
'showjobs'))->overrideGlobals();
108 $showJobsPlugin->OutputOpen();
109 return $showJobsPlugin->getResponse();
122 $uploadId = $upload->getId();
124 $userId = Auth::getUserId();
125 $jqCmdArgs = $readMeOssAgent->uploadsAdd($addUploads);
126 $dbManager = $this->
getObject(
'db.manager');
127 $sql =
'SELECT jq_pk,job_pk FROM jobqueue, job ' 128 .
'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';
129 $params = array($readMeOssAgent->AgentName,$uploadId,$userId,$groupId);
132 $sql .=
' AND jq_cmd_args=$5';
133 $params[] = $jqCmdArgs;
136 $sql .=
' AND jq_cmd_args IS NULL';
138 $scheduled = $dbManager->getSingleRow($sql,$params,$log);
139 if (!empty($scheduled)) {
140 return array($scheduled[
'job_pk'],$scheduled[
'jq_pk']);
142 if (empty($jqCmdArgs)) {
143 $jobName = $upload->getFilename();
145 $jobName =
"Multi File ReadmeOSS";
147 $jobId = JobAddJob($userId, $groupId, $jobName, $uploadId);
149 $jobQueueId = $readMeOssAgent->AgentAdd($jobId, $uploadId, $error, array(), $jqCmdArgs);
150 if ($jobQueueId < 0) {
151 throw new Exception(_(
"Cannot schedule").
": ".$error);
153 return array($jobId, $jobQueueId, $error);
164 protected function getUpload($uploadId, $groupId)
166 if ($uploadId <= 0) {
167 throw new Exception(_(
"parameter error: $uploadId"));
170 $uploadDao = $this->
getObject(
'dao.upload');
171 if (!$uploadDao->isAccessible($uploadId, $groupId)) {
172 throw new Exception(_(
"permission denied"));
175 $upload = $uploadDao->getUpload($uploadId);
176 if ($upload === null) {
177 throw new Exception(_(
'cannot find uploadId'));
Traceback_uri()
Get the URI without query to this location.
scheduleAgent($groupId, $upload, $addUploads=array())
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
Agent plugin for Readme_OSS agent.
const NAME
Mod name for the plugin.
#define PERM_WRITE
Read-Write permission.
getJobAndJobqueue($groupId, $upload, $addUploads)
Get parameters from job queue and schedule them.