17 import(
'lib.pkp.classes.plugins.GatewayPlugin');
38 parent::__construct();
39 $this->_parentPluginName = $parentPluginName;
43 $this->
import(
'classes.MarkupBatchConversionHelper');
53 $this->
import(
'classes.MarkupConversionHelper');
73 return 'MarkupBatchGatewayPlugin';
82 return __(
'plugins.generic.markup.batch.displayName');
91 return __(
'plugins.generic.markup.batch.description');
110 return $plugin->getPluginPath();
118 return parent::getSeq() + 1;
130 set_error_handler(array($this->_batchConversionHelper,
'errorHandler'), E_ERROR );
133 if ($this->_batchConversionHelper->isRunning()) {
140 foreach ($args as $index => $arg) {
141 if ($arg ==
'true') $arg =
true;
142 if ($arg ==
'false') $arg =
false;
144 if ($index % 2 == 0) {
150 $args = array_combine($keys, $values);
154 $userId = isset($args[
'userId']) ? (int) $args[
'userId'] :
false;
156 fatalError(__(
'plugins.generic.markup.archive.noUserID'));
159 $this->_user = $userDao->getById($userId);
170 $accessKey = isset($args[
'accessKey']) ? $args[
'accessKey'] :
null;
171 if (empty($accessKey)) {
172 fatalError(__(
'plugins.generic.markup.archive.noAccessKey'));
178 fatalError(__(
'plugins.generic.markup.archive.noAccessKey'));
182 $submissions = $_POST;
185 $submissionCount =
count($submissions);
188 'submissionCount' => $submissionCount,
189 'processedCount' => 0,
193 $this->_batchConversionHelper->createOutFile($data);
197 $userGroups = $userGroupDao->getByUserId($this->_user->getId(), $journal->getId());
198 $userGroup = $userGroups->next();
205 $cancellationToken = sha1(time());
206 foreach ($submissions as $submissionId => $submissionFileId) {
209 'cancellationToken' => $cancellationToken,
210 'submissionCount' => $submissionCount,
211 'processedCount' => ++$processedCount,
212 'submissionId' => $submissionId,
213 'conversionStatus' =>
'',
218 $submissionFile = $submissionFileDao->getLatestRevision($submissionFileId);
219 if (!$submissionFile) {
224 $submission = $submissionDao->getById($submissionFile->getSubmissionId());
232 $data[
'jobInfoId'] = $jobInfoId;
233 $this->_batchConversionHelper->updateOutFile($data);
235 $jobId = $this->_markupConversionHelper->triggerConversion(
238 $submissionFile->getFileStage(),
242 $data[
'otsJobId'] = $jobId;
248 $statusCallbackFn =
function($jobStatus) use ($data, $batchConversionHelper,
$request, $user, $plugin) {
254 $data[
'conversionStatus'] = $wrapper->statusCodeToLabel($jobStatus);
255 $batchConversionHelper->updateOutFile($data);
258 $tmpZipFile = $this->_markupConversionHelper->retrieveConversionJobArchive(
263 if (($tmpZipFile ==
false) || !file_exists($tmpZipFile)) {
264 throw new Exception(__(
'plugins.generic.markup.archive-download-failure'));
267 $extractionPath =
null;
268 if (($extractionPath = $this->_markupConversionHelper->unzipArchive($tmpZipFile)) ===
false) {
269 throw new Exception(__(
'plugins.generic.markup.archive-extract-failure'));
272 $fileName =
"document" .
'__' . date(
'Y-m-d_h:i:s');
273 $this->_markupConversionHelper->handleArchiveExtractionAfterGalleyGenerate(
281 catch (Exception $e) {
282 error_log(
'EXCEPTION!!! ' . $e->getMessage());
283 $statusCallbackFn($e->getMessage());
290 $this->_batchConversionHelper->deleteOutFile();