19 use \PKP\Services\PKPPublicationService;
52 $publication = $args[1];
54 $dependencies = $args[3];
55 $request = $dependencies[
'request'];
56 $dispatcher = $request->getDispatcher();
59 $submission = !empty($args[
'submission'])
61 : $args[
'submission'] =
Services::get(
'submission')->get($publication->getData(
'submissionId'));
63 $submissionContext = !empty($dependencies[
'context'])
64 ? $dependencies[
'context']
65 : $dependencies[
'context'] =
Services::get(
'context')->get($submission->getData(
'contextId'));
67 foreach ($props as $prop) {
70 $values[$prop] = array_map(
71 function($chapter) use ($publication) {
72 $data = $chapter->_data;
73 $data[
'authors'] = array_map(
74 function($chapterAuthor) {
75 return $chapterAuthor->_data;
77 DAORegistry::getDAO(
'ChapterAuthorDAO')->getAuthors($publication->getId(), $chapter->getId())->toArray()
81 $publication->getData(
'chapters')
84 case 'publicationFormats':
85 $values[$prop] = array_map(
86 function($publicationFormat) {
87 return $publicationFormat->_data;
89 $publication->getData(
'publicationFormats')
93 $values[$prop] = $dispatcher->url(
96 $submissionContext->getData(
'urlPath'),
99 [$submission->getBestId(),
'version', $publication->getId()]
123 if (isset($props[
'seriesId'])) {
126 $errors[
'seriesId'] = [__(
'publication.invalidSeries')];
141 $publication = $args[0];
145 if ($publication->getData(
'coverImage')) {
147 $submission =
Services::get(
'submission')->get($publication->getData(
'submissionId'));
148 $submissionContext = $request->getContext();
149 if ($submissionContext->getId() !== $submission->getData(
'contextId')) {
150 $submissionContext =
Services::get(
'context')->get($submission->getData(
'contextId'));
153 $supportedLocales = $submissionContext->getSupportedSubmissionLocales();
154 foreach ($supportedLocales as $localeKey) {
155 if (!array_key_exists($localeKey, $publication->getData(
'coverImage'))) {
159 import(
'classes.file.PublicFileManager');
160 $publicFileManager = new \PublicFileManager();
161 $coverImage = $publication->getData(
'coverImage', $localeKey);
162 $coverImageFilePath = $publicFileManager->getContextFilesPath($submissionContext->getId()) .
'/' . $coverImage[
'uploadName'];
166 $submissionContext->getData(
'coverThumbnailsMaxWidth'),
167 $submissionContext->getData(
'coverThumbnailsMaxHeight')
185 $newPublication = $args[0];
186 $oldPublication = $args[1];
190 if (array_key_exists(
'coverImage', $params)) {
191 import(
'classes.file.PublicFileManager');
192 $publicFileManager = new \PublicFileManager();
193 $submission =
Services::get(
'submission')->get($newPublication->getData(
'submissionId'));
197 if ($submissionContext->getId() !== $submission->getData(
'contextId')) {
198 $submissionContext =
Services::get(
'context')->get($submission->getData(
'contextId'));
201 foreach ($params[
'coverImage'] as $localeKey => $value) {
204 if (is_null($value)) {
205 $oldCoverImage = $oldPublication->getData(
'coverImage', $localeKey);
206 if (!$oldCoverImage) {
210 $coverImageFilePath = $publicFileManager->getContextFilesPath($submission->getData(
'contextId')) .
'/' . $oldCoverImage[
'uploadName'];
211 if (!file_exists($coverImageFilePath)) {
212 $publicFileManager->removeContextFile($submission->getData(
'contextId'), $this->getThumbnailFileName($oldCoverImage[
'uploadName']));
217 $newCoverImage = $newPublication->getData(
'coverImage', $localeKey);
218 if (!$newCoverImage) {
222 $coverImageFilePath = $publicFileManager->getContextFilesPath($submission->getData(
'contextId')) .
'/' . $newCoverImage[
'uploadName'];
226 $submissionContext->getData(
'coverThumbnailsMaxWidth'),
227 $submissionContext->getData(
'coverThumbnailsMaxHeight')
245 $newPublication =& $args[0];
246 $oldPublication = $args[1];
250 $oldPublicationFormats = $oldPublication->getData(
'publicationFormats');
252 foreach ($oldPublicationFormats as $oldPublicationFormat) {
253 $newPublicationFormat = clone $oldPublicationFormat;
254 $newPublicationFormat->setData(
'id',
null);
255 $newPublicationFormat->setData(
'publicationId', $newPublication->getId());
259 $metadataDaos = [
'IdentificationCodeDAO',
'MarketDAO',
'PublicationDateDAO',
'SalesRightsDAO'];
260 foreach ($metadataDaos as $metadataDao) {
261 $result =
DAORegistry::getDAO($metadataDao)->getByPublicationFormatId($oldPublicationFormat->getId());
262 while (!$result->eof()) {
263 $oldObject = $result->next();
264 $newObject = clone $oldObject;
265 $newObject->setData(
'id',
null);
266 $newObject->setData(
'publicationFormatId', $newPublicationFormat->getId());
273 ASSOC_TYPE_REPRESENTATION,
274 $oldPublicationFormat->getId(),
275 $oldPublication->getData(
'submissionId')
277 foreach ($files as $file) {
278 $newFile = clone $file;
279 $newFile->setFileId(
null);
280 $newFile->setData(
'assocId', $newPublicationFormat->getId());
281 $newFiles[] =
DAORegistry::getDAO(
'SubmissionFileDAO')->insertObject($newFile, $file->getFilePath());
284 ASSOC_TYPE_SUBMISSION_FILE,
286 $file->getData(
'publicationId')
288 foreach ($dependentFiles as $dependentFile) {
289 $newDependentFile = clone $dependentFile;
290 $newDependentFile->setFileId(
null);
291 DAORegistry::getDAO(
'SubmissionFileDAO')->insertObject($newDependentFile, $dependentFile->getFilePath());
297 $oldAuthorsIterator =
Services::get(
'author')->getMany([
'publicationIds' => $oldPublication->getId()]);
298 $oldAuthors = iterator_to_array($oldAuthorsIterator);
299 $newAuthorsIterator =
Services::get(
'author')->getMany([
'publicationIds' => $newPublication->getId()]);
300 $newAuthors = iterator_to_array($newAuthorsIterator);
302 while (!$result->eof()) {
303 $oldChapter = $result->next();
304 $newChapter = clone $oldChapter;
305 $newChapter->setData(
'id',
null);
306 $newChapter->setData(
'publicationId', $newPublication->getId());
311 foreach ($newFiles as $newFile) {
312 if ($newFile->getChapterId() == $oldChapter->getId()) {
313 $newFile->setChapterId($newChapter->getId());
323 $oldChapterAuthors =
DAORegistry::getDAO(
'ChapterAuthorDAO')->getAuthors($oldPublication->getId(), $oldChapter->getId())->toArray();
324 foreach ($newAuthors as $newAuthor) {
325 foreach ($oldAuthors as $oldAuthor) {
326 if ($newAuthor->getData(
'seq') === $oldAuthor->getData(
'seq')) {
327 foreach ($oldChapterAuthors as $oldChapterAuthor) {
328 if ($oldChapterAuthor->getId() === $oldAuthor->getId()) {
331 $newChapter->getId(),
332 $newAuthor->getId() === $newPublication->getData(
'primaryContactId'),
333 $oldChapterAuthor->getData(
'seq')
342 $newPublication = $this->
get($newPublication->getId());
355 $newPublication = $args[0];
356 $oldPublication = $args[1];
359 $datePublished = $oldPublication->getData(
'datePublished');
361 $newPublication->setData(
'status', STATUS_SCHEDULED);
376 $newPublication = $args[0];
377 $submission = $args[2];
381 ->getByPublicationId($newPublication->getId())
382 ->toAssociativeArray();
383 import(
'classes.publicationFormat.PublicationFormatTombstoneManager');
384 $publicationFormatTombstoneMgr = new \PublicationFormatTombstoneManager();
385 $publicationFormatTombstoneMgr->deleteTombstonesByPublicationFormats($publicationFormats);
389 $notificationMgr = new \NotificationManager();
390 $notificationMgr->updateNotification(
392 array(NOTIFICATION_TYPE_APPROVE_SUBMISSION),
394 ASSOC_TYPE_MONOGRAPH,
395 $newPublication->getData(
'submissionId')
410 $newPublication = $args[0];
411 $oldPublication = $args[1];
412 $submission =
Services::get(
'submission')->get($newPublication->getData(
'submissionId'));
413 $submissionContext =
Services::get(
'context')->get($submission->getData(
'contextId'));
417 ->getByPublicationId($newPublication->getId())
418 ->toAssociativeArray();
419 import(
'classes.publicationFormat.PublicationFormatTombstoneManager');
420 $publicationFormatTombstoneMgr = new \PublicationFormatTombstoneManager();
421 $publicationFormatTombstoneMgr->insertTombstonesByPublicationFormats($publicationFormats, $submissionContext);
425 $notificationMgr = new \NotificationManager();
426 $notificationMgr->updateNotification(
428 array(NOTIFICATION_TYPE_APPROVE_SUBMISSION),
430 ASSOC_TYPE_MONOGRAPH,
431 $newPublication->getData(
'submissionId')
444 $publication = $args[0];
445 $submission =
Services::get(
'submission')->get($publication->getData(
'submissionId'));
446 $context =
Services::get(
'context')->get($submission->getData(
'contextId'));
449 $publicationFormats = $publication->getData(
'publicationFormats');
450 foreach ($publicationFormats as $publicationFormat) {
451 Services::get(
'publicationFormat')->deleteFormat($publicationFormat, $submission, $context);
456 while ($chapter = $chapters->next()) {
471 $pathInfo = pathinfo($fileName);
472 return $pathInfo[
'filename'] .
'_t.' . $pathInfo[
'extension'];
482 public function makeThumbnail($filePath, $thumbFileName, $maxWidth, $maxHeight) {
483 $pathParts = pathinfo($filePath);
486 switch ($pathParts[
'extension']) {
487 case 'jpg': $cover = imagecreatefromjpeg($filePath);
break;
488 case 'png': $cover = imagecreatefrompng($filePath);
break;
489 case 'gif': $cover = imagecreatefromgif($filePath);
break;
491 if (!isset($cover)) {
492 throw new \Exception(
'Can not build thumbnail because the file was not found or the file extension was not recognized.');
496 $originalSizeArray = getimagesize($filePath);
497 $xRatio = min(1, $maxWidth / $originalSizeArray[0]);
498 $yRatio = min(1, $maxHeight / $originalSizeArray[1]);
501 $ratio = min($xRatio, $yRatio);
503 $thumbWidth = round($ratio * $originalSizeArray[0]);
504 $thumbHeight = round($ratio * $originalSizeArray[1]);
505 $thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
506 imagecopyresampled($thumb, $cover, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $originalSizeArray[0], $originalSizeArray[1]);
508 switch ($pathParts[
'extension']) {
509 case 'jpg': imagejpeg($thumb, $pathParts[
'dirname'] .
'/' . $thumbFileName);
break;
510 case 'png': imagepng($thumb, $pathParts[
'dirname'] .
'/' . $thumbFileName);
break;
511 case 'gif': imagegif($thumb, $pathParts[
'dirname'] .
'/' . $thumbFileName);
break;
514 imagedestroy($thumb);