/** * Save changes to the supplementary file. * @return int the supplementary file ID */ function execute($fileName = null) { import("file.PaperFileManager"); $paperFileManager = new PaperFileManager($this->paper->getPaperId()); $suppFileDao =& DAORegistry::getDAO('SuppFileDAO'); $fileName = isset($fileName) ? $fileName : 'uploadSuppFile'; if (isset($this->suppFile)) { $suppFile =& $this->suppFile; // Upload file, if file selected. if ($paperFileManager->uploadedFileExists($fileName)) { $paperFileManager->uploadSuppFile($fileName, $suppFile->getFileId()); import('search.PaperSearchIndex'); PaperSearchIndex::updateFileIndex($this->paper->getPaperId(), PAPER_SEARCH_SUPPLEMENTARY_FILE, $suppFile->getFileId()); } // Index metadata PaperSearchIndex::indexSuppFileMetadata($suppFile); // Update existing supplementary file $this->setSuppFileData($suppFile); $suppFileDao->updateSuppFile($suppFile); } else { // Upload file, if file selected. if ($paperFileManager->uploadedFileExists($fileName)) { $fileId = $paperFileManager->uploadSuppFile($fileName); import('search.PaperSearchIndex'); PaperSearchIndex::updateFileIndex($this->paper->getPaperId(), PAPER_SEARCH_SUPPLEMENTARY_FILE, $fileId); } else { $fileId = 0; } // Insert new supplementary file $suppFile = new SuppFile(); $suppFile->setPaperId($this->paper->getPaperId()); $suppFile->setFileId($fileId); $this->setSuppFileData($suppFile); $suppFileDao->insertSuppFile($suppFile); $this->suppFileId = $suppFile->getId(); } return $this->suppFileId; }
/** * Internal function to return a SuppFile object from a row. * @param $row array * @return SuppFile */ function &_returnSuppFileFromRow(&$row) { $suppFile = new SuppFile(); $suppFile->setId($row['supp_id']); $suppFile->setPublicSuppFileId($row['public_supp_file_id']); $suppFile->setFileId($row['file_id']); $suppFile->setArticleId($row['article_id']); $suppFile->setType($row['type']); $suppFile->setDateCreated($this->dateFromDB($row['date_created'])); $suppFile->setLanguage($row['language']); $suppFile->setShowReviewers($row['show_reviewers']); $suppFile->setDateSubmitted($this->datetimeFromDB($row['date_submitted'])); $suppFile->setSequence($row['seq']); $suppFile->setSuppAssocId($row['assoc_id']); //ArticleFile set methods $suppFile->setFileName($row['file_name']); $suppFile->setOriginalFileName($row['original_file_name']); $suppFile->setFileType($row['file_type']); $suppFile->setFileSize($row['file_size']); $suppFile->setDateModified($this->datetimeFromDB($row['date_modified'])); $suppFile->setDateUploaded($this->datetimeFromDB($row['date_uploaded'])); $this->getDataObjectSettings('article_supp_file_settings', 'supp_id', $row['supp_id'], $suppFile); HookRegistry::call('SuppFileDAO::_returnSuppFileFromRow', array(&$suppFile, &$row)); return $suppFile; }
function handleSuppFileNode(&$journal, &$suppNode, &$issue, &$section, &$article, &$errors, $isCommandLine, &$articleFileManager) { $errors = array(); $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames()); // => journal locales must be set up before $journalPrimaryLocale = $journal->getPrimaryLocale(); $suppFileDao =& DAORegistry::getDAO('SuppFileDAO'); $suppFile = new SuppFile(); $suppFile->setArticleId($article->getId()); for ($index = 0; $node = $suppNode->getChildByName('title', $index); $index++) { $locale = $node->getAttribute('locale'); if ($locale == '') { $locale = $journalPrimaryLocale; } elseif (!in_array($locale, $journalSupportedLocales)) { $errors[] = array('plugins.importexport.native.import.error.articleSuppFileTitleLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale)); return false; } $suppFile->setTitle($node->getValue(), $locale); } for ($index = 0; $node = $suppNode->getChildByName('creator', $index); $index++) { $locale = $node->getAttribute('locale'); if ($locale == '') { $locale = $journalPrimaryLocale; } elseif (!in_array($locale, $journalSupportedLocales)) { $errors[] = array('plugins.importexport.native.import.error.articleSuppFileCreatorLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale)); return false; } $suppFile->setCreator($node->getValue(), $locale); } for ($index = 0; $node = $suppNode->getChildByName('subject', $index); $index++) { $locale = $node->getAttribute('locale'); if ($locale == '') { $locale = $journalPrimaryLocale; } elseif (!in_array($locale, $journalSupportedLocales)) { $errors[] = array('plugins.importexport.native.import.error.articleSuppFileSubjectLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale)); return false; } $suppFile->setSubject($node->getValue(), $locale); } for ($index = 0; $node = $suppNode->getChildByName('type_other', $index); $index++) { $locale = $node->getAttribute('locale'); if ($locale == '') { $locale = $journalPrimaryLocale; } elseif (!in_array($locale, $journalSupportedLocales)) { $errors[] = array('plugins.importexport.native.import.error.articleSuppFileTypeOtherLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale)); return false; } $suppFile->setTypeOther($node->getValue(), $locale); } for ($index = 0; $node = $suppNode->getChildByName('description', $index); $index++) { $locale = $node->getAttribute('locale'); if ($locale == '') { $locale = $journalPrimaryLocale; } elseif (!in_array($locale, $journalSupportedLocales)) { $errors[] = array('plugins.importexport.native.import.error.articleSuppFileDescriptionLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale)); return false; } $suppFile->setDescription($node->getValue(), $locale); } for ($index = 0; $node = $suppNode->getChildByName('publisher', $index); $index++) { $locale = $node->getAttribute('locale'); if ($locale == '') { $locale = $journalPrimaryLocale; } elseif (!in_array($locale, $journalSupportedLocales)) { $errors[] = array('plugins.importexport.native.import.error.articleSuppFilePublisherLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale)); return false; } $suppFile->setPublisher($node->getValue(), $locale); } for ($index = 0; $node = $suppNode->getChildByName('sponsor', $index); $index++) { $locale = $node->getAttribute('locale'); if ($locale == '') { $locale = $journalPrimaryLocale; } elseif (!in_array($locale, $journalSupportedLocales)) { $errors[] = array('plugins.importexport.native.import.error.articleSuppFileSponsorLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale)); return false; } $suppFile->setSponsor($node->getValue(), $locale); } for ($index = 0; $node = $suppNode->getChildByName('source', $index); $index++) { $locale = $node->getAttribute('locale'); if ($locale == '') { $locale = $journalPrimaryLocale; } elseif (!in_array($locale, $journalSupportedLocales)) { $errors[] = array('plugins.importexport.native.import.error.articleSuppFileSourceLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale)); return false; } $suppFile->setSource($node->getValue(), $locale); } if ($node = $suppNode->getChildByName('date_created')) { $createdDate = strtotime($node->getValue()); if ($createdDate !== -1) { $suppFile->setDateCreated($createdDate); } } switch ($suppType = $suppNode->getAttribute('type')) { case 'research_instrument': $suppFile->setType(__('author.submit.suppFile.researchInstrument')); break; case 'research_materials': $suppFile->setType(__('author.submit.suppFile.researchMaterials')); break; case 'research_results': $suppFile->setType(__('author.submit.suppFile.researchResults')); break; case 'transcripts': $suppFile->setType(__('author.submit.suppFile.transcripts')); break; case 'data_analysis': $suppFile->setType(__('author.submit.suppFile.dataAnalysis')); break; case 'data_set': $suppFile->setType(__('author.submit.suppFile.dataSet')); break; case 'source_text': $suppFile->setType(__('author.submit.suppFile.sourceText')); break; case 'other': $suppFile->setType(''); break; default: $errors[] = array('plugins.importexport.native.import.error.unknownSuppFileType', array('suppFileType' => $suppType)); return false; } $suppFile->setLanguage($suppNode->getAttribute('language')); $suppFile->setPublicSuppFileId($suppNode->getAttribute('public_id')); if (!($fileNode = $suppNode->getChildByName('file'))) { $errors[] = array('plugins.importexport.native.import.error.suppFileMissing', array('articleTitle' => $article->getLocalizedTitle(), 'sectionTitle' => $section->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification())); return false; } if ($href = $fileNode->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->copySuppFile($url, $href->getAttribute('mime_type'))) === false) { $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url)); return false; } } } if ($embed = $fileNode->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->writeSuppFile($originalName, base64_decode($embed->getValue()), $embed->getAttribute('mime_type'))) === false) { $errors[] = array('plugins.importexport.native.import.error.couldNotWriteFile', array('originalName' => $originalName)); return false; } } if (!$fileId) { $errors[] = array('plugins.importexport.native.import.error.suppFileMissing', array('articleTitle' => $article->getLocalizedTitle(), 'sectionTitle' => $section->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification())); return false; } $suppFile->setFileId($fileId); $suppFileDao->insertSuppFile($suppFile); return true; }
/** * Save changes to the supplementary file. * @return int the supplementary file ID */ function execute() { import('classes.file.ArticleFileManager'); $articleFileManager = new ArticleFileManager($this->articleId); $suppFileDao =& DAORegistry::getDAO('SuppFileDAO'); $fileName = 'uploadSuppFile'; // edit an existing supp file, otherwise create new supp file entry if (isset($this->suppFile)) { $suppFile =& $this->suppFile; // Remove old file and upload new, if file is selected. if ($articleFileManager->uploadedFileExists($fileName)) { $articleFileDao =& DAORegistry::getDAO('ArticleFileDAO'); $suppFileId = $articleFileManager->uploadSuppFile($fileName, $suppFile->getFileId(), true); $suppFile->setFileId($suppFileId); } // Update existing supplementary file $this->setSuppFileData($suppFile); $suppFileDao->updateSuppFile($suppFile); } else { // Upload file, if file selected. if ($articleFileManager->uploadedFileExists($fileName)) { $fileId = $articleFileManager->uploadSuppFile($fileName); // Insert new supplementary file $suppFile = new SuppFile(); $suppFile->setArticleId($this->articleId); $suppFile->setFileId($fileId); $this->setSuppFileData($suppFile); $suppFileDao->insertSuppFile($suppFile); $this->suppFileId = $suppFile->getId(); } else { $fileId = 0; } } return $this->suppFileId; }
/** * Save changes to the supplementary file. * @return int the supplementary file ID */ function execute($fileName = null) { import('classes.file.ArticleFileManager'); $articleFileManager = new ArticleFileManager($this->article->getArticleId()); $suppFileDao =& DAORegistry::getDAO('SuppFileDAO'); $fileName = isset($fileName) ? $fileName : 'uploadSuppFile'; if (isset($this->suppFile)) { $suppFile =& $this->suppFile; // Upload file, if file selected. if ($articleFileManager->uploadedFileExists($fileName)) { $articleFileManager->uploadSuppFile($fileName, $suppFile->getFileId()); import('classes.search.ArticleSearchIndex'); ArticleSearchIndex::updateFileIndex($this->article->getArticleId(), ARTICLE_SEARCH_SUPPLEMENTARY_FILE, $suppFile->getFileId()); } // Index metadata ArticleSearchIndex::indexSuppFileMetadata($suppFile); // Update existing supplementary file $this->setSuppFileData($suppFile); $suppFileDao->updateSuppFile($suppFile); } else { // Upload file, if file selected. if ($articleFileManager->uploadedFileExists($fileName)) { $fileId = $articleFileManager->uploadSuppFile($fileName); import('classes.search.ArticleSearchIndex'); ArticleSearchIndex::updateFileIndex($this->article->getArticleId(), ARTICLE_SEARCH_SUPPLEMENTARY_FILE, $fileId); } else { $fileId = 0; } // Insert new supplementary file $suppFile = new SuppFile(); $suppFile->setArticleId($this->article->getArticleId()); $suppFile->setFileId($fileId); $this->setSuppFileData($suppFile); $suppFileDao->insertSuppFile($suppFile); $this->suppFileId = $suppFile->getId(); } return $this->suppFileId; }
/** * @covers OAIMetadataFormat_DC * @covers Dc11SchemaArticleAdapter */ public function testToXml() { // // Create test data. // // Author import('classes.article.Author'); $author = new Author(); $author->setFirstName('author-firstname'); $author->setLastName('author-lastname'); $author->setAffiliation('author-affiliation', 'en_US'); // Supplementary file import('classes.article.SuppFile'); $suppFile = new SuppFile(); $suppFile->setFileId(999); // 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->addAuthor($author); $article->setSuppFiles(array($suppFile)); $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->setSubjectClass('article-subject-class', 'en_US'); $article->setAbstract('article-abstract', 'en_US'); $article->setSponsor('article-sponsor', 'en_US'); $article->setStoredDOI('article-doi'); $article->setLanguage('en_US'); $article->setCoverageGeo('article-coverage-geo', 'en_US'); $article->setCoverageChron('article-coverage-chron', 'en_US'); $article->setCoverageSample('article-coverage-sample', 'en_US'); // Galleys import('classes.article.ArticleGalley'); $galley = new ArticleGalley(); $galley->setFileType('galley-filetype'); $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'); // 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->setDatePublished('2010-11-05'); // // 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->returnValue('router-url')); // 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 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('OAIDAO', array('getGalleysByArticle')); $articleGalleyDao->expects($this->any())->method('getGalleysByArticle')->will($this->returnValue($galleys)); DAORegistry::registerDAO('ArticleGalleyDAO', $articleGalleyDao); // // 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); }
/** * Save changes to the supplementary file. * @return int the supplementary file ID */ function execute($fileName = null) { import('classes.file.ArticleFileManager'); $articleFileManager = new ArticleFileManager($this->article->getArticleId()); $suppFileDao =& DAORegistry::getDAO('SuppFileDAO'); $fileName = isset($fileName) ? $fileName : 'uploadSuppFile'; if (isset($this->suppFile)) { $suppFile =& $this->suppFile; // Upload file, if file selected. if ($articleFileManager->uploadedFileExists($fileName)) { $articleFileManager->uploadSuppFile($fileName, $suppFile->getFileId()); import('classes.search.ArticleSearchIndex'); ArticleSearchIndex::updateFileIndex($this->article->getArticleId(), ARTICLE_SEARCH_SUPPLEMENTARY_FILE, $suppFile->getFileId()); } // Index metadata ArticleSearchIndex::indexSuppFileMetadata($suppFile); // Update existing supplementary file $this->setSuppFileData($suppFile); $suppFileDao->updateSuppFile($suppFile); } else { // Upload file, if file selected. if ($articleFileManager->uploadedFileExists($fileName)) { $fileId = $articleFileManager->uploadSuppFile($fileName); import('classes.search.ArticleSearchIndex'); ArticleSearchIndex::updateFileIndex($this->article->getArticleId(), ARTICLE_SEARCH_SUPPLEMENTARY_FILE, $fileId); // Insert new supplementary file $suppFile = new SuppFile(); $suppFile->setArticleId($this->article->getArticleId()); $suppFile->setFileId($fileId); $this->setSuppFileData($suppFile); $suppFileDao->insertSuppFile($suppFile); $this->suppFileId = $suppFile->getId(); } else { $fileId = 0; } } // Notifications import('lib.pkp.classes.notification.NotificationManager'); $notificationManager = new NotificationManager(); $journal =& Request::getJournal(); $url = Request::url($journal->getPath(), 'sectionEditor', 'submission', array($this->article->getArticleId(), 'submissionReview')); $sectionEditorsDao =& DAORegistry::getDAO('SectionEditorsDAO'); $sectionEditors =& $sectionEditorsDao->getEditorsBySectionId($journal->getId(), $this->article->getSectionId()); foreach ($sectionEditors as $sectionEditor) { $notificationSectionEditors[] = array('id' => $sectionEditor->getId()); } if ($suppFile->getData('type') == 'Raw Data File') { $message = 'notification.type.rawDataSubmitted'; } if ($suppFile->getData('type') == 'Other Supplementary Research Output') { $message = 'notification.type.otherSuppResearchOutput'; } if ($suppFile->getData('type') == 'Progress Report') { $message = 'notification.type.progressReport'; } if ($suppFile->getData('type') == 'Completion Report') { $message = 'notification.type.completionReport'; } if ($suppFile->getData('type') == 'Extension Request') { $message = 'notification.type.extensionRequest'; } if ($this->getData('type') == "Supp File") { $message = 'notification.type.suppFile'; } if (isset($message)) { foreach ($notificationSectionEditors as $userRole) { $notificationManager->createNotification($userRole['id'], $message, $this->article->getLocalizedTitle(), $url, 1, NOTIFICATION_TYPE_SUPP_FILE_MODIFIED); } } return $this->suppFileId; }
/** * Save changes to the supplementary file. * @return int the supplementary file ID */ function execute($fileName = null) { import('classes.file.ArticleFileManager'); $articleFileManager = new ArticleFileManager($this->article->getArticleId()); $suppFileDao =& DAORegistry::getDAO('SuppFileDAO'); $fileName = 'uploadSuppFile'; // Upload file, if file selected. if ($articleFileManager->uploadedFileExists($fileName)) { $fileId = $articleFileManager->uploadSuppFile($fileName); import('classes.search.ArticleSearchIndex'); ArticleSearchIndex::updateFileIndex($this->article->getArticleId(), ARTICLE_SEARCH_SUPPLEMENTARY_FILE, $fileId); // Insert new supplementary file $suppFile = new SuppFile(); $suppFile->setArticleId($this->article->getArticleId()); $suppFile->setFileId($fileId); $this->setSuppFileData($suppFile); $suppFileDao->insertSuppFile($suppFile); $this->suppFileId = $suppFile->getId(); } else { $fileId = 0; } // Save article settings (withdrawReason and withdrawComments) $articleDao =& DAORegistry::getDAO('ArticleDAO'); $article =& $this->article; $article->setWithdrawReason($this->getData('withdrawReason'), null); if ($article->getWithdrawReason('en_US') == "2") { $article->setWithdrawReason($this->getData('otherReason'), null); } $article->setWithdrawComments($this->getData('withdrawComments'), null); // Save the article $articleDao->updateArticle($article); return $this->suppFileId; }