Esempio n. 1
0
 /**
  * @covers ArticleSearchIndex
  */
 public function testUpdateFileIndexViaPluginHook()
 {
     // Diverting to the search plugin hook.
     HookRegistry::register('ArticleSearchIndex::articleFileChanged', array($this, 'callbackUpdateFileIndex'));
     // Simulate updating an article file via hook.
     $articleSearchIndex = new ArticleSearchIndex();
     $articleSearchIndex->articleFileChanged(0, 1, 2);
     // Test whether the hook was called.
     $calledHooks = HookRegistry::getCalledHooks();
     $lastHook = array_pop($calledHooks);
     self::assertEquals('ArticleSearchIndex::articleFileChanged', $lastHook[0]);
     // Remove the test hook.
     HookRegistry::clear('ArticleSearchIndex::articleFileChanged');
 }
Esempio n. 2
0
 /**
  * Save settings.
  */
 function execute()
 {
     $articleDao = DAORegistry::getDAO('ArticleDAO');
     $signoffDao = DAORegistry::getDAO('SignoffDAO');
     $sectionEditorSubmissionDao = DAORegistry::getDAO('SectionEditorSubmissionDAO');
     $application = PKPApplication::getApplication();
     $request = $this->request;
     $user = $request->getUser();
     $router = $request->getRouter();
     $journal = $router->getContext($request);
     $article = $articleDao->newDataObject();
     $article->setLocale($journal->getPrimaryLocale());
     // FIXME in bug #5543
     $article->setUserId($user->getId());
     $article->setJournalId($journal->getId());
     $article->setSectionId($this->getData('sectionId'));
     $article->setLanguage($this->getData('language'));
     $article->setTitle($this->getData('title'), null);
     // Localized
     $article->setAbstract($this->getData('abstract'), null);
     // Localized
     $article->setDiscipline($this->getData('discipline'), null);
     // Localized
     $article->setSubjectClass($this->getData('subjectClass'), null);
     // Localized
     $article->setSubject($this->getData('subject'), null);
     // Localized
     $article->setCoverageGeo($this->getData('coverageGeo'), null);
     // Localized
     $article->setCoverageChron($this->getData('coverageChron'), null);
     // Localized
     $article->setCoverageSample($this->getData('coverageSample'), null);
     // Localized
     $article->setType($this->getData('type'), null);
     // Localized
     $article->setSponsor($this->getData('sponsor'), null);
     // Localized
     $article->setCitations($this->getData('citations'));
     $article->setPages($this->getData('pages'));
     // Set some default values so the ArticleDAO doesn't complain when adding this article
     $article->setDateSubmitted(Core::getCurrentDate());
     $article->setStatus(STATUS_PUBLISHED);
     $article->setSubmissionProgress(0);
     $article->stampStatusModified();
     $article->setCurrentRound(1);
     $article->setFastTracked(1);
     $article->setHideAuthor(0);
     $article->setCommentsStatus(0);
     // Insert the article to get it's ID
     $articleDao->insertObject($article);
     $articleId = $article->getId();
     // Add authors
     $authors = $this->getData('authors');
     for ($i = 0, $count = count($authors); $i < $count; $i++) {
         if ($authors[$i]['authorId'] > 0) {
             // Update an existing author
             $author =& $authorDao->getAuthor($authors[$i]['authorId'], $articleId);
             $isExistingAuthor = true;
         } else {
             // Create a new author
             $author = new Author();
             $isExistingAuthor = false;
         }
         if ($author != null) {
             $author->setSubmissionId($articleId);
             $author->setFirstName($authors[$i]['firstName']);
             $author->setMiddleName($authors[$i]['middleName']);
             $author->setLastName($authors[$i]['lastName']);
             if (array_key_exists('affiliation', $authors[$i])) {
                 $author->setAffiliation($authors[$i]['affiliation'], null);
             }
             $author->setCountry($authors[$i]['country']);
             $author->setEmail($authors[$i]['email']);
             $author->setUrl($authors[$i]['url']);
             if (array_key_exists('competingInterests', $authors[$i])) {
                 $author->setCompetingInterests($authors[$i]['competingInterests'], null);
             }
             $author->setBiography($authors[$i]['biography'], null);
             $author->setPrimaryContact($this->getData('primaryContact') == $i ? 1 : 0);
             $author->setSequence($authors[$i]['seq']);
             if ($isExistingAuthor == false) {
                 $authorDao = DAORegistry::getDAO('AuthorDAO');
                 /* @var $authorDao AuthorDAO */
                 $authorDao->insertObject($author);
             }
         }
     }
     // Add the submission files as galleys
     import('lib.pkp.classes.file.TemporaryFileManager');
     import('classes.file.ArticleFileManager');
     $tempFileIds = $this->getData('tempFileId');
     $temporaryFileManager = new TemporaryFileManager();
     $articleFileManager = new ArticleFileManager($articleId);
     $designatedPrimary = false;
     foreach (array_keys($tempFileIds) as $locale) {
         $temporaryFile = $temporaryFileManager->getFile($tempFileIds[$locale], $user->getId());
         $fileId = null;
         if ($temporaryFile) {
             $fileId = $articleFileManager->temporaryFileToArticleFile($temporaryFile, SUBMISSION_FILE_SUBMISSION);
             $fileType = $temporaryFile->getFileType();
             if (strstr($fileType, 'html')) {
                 import('classes.article.ArticleHTMLGalley');
                 $galley = new ArticleHTMLGalley();
             } else {
                 import('classes.article.ArticleGalley');
                 $galley = new ArticleGalley();
             }
             $galley->setArticleId($articleId);
             $galley->setFileId($fileId);
             $galley->setLocale($locale);
             if ($galley->isHTMLGalley()) {
                 $galley->setLabel('HTML');
             } else {
                 if (strstr($fileType, 'pdf')) {
                     $galley->setLabel('PDF');
                 } else {
                     if (strstr($fileType, 'postscript')) {
                         $galley->setLabel('Postscript');
                     } else {
                         if (strstr($fileType, 'xml')) {
                             $galley->setLabel('XML');
                         } else {
                             $galley->setLabel(__('common.untitled'));
                         }
                     }
                 }
             }
             $galleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
             $galleyDao->insertGalley($galley);
             if (!$designatedPrimary) {
                 $article->setSubmissionFileId($fileId);
                 if ($locale == $journal->getPrimaryLocale()) {
                     // Used to make sure that *some* file
                     // is designated Review Version, but
                     // preferrably the primary locale.
                     $designatedPrimary = true;
                 }
             }
         }
         // Update file search index
         import('classes.search.ArticleSearchIndex');
         $articleSearchIndex = new ArticleSearchIndex();
         if (isset($galley)) {
             $articleSearchIndex->articleFileChanged($galley->getArticleId(), SUBMISSION_SEARCH_GALLEY_FILE, $galley->getFileId());
         }
         $articleSearchIndex->articleChangesFinished();
     }
     // Designate this as the review version by default.
     $authorSubmissionDao = DAORegistry::getDAO('AuthorSubmissionDAO');
     $authorSubmission =& $authorSubmissionDao->getAuthorSubmission($articleId);
     import('classes.submission.author.AuthorAction');
     AuthorAction::designateReviewVersion($authorSubmission, true);
     // Accept the submission
     $sectionEditorSubmission =& $sectionEditorSubmissionDao->getSectionEditorSubmission($articleId);
     $articleFileManager = new ArticleFileManager($articleId);
     import('classes.submission.sectionEditor.SectionEditorAction');
     assert(false);
     // FIXME: $decisionLabels missing from call below.
     SectionEditorAction::recordDecision($this->request, $sectionEditorSubmission, SUBMISSION_EDITOR_DECISION_ACCEPT);
     import('classes.author.form.submit.AuthorSubmitForm');
     AuthorSubmitForm::assignEditors($article);
     $articleDao->updateObject($article);
     // Add to end of editing queue
     import('classes.submission.editor.EditorAction');
     if (isset($galley)) {
         EditorAction::expediteSubmission($article, $this->request);
     }
     if ($this->getData('destination') == "issue") {
         // Add to an existing issue
         $issueId = $this->getData('issueId');
         $this->scheduleForPublication($articleId, $issueId);
     }
     // Import the references list.
     $citationDao = DAORegistry::getDAO('CitationDAO');
     $rawCitationList = $article->getCitations();
     $citationDao->importCitations($request, ASSOC_TYPE_ARTICLE, $articleId, $rawCitationList);
     // Index article.
     import('classes.search.ArticleSearchIndex');
     $articleSearchIndex = new ArticleSearchIndex();
     $articleSearchIndex->articleMetadataChanged($article);
     $articleSearchIndex->articleChangesFinished();
 }
 /**
  * Save changes to the galley.
  * @return int the galley ID
  */
 function execute($fileName = null, $createRemote = false)
 {
     import('classes.file.ArticleFileManager');
     $articleFileManager = new ArticleFileManager($this->articleId);
     $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
     $fileName = isset($fileName) ? $fileName : 'galleyFile';
     $journal =& Request::getJournal();
     $fileId = null;
     $articleDao =& DAORegistry::getDAO('ArticleDAO');
     $article =& $articleDao->getArticle($this->articleId, $journal->getId());
     if (isset($this->galley)) {
         $galley =& $this->galley;
         // Upload galley file
         if ($articleFileManager->uploadedFileExists($fileName)) {
             if ($galley->getFileId()) {
                 $articleFileManager->uploadPublicFile($fileName, $galley->getFileId());
                 $fileId = $galley->getFileId();
             } else {
                 $fileId = $articleFileManager->uploadPublicFile($fileName);
                 $galley->setFileId($fileId);
             }
             // Update file search index
             import('classes.search.ArticleSearchIndex');
             $articleSearchIndex = new ArticleSearchIndex();
             $articleSearchIndex->articleFileChanged($this->articleId, ARTICLE_SEARCH_GALLEY_FILE, $galley->getFileId());
             $articleSearchIndex->articleChangesFinished();
         }
         if ($articleFileManager->uploadedFileExists('styleFile')) {
             // Upload stylesheet file
             $styleFileId = $articleFileManager->uploadPublicFile('styleFile', $galley->getStyleFileId());
             $galley->setStyleFileId($styleFileId);
         } else {
             if ($this->getData('deleteStyleFile')) {
                 // Delete stylesheet file
                 $styleFile =& $galley->getStyleFile();
                 if (isset($styleFile)) {
                     $articleFileManager->deleteFile($styleFile->getFileId());
                 }
             }
         }
         // Update existing galley
         $galley->setLabel($this->getData('label'));
         if ($journal->getSetting('enablePublicGalleyId')) {
             $galley->setStoredPubId('publisher-id', $this->getData('publicGalleyId'));
         }
         $galley->setLocale($this->getData('galleyLocale'));
         if ($this->getData('remoteURL')) {
             $galley->setRemoteURL($this->getData('remoteURL'));
         }
         // consider the additional field names from the public identifer plugins
         import('classes.plugins.PubIdPluginHelper');
         $pubIdPluginHelper = new PubIdPluginHelper();
         $pubIdPluginHelper->execute($this, $galley);
         parent::execute();
         $galleyDao->updateGalley($galley);
     } else {
         // Upload galley file
         if ($articleFileManager->uploadedFileExists($fileName)) {
             $fileType = $articleFileManager->getUploadedFileType($fileName);
             $fileId = $articleFileManager->uploadPublicFile($fileName);
         }
         if (isset($fileType) && strstr($fileType, 'html')) {
             // Assume HTML galley
             $galley = new ArticleHTMLGalley();
         } else {
             $galley = new ArticleGalley();
         }
         $galley->setArticleId($this->articleId);
         $galley->setFileId($fileId);
         if ($this->getData('label') == null) {
             // Generate initial label based on file type
             $enablePublicGalleyId = $journal->getSetting('enablePublicGalleyId');
             if ($galley->isHTMLGalley()) {
                 $galley->setLabel('HTML');
                 if ($enablePublicGalleyId) {
                     $galley->setStoredPubId('publisher-id', 'html');
                 }
             } else {
                 if ($createRemote) {
                     $galley->setLabel(__('common.remote'));
                     $galley->setRemoteURL(__('common.remoteURL'));
                     if ($enablePublicGalleyId) {
                         $galley->setStoredPubId('publisher-id', strtolower(__('common.remote')));
                     }
                 } else {
                     if (isset($fileType)) {
                         if (strstr($fileType, 'pdf')) {
                             $galley->setLabel('PDF');
                             if ($enablePublicGalleyId) {
                                 $galley->setStoredPubId('publisher-id', 'pdf');
                             }
                         } else {
                             if (strstr($fileType, 'postscript')) {
                                 $galley->setLabel('PostScript');
                                 if ($enablePublicGalleyId) {
                                     $galley->setStoredPubId('publisher-id', 'ps');
                                 }
                             } else {
                                 if (strstr($fileType, 'xml')) {
                                     $galley->setLabel('XML');
                                     if ($enablePublicGalleyId) {
                                         $galley->setStoredPubId('publisher-id', 'xml');
                                     }
                                 } else {
                                     if (strstr($fileType, 'epub')) {
                                         $galley->setLabel('EPUB');
                                         if ($enablePublicGalleyId) {
                                             $galley->setStoredPubId('publisher-id', 'epub');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($galley->getLabel() == null) {
                 $galley->setLabel(__('common.untitled'));
             }
         } else {
             $galley->setLabel($this->getData('label'));
         }
         $galley->setLocale($article->getLocale());
         if ($enablePublicGalleyId) {
             // check to make sure the assigned public id doesn't already exist for another galley of this article
             $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
             /* @var $galleylDao ArticleGalleyDAO */
             $publicGalleyId = $galley->getPubId('publisher-id');
             $suffix = '';
             $i = 1;
             while ($galleyDao->getGalleyByPubId('publisher-id', $publicGalleyId . $suffix, $this->articleId)) {
                 $suffix = '_' . $i++;
             }
             $galley->setStoredPubId('publisher-id', $publicGalleyId . $suffix);
         }
         parent::execute();
         // Insert new galley
         $galleyDao->insertGalley($galley);
         $this->galleyId = $galley->getId();
     }
     if ($fileId) {
         // Update file search index
         import('classes.search.ArticleSearchIndex');
         $articleSearchIndex = new ArticleSearchIndex();
         $articleSearchIndex->articleFileChanged($this->articleId, ARTICLE_SEARCH_GALLEY_FILE, $fileId);
         $articleSearchIndex->articleChangesFinished();
     }
     // Stamp the article modification (for OAI)
     $articleDao->updateArticle($article);
     return $this->galleyId;
 }
Esempio n. 4
0
 /**
  * Rush a new submission into the end of the editing queue.
  * @param $article object
  */
 function expediteSubmission($article, $request)
 {
     $user =& $request->getUser();
     import('classes.submission.editor.EditorAction');
     import('classes.submission.sectionEditor.SectionEditorAction');
     import('classes.submission.proofreader.ProofreaderAction');
     $sectionEditorSubmissionDao =& DAORegistry::getDAO('SectionEditorSubmissionDAO');
     $sectionEditorSubmission =& $sectionEditorSubmissionDao->getSectionEditorSubmission($article->getId());
     $submissionFile = $sectionEditorSubmission->getSubmissionFile();
     // Add a log entry before doing anything.
     import('classes.article.log.ArticleLog');
     import('classes.article.log.ArticleEventLogEntry');
     ArticleLog::logEvent($request, $article, ARTICLE_LOG_EDITOR_EXPEDITE, 'log.editor.submissionExpedited', array('editorName' => $user->getFullName()));
     // 1. Ensure that an editor is assigned.
     $editAssignments =& $sectionEditorSubmission->getEditAssignments();
     if (empty($editAssignments)) {
         // No editors are currently assigned; assign self.
         EditorAction::assignEditor($article->getId(), $user->getId(), true, false, $request);
     }
     // 2. Accept the submission and send to copyediting.
     $sectionEditorSubmission =& $sectionEditorSubmissionDao->getSectionEditorSubmission($article->getId());
     if (!$sectionEditorSubmission->getFileBySignoffType('SIGNOFF_COPYEDITING_INITIAL', true)) {
         SectionEditorAction::recordDecision($sectionEditorSubmission, SUBMISSION_EDITOR_DECISION_ACCEPT, $request);
         $reviewFile = $sectionEditorSubmission->getReviewFile();
         SectionEditorAction::setCopyeditFile($sectionEditorSubmission, $reviewFile->getFileId(), $reviewFile->getRevision(), $request);
     }
     // 3. Add a galley.
     $sectionEditorSubmission =& $sectionEditorSubmissionDao->getSectionEditorSubmission($article->getId());
     $galleys =& $sectionEditorSubmission->getGalleys();
     $articleSearchIndex = null;
     if (empty($galleys)) {
         // No galley present -- use copyediting file.
         import('classes.file.ArticleFileManager');
         $copyeditFile =& $sectionEditorSubmission->getFileBySignoffType('SIGNOFF_COPYEDITING_INITIAL');
         $fileType = $copyeditFile->getFileType();
         $articleFileManager = new ArticleFileManager($article->getId());
         $fileId = $articleFileManager->copyPublicFile($copyeditFile->getFilePath(), $fileType);
         if (strstr($fileType, 'html')) {
             $galley = new ArticleHTMLGalley();
         } else {
             $galley = new ArticleGalley();
         }
         $galley->setArticleId($article->getId());
         $galley->setFileId($fileId);
         $galley->setLocale(AppLocale::getLocale());
         if ($galley->isHTMLGalley()) {
             $galley->setLabel('HTML');
         } else {
             if (strstr($fileType, 'pdf')) {
                 $galley->setLabel('PDF');
             } else {
                 if (strstr($fileType, 'postscript')) {
                     $galley->setLabel('Postscript');
                 } else {
                     if (strstr($fileType, 'xml')) {
                         $galley->setLabel('XML');
                     } else {
                         $galley->setLabel(__('common.untitled'));
                     }
                 }
             }
         }
         $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
         $galleyDao->insertGalley($galley);
         // Update file search index
         import('classes.search.ArticleSearchIndex');
         $articleSearchIndex = new ArticleSearchIndex();
         $articleSearchIndex->articleFileChanged($article->getId(), ARTICLE_SEARCH_GALLEY_FILE, $fileId);
     }
     $sectionEditorSubmission->setStatus(STATUS_QUEUED);
     $sectionEditorSubmissionDao->updateSectionEditorSubmission($sectionEditorSubmission);
     if ($articleSearchIndex) {
         $articleSearchIndex->articleChangesFinished();
     }
 }
Esempio n. 5
0
 /**
  * Save changes to the supplementary file.
  * @return int the supplementary file ID
  */
 function execute($fileName = null, $createRemote = false)
 {
     import('classes.file.ArticleFileManager');
     $articleFileManager = new ArticleFileManager($this->article->getId());
     $suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
     $fileName = isset($fileName) ? $fileName : 'uploadSuppFile';
     import('classes.search.ArticleSearchIndex');
     $articleSearchIndex = new ArticleSearchIndex();
     if (isset($this->suppFile)) {
         parent::execute();
         // Upload file, if file selected.
         if ($articleFileManager->uploadedFileExists($fileName)) {
             $fileId = $this->suppFile->getFileId();
             if ($fileId != 0) {
                 $articleFileManager->uploadSuppFile($fileName, $fileId);
             } else {
                 $fileId = $articleFileManager->uploadSuppFile($fileName);
                 $this->suppFile->setFileId($fileId);
             }
             $articleSearchIndex->articleFileChanged($this->article->getId(), ARTICLE_SEARCH_SUPPLEMENTARY_FILE, $fileId);
         }
         // Update existing supplementary file
         $this->setSuppFileData($this->suppFile);
         if ($this->getData('remoteURL')) {
             $this->suppFile->setRemoteURL($this->getData('remoteURL'));
         }
         $suppFileDao->updateSuppFile($this->suppFile);
     } else {
         // Upload file, if file selected.
         if ($articleFileManager->uploadedFileExists($fileName)) {
             $fileId = $articleFileManager->uploadSuppFile($fileName);
             $articleSearchIndex->articleFileChanged($this->article->getId(), ARTICLE_SEARCH_SUPPLEMENTARY_FILE, $fileId);
         } else {
             $fileId = 0;
         }
         // Insert new supplementary file
         $this->suppFile = new SuppFile();
         $this->suppFile->setArticleId($this->article->getId());
         $this->suppFile->setFileId($fileId);
         if ($createRemote) {
             $this->suppFile->setRemoteURL(__('common.remoteURL'));
         }
         parent::execute();
         $this->setSuppFileData($this->suppFile);
         $suppFileDao->insertSuppFile($this->suppFile);
         $this->suppFileId = $this->suppFile->getId();
     }
     // Index updated metadata.
     $articleSearchIndex->suppFileMetadataChanged($this->suppFile);
     $articleSearchIndex->articleChangesFinished();
     return $this->suppFileId;
 }