/** * 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; }
/** * Save changes to the galley. * @return int the galley ID */ function execute($fileName = null) { import('file.ArticleFileManager'); $articleFileManager = new ArticleFileManager($this->articleId); $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO'); $fileName = isset($fileName) ? $fileName : 'galleyFile'; $journal =& Request::getJournal(); if (isset($this->galley)) { $galley =& $this->galley; // Upload galley file if ($articleFileManager->uploadedFileExists($fileName)) { if ($galley->getFileId()) { $articleFileManager->uploadPublicFile($fileName, $galley->getFileId()); } else { $fileId = $articleFileManager->uploadPublicFile($fileName); $galley->setFileId($fileId); } // Update file search index import('search.ArticleSearchIndex'); ArticleSearchIndex::updateFileIndex($this->articleId, ARTICLE_SEARCH_GALLEY_FILE, $galley->getFileId()); } 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->setPublicGalleyId($this->getData('publicGalleyId')); } $galley->setLocale($this->getData('galleyLocale')); $galleyDao->updateGalley($galley); } else { // Upload galley file if ($articleFileManager->uploadedFileExists($fileName)) { $fileType = $articleFileManager->getUploadedFileType($fileName); $fileId = $articleFileManager->uploadPublicFile($fileName); // Update file search index import('search.ArticleSearchIndex'); ArticleSearchIndex::updateFileIndex($this->articleId, ARTICLE_SEARCH_GALLEY_FILE, $fileId); } else { $fileId = 0; } 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->setPublicGalleyId('html'); } } else { if (isset($fileType)) { if (strstr($fileType, 'pdf')) { $galley->setLabel('PDF'); if ($enablePublicGalleyId) { $galley->setPublicgalleyId('pdf'); } } else { if (strstr($fileType, 'postscript')) { $galley->setLabel('PostScript'); if ($enablePublicGalleyId) { $galley->setPublicgalleyId('ps'); } } else { if (strstr($fileType, 'xml')) { $galley->setLabel('XML'); if ($enablePublicGalleyId) { $galley->setPublicgalleyId('xml'); } } } } } } if ($galley->getLabel() == null) { $galley->setLabel(Locale::translate('common.untitled')); } } else { $galley->setLabel($this->getData('label')); } $galley->setLocale($this->getData('galleyLocale')); if ($enablePublicGalleyId) { // check to make sure the assigned public id doesn't already exist $publicGalleyId = $galley->getPublicgalleyId(); $suffix = ''; $i = 1; while ($galleyDao->publicGalleyIdExists($publicGalleyId . $suffix, 0, $galley->getArticleId())) { $suffix = '_' . $i++; } $galley->setPublicgalleyId($publicGalleyId . $suffix); } // Insert new galley $galleyDao->insertGalley($galley); $this->galleyId = $galley->getId(); } return $this->galleyId; }