Inheritance: extends FileManager
 /**
  * An action to download an issue galley
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function download($args, $request)
 {
     $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
     $issueGalley = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE_GALLEY);
     import('classes.file.IssueFileManager');
     $issueFileManager = new IssueFileManager($issue->getId());
     return $issueFileManager->downloadFile($issueGalley->getFileId());
 }
Beispiel #2
0
 /**
  * Save changes to the galley.
  * @param $request PKPRequest
  * @return int the galley ID
  */
 function execute($request)
 {
     import('classes.file.IssueFileManager');
     $issueFileManager = new IssueFileManager($this->_issue->getId());
     $journal = $request->getJournal();
     $user = $request->getUser();
     $issueGalley = $this->_issueGalley;
     $issueGalleyDao = DAORegistry::getDAO('IssueGalleyDAO');
     // If a temporary file ID was specified (i.e. an upload occurred), get the file for later.
     $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO');
     $temporaryFile = $temporaryFileDao->getTemporaryFile($this->getData('temporaryFileId'), $user->getId());
     if ($issueGalley) {
         // Update an existing galley
         if ($temporaryFile) {
             // Galley has a file, delete it before uploading new one
             if ($issueGalley->getFileId()) {
                 $issueFileManager->deleteFile($issueGalley->getFileId());
             }
             // Upload new file
             $issueFile = $issueFileManager->fromTemporaryFile($temporaryFile);
             $issueGalley->setFileId($issueFile->getFileId());
         }
         $issueGalley->setLabel($this->getData('label'));
         $issueGalley->setStoredPubId('publisher-id', $this->getData('publicGalleyId'));
         $issueGalley->setLocale($this->getData('galleyLocale'));
         // Update galley in the db
         $issueGalleyDao->updateObject($issueGalley);
     } else {
         // Create a new galley
         $issueGalleyFile = $issueFileManager->fromTemporaryFile($temporaryFile);
         $issueGalley = $issueGalleyDao->newDataObject();
         $issueGalley->setIssueId($this->_issue->getId());
         $issueGalley->setFileId($issueGalleyFile->getId());
         if ($this->getData('label') == null) {
             // Generate initial label based on file type
             if (isset($fileType)) {
                 if (strstr($fileType, 'pdf')) {
                     $issueGalley->setLabel('PDF');
                 } else {
                     if (strstr($fileType, 'postscript')) {
                         $issueGalley->setLabel('PostScript');
                     } else {
                         if (strstr($fileType, 'xml')) {
                             $issueGalley->setLabel('XML');
                         }
                     }
                 }
             }
             if ($issueGalley->getLabel() == null) {
                 $issueGalley->setLabel(__('common.untitled'));
             }
         } else {
             $issueGalley->setLabel($this->getData('label'));
         }
         $issueGalley->setLocale($this->getData('galleyLocale'));
         $issueGalley->setStoredPubId('publisher-id', $this->getData('publicGalleyId'));
         // Insert new galley into the db
         $issueGalleyDao->insertObject($issueGalley);
         $this->_issueGalley = $issueGalley;
     }
     return $this->_issueGalley->getId();
 }
 /**
  * Show an issue galley file (either inline or download)
  * @param $issueId int
  * @param $galleyId int
  * @param $request Request
  * @param $inline boolean
  */
 function _showIssueGalley($request, $inline = false)
 {
     $journal =& $request->getJournal();
     $issue =& $this->getIssue();
     $galley =& $this->getGalley();
     $galleyDao =& DAORegistry::getDAO('IssueGalleyDAO');
     if (!HookRegistry::call('IssueHandler::viewFile', array(&$issue, &$galley))) {
         import('classes.file.IssueFileManager');
         $issueFileManager = new IssueFileManager($issue->getId());
         return $issueFileManager->downloadFile($galley->getFileId(), $inline);
     }
 }
Beispiel #4
0
 /**
  * Delete issue. Deletes associated issue galleys, cover pages, and published articles.
  * @param $issue object issue
  */
 function deleteObject($issue)
 {
     import('classes.file.PublicFileManager');
     $publicFileManager = new PublicFileManager();
     $coverImage = $issue->getCoverImage();
     if (!empty($coverImage)) {
         $publicFileManager->removeJournalFile($issue->getJournalId(), $coverImage);
     }
     $issueId = $issue->getId();
     // Delete issue-specific ordering if it exists.
     $sectionDao = DAORegistry::getDAO('SectionDAO');
     $sectionDao->deleteCustomSectionOrdering($issueId);
     // Delete published issue galleys and issue files
     $issueGalleyDao = DAORegistry::getDAO('IssueGalleyDAO');
     $issueGalleyDao->deleteByIssueId($issueId);
     $issueFileDao = DAORegistry::getDAO('IssueFileDAO');
     $issueFileDao->deleteByIssueId($issueId);
     import('classes.file.IssueFileManager');
     $issueFileManager = new IssueFileManager($issueId);
     $issueFileManager->deleteIssueTree();
     // Delete published articles
     $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
     $publishedArticleDao->deletePublishedArticlesByIssueId($issueId);
     // Delete issue settings and issue
     $this->update('DELETE FROM issue_settings WHERE issue_id = ?', (int) $issueId);
     $this->update('DELETE FROM issues WHERE issue_id = ?', (int) $issueId);
     $this->update('DELETE FROM custom_issue_orders WHERE issue_id = ?', (int) $issueId);
     $this->resequenceCustomIssueOrders($issue->getJournalId());
     $this->flushCache();
 }
 /**
  * Download an issue file.
  * @param $args array ($issueId, $fileId)
  */
 function downloadIssueFile($args, $request)
 {
     $issueId = isset($args[0]) ? (int) $args[0] : 0;
     $fileId = isset($args[1]) ? (int) $args[1] : 0;
     $this->validate($issueId, true);
     if ($fileId) {
         import('classes.file.IssueFileManager');
         $issueFileManager = new IssueFileManager($issueId);
         return $issueFileManager->downloadFile($fileId);
     }
     $request->redirect(null, null, 'issueGalleys', $issueId);
 }
Beispiel #6
0
 /**
  * Delete issue. Deletes associated issue galleys, cover pages, and published articles.
  * @param $issue object issue
  */
 function deleteIssue(&$issue)
 {
     import('classes.file.PublicFileManager');
     $publicFileManager = new PublicFileManager();
     if (is_array($issue->getFileName(null))) {
         foreach ($issue->getFileName(null) as $fileName) {
             if ($fileName != '') {
                 $publicFileManager->removeJournalFile($issue->getJournalId(), $fileName);
             }
         }
     }
     if (($fileName = $issue->getStyleFileName()) != '') {
         $publicFileManager->removeJournalFile($issue->getJournalId(), $fileName);
     }
     $issueId = $issue->getId();
     // Delete issue-specific ordering if it exists.
     $sectionDao =& DAORegistry::getDAO('SectionDAO');
     $sectionDao->deleteCustomSectionOrdering($issueId);
     // Delete published issue galleys and issue files
     $issueGalleyDao =& DAORegistry::getDAO('IssueGalleyDAO');
     $issueGalleyDao->deleteGalleysByIssue($issueId);
     $issueFileDao =& DAORegistry::getDAO('IssueFileDAO');
     $issueFileDao->deleteIssueFiles($issueId);
     import('classes.file.IssueFileManager');
     $issueFileManager = new IssueFileManager($issueId);
     $issueFileManager->deleteIssueTree();
     // Delete published articles
     $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
     $publishedArticleDao->deletePublishedArticlesByIssueId($issueId);
     // Delete issue settings and issue
     $this->update('DELETE FROM issue_settings WHERE issue_id = ?', (int) $issueId);
     $this->update('DELETE FROM issues WHERE issue_id = ?', (int) $issueId);
     $this->update('DELETE FROM custom_issue_orders WHERE issue_id = ?', (int) $issueId);
     $this->resequenceCustomIssueOrders($issue->getJournalId());
     $this->flushCache();
 }
Beispiel #7
0
 /**
  * Save changes to the galley.
  * @return int the galley ID
  */
 function execute($fileName = null)
 {
     import('classes.file.IssueFileManager');
     $issueFileManager = new IssueFileManager($this->getIssueId());
     $galleyDao =& DAORegistry::getDAO('IssueGalleyDAO');
     $fileName = isset($fileName) ? $fileName : 'galleyFile';
     $journal =& Request::getJournal();
     $galley =& $this->getGalley();
     // Update an existing galley
     if ($galley) {
         if ($issueFileManager->uploadedFileExists($fileName)) {
             // Galley has a file, delete it before uploading new one
             if ($galley->getFileId()) {
                 $issueFileManager->deleteFile($galley->getFileId());
             }
             // Upload new file
             $fileId = $issueFileManager->uploadPublicFile($fileName);
             $galley->setFileId($fileId);
         }
         $galley->setLabel($this->getData('label'));
         if ($journal->getSetting('enablePublicGalleyId')) {
             $galley->setStoredPubId('publisher-id', $this->getData('publicGalleyId'));
         }
         $galley->setLocale($this->getData('galleyLocale'));
         // Update galley in the db
         $galleyDao->updateGalley($galley);
     } else {
         // Create a new galley
         // Upload galley file
         if ($issueFileManager->uploadedFileExists($fileName)) {
             $fileType = $issueFileManager->getUploadedFileType($fileName);
             $fileId = $issueFileManager->uploadPublicFile($fileName);
         } else {
             // No galley file uploaded
             $fileId = 0;
         }
         $galley = new IssueGalley();
         $galley->setIssueId($this->getIssueId());
         $galley->setFileId($fileId);
         if ($this->getData('label') == null) {
             // Generate initial label based on file type
             $enablePublicGalleyId = $journal->getSetting('enablePublicGalleyId');
             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');
                             }
                         }
                     }
                 }
             }
             if ($galley->getLabel() == null) {
                 $galley->setLabel(__('common.untitled'));
             }
         } else {
             $galley->setLabel($this->getData('label'));
         }
         $galley->setLocale($this->getData('galleyLocale'));
         if ($enablePublicGalleyId) {
             // Ensure the assigned public id doesn't already exist
             $journalDao =& DAORegistry::getDAO('JournalDAO');
             /* @var $journalDao JournalDAO */
             $publicGalleyId = $galley->getPubId('publisher-id');
             $suffix = '';
             $i = 1;
             while ($journalDao->anyPubIdExists($journal->getId(), 'publisher-id', $publicGalleyId . $suffix)) {
                 $suffix = '_' . $i++;
             }
             $galley->setStoredPubId('publisher-id', $publicGalleyId . $suffix);
         }
         // Insert new galley into the db
         $galleyDao->insertGalley($galley);
         $this->setGalley($galley);
     }
     return $this->getGalleyId();
 }
 function importIssues()
 {
     assert($this->xml->name == 'issues');
     $issueDAO =& DAORegistry::getDAO('IssueDAO');
     $issueFileDAO =& DAORegistry::getDAO('IssueFileDAO');
     $issueGalleyDAO =& DAORegistry::getDAO('IssueGalleyDAO');
     $sectionDAO =& DAORegistry::getDAO('SectionDAO');
     $issues = $issueDAO->getIssues($this->journal->getId());
     $publicFileManager =& new PublicFileManager();
     $this->nextElement();
     while ($this->xml->name == 'issue') {
         $issueXML = $this->getCurrentElementAsDom();
         $issue = new Issue();
         $issue->setJournalId($this->journal->getId());
         $issue->setVolume((int) $issueXML->volume);
         $issue->setNumber((string) $issueXML->number);
         $issue->setYear((int) $issueXML->year);
         $issue->setPublished((int) $issueXML->published);
         $issue->setCurrent((int) $issueXML->current);
         $issue->setDatePublished((string) $issueXML->datePublished);
         $issue->setDateNotified((string) $issueXML->dateNotified);
         $issue->setLastModified((string) $issueXML->lastModified);
         $issue->setAccessStatus((int) $issueXML->accessStatus);
         $issue->setOpenAccessDate((string) $issueXML->openAccessDate);
         $issue->setShowVolume((int) $issueXML->showVolume);
         $issue->setShowNumber((int) $issueXML->showNumber);
         $issue->setShowYear((int) $issueXML->showYear);
         $issue->setShowTitle((int) $issueXML->showTitle);
         $issue->setStyleFileName((string) $issueXML->styleFileName);
         $issue->setOriginalStyleFileName((string) $issueXML->originalStyleFileName);
         $oldIssueId = (int) $issueXML->oldId;
         $issueDAO->insertIssue($issue);
         //$issueDAO->insertCustomIssueOrder($this->journal->getId(), $issue->getId(), (int)$issueXML->customOrder);
         $this->idTranslationTable->register(INTERNAL_TRANSFER_OBJECT_ISSUE, $oldIssueId, $issue->getId());
         $this->restoreDataObjectSettings($issueDAO, $issueXML->settings, 'issue_settings', 'issue_id', $issue->getId());
         $issue =& $issueDAO->getIssueById($issue->getId());
         // Reload issue to get restored settings
         $covers = $issue->getFileName(null);
         if ($covers) {
             foreach ($covers as $locale => $oldCoverFileName) {
                 $sourceFile = $this->publicFolderPath . '/' . $oldCoverFileName;
                 $extension = $publicFileManager->getExtension($oldCoverFileName);
                 $destFile = 'cover_issue_' . $issue->getId() . "_{$locale}.{$extension}";
                 $publicFileManager->copyJournalFile($this->journal->getId(), $sourceFile, $destFile);
                 unlink($sourceFile);
                 $issue->setFileName($destFile, $locale);
                 $issueDAO->updateIssue($issue);
             }
         }
         if ($issue->getStyleFileName()) {
             $oldStyleFileName = $issue->getStyleFileName();
             $sourceFile = $this->publicFolderPath . '/' . $oldStyleFileName;
             $destFile = 'style_' . $issue->getId() . '.css';
             $publicFileManager->copyJournalFile($this->journal->getId(), $sourceFile, $destFile);
             unlink($sourceFile);
             $issue->setStyleFileName($destFile);
             $issueDAO->updateIssue($issue);
         }
         $issueFileManager = new IssueFileManager($issue->getId());
         foreach ($issueXML->issueFile as $issueFileXML) {
             $issueFile = new IssueFile();
             $issueFile->setIssueId($issue->getId());
             $issueFile->setFileName((string) $issueFileXML->fileName);
             $issueFile->setFileType((string) $issueFileXML->fileType);
             $issueFile->setFileSize((int) $issueFileXML->fileSize);
             $issueFile->setContentType((string) $issueFileXML->contentType);
             $issueFile->setOriginalFileName((string) $issueFileXML->originalFileName);
             $issueFile->setDateUploaded((string) $issueFileXML->dateUploaded);
             $issueFile->setDateModified((string) $issueFileXML->dateModified);
             $issueFileDAO->insertIssueFile($issueFile);
             $oldFileName = $issueFile->getFileName();
             $extension = $issueFileManager->parseFileExtension($oldFileName);
             $contentPath = $issueFileManager->contentTypeToPath($issueFile->getContentType());
             $contentAbbrev = $issueFileManager->contentTypeToAbbrev($issueFile->getContentType());
             $fileInTransferPackage = $this->journalFolderPath . "/issues/{$oldIssueId}/{$contentPath}/{$oldFileName}";
             $newFileName = $issue->getId() . '-' . $issueFile->getId() . '-' . $contentAbbrev . '.' . $extension;
             $newFilePath = "{$contentPath}/{$newFileName}";
             $issueFileManager->copyFile($fileInTransferPackage, $issueFileManager->getFilesDir() . $newFilePath);
             unlink($fileInTransferPackage);
             $issueFile->setFileName($newFileName);
             $issueFileDAO->updateIssueFile($issueFile);
             $this->idTranslationTable->register(INTERNAL_TRANSFER_OBJECT_ISSUE_FILE, (int) $issueFileXML->oldId, $issueFile->getId());
         }
         foreach ($issueXML->issueGalley as $issueGalleyXML) {
             $issueGalley = new issueGalley();
             $issueGalley->setIssueId($issue->getId());
             $issueGalley->setLocale((string) $issueGalleyXML->locale);
             $issueGalley->setFileId($this->idTranslationTable->resolve(INTERNAL_TRANSFER_OBJECT_ISSUE_FILE, (int) $issueGalleyXML->fileId));
             $issueGalley->setLabel((string) $issueGalleyXML->label);
             $issueGalley->setSequence((int) $issueGalleyXML->sequence);
             $issueGalleyDAO->insertGalley($issueGalley);
             $this->idTranslationTable->register(INTERNAL_TRANSFER_OBJECT_ISSUE_GALLEY, (int) $issueGalleyXML->oldId, $issueGalley->getId());
             $this->restoreDataObjectSettings($issueGalleyDAO, $issueGalleyXML->settings, 'issue_galley_settings', 'galley_id', $issueGalley->getId());
         }
         if (isset($issueXML->customSectionOrder)) {
             foreach ($issueXML->customSectionOrder->sectionOrder as $sectionOrderXML) {
                 try {
                     $sectionId = $this->idTranslationTable->resolve(INTERNAL_TRANSFER_OBJECT_SECTION, (int) $sectionOrderXML['sectionId']);
                     $seq = (int) $sectionOrderXML['seq'];
                     $sectionDAO->insertCustomSectionOrder($issue->getId(), $sectionId, $seq);
                 } catch (Exception $e) {
                 }
             }
         }
         $this->nextElement();
     }
 }
Beispiel #9
0
 /**
  * Downloads an issue galley file
  * @param $args array ($issueId, $galleyId)
  * @param $request Request
  */
 function download($args, $request)
 {
     if ($this->userCanViewGalley($request)) {
         $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
         $galley = $this->getGalley();
         if (!HookRegistry::call('IssueHandler::download', array(&$issue, &$galley))) {
             import('classes.file.IssueFileManager');
             $issueFileManager = new IssueFileManager($issue->getId());
             return $issueFileManager->downloadFile($galley->getFileId(), $request->getUserVar('inline') ? true : false);
         }
     }
 }
 /**
  * Handle a submission element
  * @param $node DOMElement
  * @return IssueGalley
  */
 function handleElement($node)
 {
     $deployment = $this->getDeployment();
     $context = $deployment->getContext();
     $issue = $deployment->getIssue();
     assert(is_a($issue, 'Issue'));
     // Create the data object
     $issueGalleyDao = DAORegistry::getDAO('IssueGalleyDAO');
     $issueGalley = $issueGalleyDao->newDataObject();
     $issueGalley->setIssueId($issue->getId());
     $locale = $node->getAttribute('locale');
     if (empty($locale)) {
         $locale = $context->getPrimaryLocale();
     }
     $issueGalley->setLocale($locale);
     $issueGalley->setSequence($issueGalleyDao->getNextGalleySequence($issue->getId()));
     // Handle metadata in subelements.
     for ($n = $node->firstChild; $n !== null; $n = $n->nextSibling) {
         if (is_a($n, 'DOMElement')) {
             switch ($n->tagName) {
                 case 'label':
                     $issueGalley->setLabel($n->textContent);
                     break;
                 case 'issue_file':
                     $issueFileDao = DAORegistry::getDAO('IssueFileDAO');
                     $issueFile = $issueFileDao->newDataObject();
                     $issueFile->setIssueId($issue->getId());
                     for ($o = $n->firstChild; $o !== null; $o = $o->nextSibling) {
                         if (is_a($o, 'DOMElement')) {
                             switch ($o->tagName) {
                                 case 'file_name':
                                     $issueFile->setServerFileName($o->textContent);
                                     break;
                                 case 'file_type':
                                     $issueFile->setFileType($o->textContent);
                                     break;
                                 case 'file_size':
                                     $issueFile->setFileSize($o->textContent);
                                     break;
                                 case 'content_type':
                                     $issueFile->setContentType((int) $o->textContent);
                                     break;
                                 case 'original_file_name':
                                     $issueFile->setOriginalFileName($o->textContent);
                                     break;
                                 case 'date_uploaded':
                                     $issueFile->setDateUploaded($o->textContent);
                                     break;
                                 case 'date_modified':
                                     $issueFile->setDateModified($o->textContent);
                                     break;
                                 case 'embed':
                                     import('classes.file.IssueFileManager');
                                     $issueFileManager = new IssueFileManager($issue->getId());
                                     $filePath = $issueFileManager->getFilesDir() . $issueFileManager->contentTypeToPath($issueFile->getContentType()) . '/' . $issueFile->getServerFileName();
                                     $issueFileManager->writeFile($filePath, base64_decode($o->textContent));
                                     break;
                             }
                         }
                     }
                     $issueFileId = $issueFileDao->insertObject($issueFile);
                     $issueGalley->setFileId($issueFileId);
                     break;
             }
         }
     }
     $issueGalleyDao->insertObject($issueGalley);
     return $issueGalley;
 }
 /**
  * Add the issue file to its DOM element.
  * @param $doc DOMDocument
  * @param $issueGalleyNode DOMElement
  * @param $issueGalley IssueGalley
  */
 function addFile($doc, $issueGalleyNode, $issueGalley)
 {
     $issueFileDao = DAORegistry::getDAO('IssueFileDAO');
     $issueFile = $issueFileDao->getById($issueGalley->getFileId());
     if ($issueFile) {
         $deployment = $this->getDeployment();
         $issueFileNode = $doc->createElementNS($deployment->getNamespace(), 'issue_file');
         $issueFileNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'file_name', $issueFile->getServerFileName()));
         $issueFileNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'file_type', $issueFile->getContentType()));
         $issueFileNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'file_size', $issueFile->getFileSize()));
         $issueFileNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'content_type', $issueFile->getFileType()));
         $issueFileNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'original_file_name', $issueFile->getOriginalFileName()));
         $issueFileNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'date_uploaded', strftime('%F', strtotime($issueFile->getDateUploaded()))));
         $issueFileNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'date_modified', strftime('%F', strtotime($issueFile->getDateModified()))));
         import('classes.file.IssueFileManager');
         $issueFileManager = new IssueFileManager($issueGalley->getIssueId());
         $filePath = $issueFileManager->getFilesDir() . '/' . $issueFileManager->contentTypeToPath($issueFile->getContentType()) . '/' . $issueFile->getServerFileName();
         $embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($filePath)));
         $embedNode->setAttribute('encoding', 'base64');
         $issueFileNode->appendChild($embedNode);
         $issueGalleyNode->appendChild($issueFileNode);
     }
 }
 /**
  * Show an issue galley file (either inline or download)
  * @param $issueId int
  * @param $galleyId int
  * @param $request Request
  * @param $inline boolean
  */
 function _showIssueGalley($request, $inline = false)
 {
     $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
     $galley = $this->getGalley();
     if (!HookRegistry::call('IssueHandler::viewFile', array(&$issue, &$galley))) {
         import('classes.file.IssueFileManager');
         $issueFileManager = new IssueFileManager($issue->getId());
         return $issueFileManager->downloadFile($galley->getFileId(), $inline);
     }
 }