/** * 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; }
/** * @covers OAIMetadataFormat_DC * @covers Dc11SchemaArticleAdapter */ public function testToXml() { $this->markTestSkipped('Skipped because of weird class interaction with ControlledVocabDAO.'); // // Create test data. // $journalId = 1; // Enable the DOI plugin. $pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO'); /* @var $pluginSettingsDao PluginSettingsDAO */ $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enabled', 1); $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enableIssueDoi', 1); $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enableArticleDoi', 1); $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enableGalleyDoi', 1); // Author import('classes.article.Author'); $author = new Author(); $author->setFirstName('author-firstname'); $author->setLastName('author-lastname'); $author->setAffiliation('author-affiliation', 'en_US'); $author->setEmail('*****@*****.**'); // Article import('classes.article.PublishedArticle'); $article = $this->getMock('PublishedArticle', array('getBestArticleId')); /* @var $article PublishedArticle */ $article->expects($this->any())->method('getBestArticleId')->will($this->returnValue(9)); $article->setId(9); $article->setJournalId($journalId); $author->setSubmissionId($article->getId()); $article->setPages(15); $article->setType('art-type', 'en_US'); $article->setTitle('article-title-en', 'en_US'); $article->setTitle('article-title-de', 'de_DE'); $article->setDiscipline('article-discipline', 'en_US'); $article->setSubject('article-subject', 'en_US'); $article->setAbstract('article-abstract', 'en_US'); $article->setSponsor('article-sponsor', 'en_US'); $article->setStoredPubId('doi', 'article-doi'); $article->setLanguage('en_US'); // Galleys import('classes.article.ArticleGalley'); $galley = new ArticleGalley(); $galley->setId(98); $galley->setStoredPubId('doi', 'galley-doi'); $galleys = array($galley); // Journal import('classes.journal.Journal'); $journal = $this->getMock('Journal', array('getSetting')); /* @var $journal Journal */ $journal->expects($this->any())->method('getSetting')->will($this->returnCallback(array($this, 'getJournalSetting'))); $journal->setPrimaryLocale('en_US'); $journal->setPath('journal-path'); $journal->setId($journalId); // Section import('classes.journal.Section'); $section = new Section(); $section->setIdentifyType('section-identify-type', 'en_US'); // Issue import('classes.issue.Issue'); $issue = $this->getMock('Issue', array('getIssueIdentification')); /* @var $issue Issue */ $issue->expects($this->any())->method('getIssueIdentification')->will($this->returnValue('issue-identification')); $issue->setId(96); $issue->setDatePublished('2010-11-05'); $issue->setStoredPubId('doi', 'issue-doi'); $issue->setJournalId($journalId); // // Create infrastructural support objects // // Router import('lib.pkp.classes.core.PKPRouter'); $router = $this->getMock('PKPRouter', array('url')); $application = PKPApplication::getApplication(); $router->setApplication($application); $router->expects($this->any())->method('url')->will($this->returnCallback(array($this, 'routerUrl'))); // Request import('classes.core.Request'); $request = $this->getMock('Request', array('getRouter')); $request->expects($this->any())->method('getRouter')->will($this->returnValue($router)); Registry::set('request', $request); // // Create mock DAOs // // Create a mocked AuthorDAO that returns our test author. import('classes.article.AuthorDAO'); $authorDao = $this->getMock('AuthorDAO', array('getBySubmissionId')); $authorDao->expects($this->any())->method('getBySubmissionId')->will($this->returnValue(array($author))); DAORegistry::registerDAO('AuthorDAO', $authorDao); // Create a mocked OAIDAO that returns our test data. import('classes.oai.ojs.OAIDAO'); $oaiDao = $this->getMock('OAIDAO', array('getJournal', 'getSection', 'getIssue')); $oaiDao->expects($this->any())->method('getJournal')->will($this->returnValue($journal)); $oaiDao->expects($this->any())->method('getSection')->will($this->returnValue($section)); $oaiDao->expects($this->any())->method('getIssue')->will($this->returnValue($issue)); DAORegistry::registerDAO('OAIDAO', $oaiDao); // Create a mocked ArticleGalleyDAO that returns our test data. import('classes.article.ArticleGalleyDAO'); $articleGalleyDao = $this->getMock('ArticleGalleyDAO', array('getBySubmissionId')); $articleGalleyDao->expects($this->any())->method('getBySubmissionId')->will($this->returnValue($galleys)); DAORegistry::registerDAO('ArticleGalleyDAO', $articleGalleyDao); // FIXME: ArticleGalleyDAO::getBySubmissionId returns iterator; array expected here. Fix expectations. // Create a mocked PublishedArticleDAO that returns our test article. import('classes.article.PublishedArticleDAO'); $articleDao = $this->getMock('PublishedArticleDAO', array('getPublishedArticleByArticleId')); $articleDao->expects($this->any())->method('getPublishedArticleByArticleId')->will($this->returnValue($article)); DAORegistry::registerDAO('PublishedArticleDAO', $articleDao); // // Test // // OAI record $record = new OAIRecord(); $record->setData('article', $article); $record->setData('galleys', $galleys); $record->setData('journal', $journal); $record->setData('section', $section); $record->setData('issue', $issue); // Instantiate the OAI meta-data format. $prefix = OAIMetadataFormatPlugin_DC::getMetadataPrefix(); $schema = OAIMetadataFormatPlugin_DC::getSchema(); $namespace = OAIMetadataFormatPlugin_DC::getNamespace(); $mdFormat = new OAIMetadataFormat_DC($prefix, $schema, $namespace); $xml = $mdFormat->toXml($record); self::assertXmlStringEqualsXmlFile('tests/plugins/oaiMetadataFormats/dc/expectedResult.xml', $xml); }
function handleGalleyNode(&$journal, &$galleyNode, &$issue, &$section, &$article, &$errors, $isCommandLine, $isHtml, $galleyCount, &$articleFileManager) { $errors = array(); $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames()); // => journal locales must be set up before $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO'); if ($isHtml) { $galley = new ArticleHtmlGalley(); } else { $galley = new ArticleGalley(); } if (($value = $galleyNode->getAttribute('public_id')) != '') { $anotherGalley = $galleyDao->getGalleyByPubId('publisher-id', $value, $article->getId()); if ($anotherGalley) { $errors[] = array('plugins.importexport.native.import.error.duplicatePublicGalleyId', array('publicId' => $value, 'articleTitle' => $article->getLocalizedTitle())); $hasErrors = true; } else { $galley->setStoredPubId('publisher-id', $value); } } $galley->setArticleId($article->getId()); $galley->setSequence($galleyCount); /* --- Set IDs --- */ if (!NativeImportDom::handlePubIds($galleyNode, $galley, $journal, $issue, $article, $errors)) { return false; } // just journal supported locales? $locale = $galleyNode->getAttribute('locale'); if ($locale == '') { $locale = $article->getLocale(); } elseif (!in_array($locale, $journalSupportedLocales)) { $errors[] = array('plugins.importexport.native.import.error.galleyLocaleUnsupported', array('articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale)); return false; } $galley->setLocale($locale); /* --- Galley Label --- */ if (!($node = $galleyNode->getChildByName('label'))) { $errors[] = array('plugins.importexport.native.import.error.galleyLabelMissing', array('articleTitle' => $article->getLocalizedTitle(), 'sectionTitle' => $section->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification())); return false; } $galley->setLabel($node->getValue()); /* --- Galley File --- */ if (!($node = $galleyNode->getChildByName('file'))) { $errors[] = array('plugins.importexport.native.import.error.galleyFileMissing', array('articleTitle' => $article->getLocalizedTitle(), 'sectionTitle' => $section->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification())); return false; } if ($href = $node->getChildByName('href')) { $url = $href->getAttribute('src'); if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) { if ($isCommandLine && NativeImportDom::isRelativePath($url)) { // The command-line tool does a chdir; we need to prepend the original pathname to relative paths so we're not looking in the wrong place. $url = PWD . '/' . $url; } if (($fileId = $articleFileManager->copyPublicFile($url, $href->getAttribute('mime_type'))) === false) { $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url)); return false; } } } if ($embed = $node->getChildByName('embed')) { if (($type = $embed->getAttribute('encoding')) !== 'base64') { $errors[] = array('plugins.importexport.native.import.error.unknownEncoding', array('type' => $type)); return false; } $originalName = $embed->getAttribute('filename'); if (($fileId = $articleFileManager->writePublicFile($originalName, base64_decode($embed->getValue()), $embed->getAttribute('mime_type'))) === false) { $errors[] = array('plugins.importexport.native.import.error.couldNotWriteFile', array('originalName' => $originalName)); return false; } } if (!isset($fileId)) { $errors[] = array('plugins.importexport.native.import.error.galleyFileMissing', array('articleTitle' => $article->getLocalizedTitle(), 'sectionTitle' => $section->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification())); return false; } $galley->setFileId($fileId); $galleyDao->insertGalley($galley); if ($isHtml) { $result = NativeImportDom::handleHtmlGalleyNodes($galleyNode, $articleFileManager, $galley, $errors, $isCommandLine); if (!$result) { return false; } } return true; }