13 use Symfony\Component\HttpFoundation\Request;
17 const NAME =
'ui_reportImport';
24 function __construct()
26 parent::__construct(self::NAME, array(
27 self::TITLE => _(
"Report Import"),
29 self::REQUIRES_LOGIN => TRUE
31 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
32 $this->folderDao = $GLOBALS[
'container']->get(
'dao.folder');
37 $text = _(
"Import Report");
38 menu_insert(
"Browse-Pfile::Import Report", 0, self::NAME, $text);
39 menu_insert(
"Main::Upload::Import Report", 0, self::NAME, $text);
42 protected function handle(Request $request)
44 $uploadId = intval(
GetArrayVal(
"uploadselect", $_POST));
45 if (empty($uploadId) ||
46 !array_key_exists(
'report',$_FILES) ||
47 empty($_FILES[
'report'][
'size']))
49 return $this->showUiToChoose();
53 $jobMetaData = $this->runImport($uploadId, $_FILES[
'report'], $request);
55 $showJobsPlugin->OutputOpen();
56 return $showJobsPlugin->getResponse();
60 protected function showUiToChoose()
63 $groupId = Auth::getGroupId();
64 $vars[
'userIsAdmin'] = Auth::isAdmin();
66 $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId());
68 if (empty($folder_pk)) {
69 $folder_pk = $rootFolder->getId();
71 $vars[
'folderId'] = $folder_pk;
73 $folderUploads = $this->folderDao->getFolderUploads($folder_pk, $groupId);
74 $uploadsById = array();
76 foreach ($folderUploads as $uploadProgress)
78 if ($uploadProgress->getGroupId() != $groupId) {
81 if (!$this->uploadDao->isEditable($uploadProgress->getId(), $groupId)) {
84 $display = $uploadProgress->getFilename() . _(
" from ") .
Convert2BrowserTime(date(
"Y-m-d H:i:s",$uploadProgress->getTimestamp()));
85 $uploadsById[$uploadProgress->getId()] = $display;
87 $vars[
'uploadList'] = $uploadsById;
93 $uploadId = key($uploadsById);
95 $vars[
'uploadId'] = $uploadId;
97 $folderStructure = $this->folderDao->getFolderStructure($rootFolder->getId());
98 $vars[
'folderStructure'] = $folderStructure;
99 $vars[
'baseUri'] = $Uri =
Traceback_uri() .
"?mod=" . self::NAME .
"&folder=";
101 return $this->
render(
'ReportImportPlugin.html.twig', $this->mergeWithDefault($vars));
104 public function runImport($uploadId, $report, $request)
106 $reportImportAgent =
plugin_find(
'agent_reportImport');
108 $jqCmdArgs = $reportImportAgent->addReport($report);
109 $jqCmdArgs .= $reportImportAgent->setAdditionalJqCmdArgs($request);
111 $userId = Auth::getUserId();
112 $groupId = Auth::getGroupId();
113 $dbManager = $this->
getObject(
'db.manager');
114 $sql =
'SELECT jq_pk,job_pk FROM jobqueue, job '
115 .
'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';
116 $params = array($reportImportAgent->AgentName,$uploadId,$userId,$groupId);
117 $statementName = __METHOD__;
119 $sql .=
' AND jq_cmd_args=$5';
120 $params[] = $jqCmdArgs;
121 $statementName .=
'.args';
124 $sql .=
' AND jq_cmd_args IS NULL';
127 $scheduled = $dbManager->getSingleRow($sql,$params,$statementName);
128 if (!empty($scheduled)) {
129 return array($scheduled[
'job_pk'],$scheduled[
'jq_pk']);
132 $upload = $this->getUpload($uploadId, $groupId);
133 $jobId = JobAddJob($userId, $groupId, $upload->getFilename(), $uploadId);
135 $jobQueueId = $reportImportAgent->AgentAdd($jobId, $uploadId, $error, array(), $jqCmdArgs);
138 throw new Exception(_(
"Cannot schedule").
": ".$error);
140 return array($jobId,$jobQueueId);
143 protected function getUpload($uploadId, $groupId)
147 throw new Exception(_(
"parameter error: $uploadId"));
149 if (!$this->uploadDao->isAccessible($uploadId, $groupId))
151 throw new Exception(_(
"permission denied"));
154 $upload = $this->uploadDao->getUpload($uploadId);
155 if ($upload ===
null)
157 throw new Exception(_(
'cannot find uploadId'));
Contains the constants and helpers for authentication of user.
render($templateName, $vars=null, $headers=null)
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.
GetArrayVal($Key, $Arr)
Get the value from a array(map)
Convert2BrowserTime($server_time)
Convert the server time to browser time.
#define PERM_WRITE
Read-Write permission.