Inheritance: extends ImportExportPlugin
Exemplo n.º 1
0
 /**
  * @copydoc ImportExportPlugin::display()
  */
 function display($args, $request)
 {
     $context = $request->getContext();
     switch (current($args)) {
         case 'exportRepresentations':
             $selectedRepresentations = (array) $request->getUserVar('selectedRepresentations');
             if (!empty($selectedRepresentations)) {
                 $objects = $this->_getArticleGalleys($selectedRepresentations, $context);
                 $filter = 'galley=>medra-xml';
                 $tab = (string) $request->getUserVar('tab');
                 $objectsFileNamePart = 'galleys';
             }
             // Execute export action
             $this->executeExportAction($request, $objects, $filter, $tab, $objectsFileNamePart);
         default:
             parent::display($args, $request);
     }
 }
Exemplo n.º 2
0
 /**
  * @copydoc DOIPubIdExportPlugin::executeExportAction()
  */
 function executeExportAction($request, $objects, $filter, $tab, $objectsFileNamePart)
 {
     $context = $request->getContext();
     $path = array('plugin', $this->getName());
     if ($request->getUserVar(CROSSREF_EXPORT_ACTION_CHECKSTATUS)) {
         $this->checkStatus($objects, $context);
         // redirect back to the right tab
         $request->redirect(null, null, null, $path, null, $tab);
     } else {
         parent::executeExportAction($request, $objects, $filter, $tab, $objectsFileNamePart);
     }
 }
Exemplo n.º 3
0
 /**
  * @copydoc ImportExportPlugin::executeExportAction()
  */
 function executeExportAction($request, $objects, $filter, $tab, $objectsFileNamePart)
 {
     $context = $request->getContext();
     $path = array('plugin', $this->getName());
     // Export
     if ($request->getUserVar(DOI_EXPORT_ACTION_EXPORT)) {
         $result = $this->_checkForTar();
         if ($result === true) {
             $exportedFiles = array();
             foreach ($objects as $object) {
                 // Get the XML
                 $exportXml = $this->exportXML($object, $filter, $context);
                 // Write the XML to a file.
                 // export file name example: datacite/20160723-160036-articles-1-1.xml
                 $objectFileNamePart = $objectsFileNamePart . '-' . $object->getId();
                 $exportFileName = $this->getExportFileName($objectFileNamePart, $context);
                 file_put_contents($exportFileName, $exportXml);
                 $exportedFiles[] = $exportFileName;
             }
             // If we have more than one export file we package the files
             // up as a single tar before going on.
             assert(count($exportedFiles) >= 1);
             if (count($exportedFiles) > 1) {
                 // tar file name: e.g. datacite/20160723-160036-articles-1.tar.gz
                 $finalExportFileName = $this->getExportPath() . date('Ymd-His') . '-' . $objectsFileNamePart . '-' . $context->getId() . '.tar.gz';
                 $finalExportFileType = DATACITE_EXPORT_FILE_TAR;
                 $this->_tarFiles($this->getExportPath(), $finalExportFileName, $exportedFiles);
                 // remove files
                 foreach ($exportedFiles as $exportedFile) {
                     $this->cleanTmpfile($exportedFile);
                 }
             } else {
                 $finalExportFileName = array_shift($exportedFiles);
                 $finalExportFileType = DATACITE_EXPORT_FILE_XML;
             }
             header('Content-Type: application/' . ($finalExportFileType == DATACITE_EXPORT_FILE_TAR ? 'x-gtar' : 'xml'));
             header('Cache-Control: private');
             header('Content-Disposition: attachment; filename="' . basename($finalExportFileName) . '"');
             readfile($finalExportFileName);
         } else {
             if (is_array($result)) {
                 foreach ($result as $error) {
                     assert(is_array($error) && count($error) >= 1);
                     $this->_sendNotification($request->getUser(), $error[0], NOTIFICATION_TYPE_ERROR, isset($error[1]) ? $error[1] : null);
                 }
             }
             // redirect back to the right tab
             $request->redirect(null, null, null, $path, null, $tab);
         }
     } elseif ($request->getUserVar(DOI_EXPORT_ACTION_DEPOSIT)) {
         $resultErrors = array();
         foreach ($objects as $object) {
             // Get the XML
             $exportXml = $this->exportXML($object, $filter, $context);
             // Write the XML to a file.
             // export file name example: datacite/20160723-160036-articles-1-1.xml
             $objectFileNamePart = $objectsFileNamePart . '-' . $object->getId();
             $exportFileName = $this->getExportFileName($objectFileNamePart, $context);
             file_put_contents($exportFileName, $exportXml);
             // Deposit the XML file.
             $result = $this->depositXML($object, $context, $exportFileName);
             if (is_array($result)) {
                 $resultErrors[] = $result;
             }
             // Remove all temporary files.
             $this->cleanTmpfile($exportFileName);
         }
         // send notifications
         if (empty($resultErrors)) {
             $this->_sendNotification($request->getUser(), $this->getDepositSuccessNotificationMessageKey(), NOTIFICATION_TYPE_SUCCESS);
         } else {
             foreach ($resultErrors as $error) {
                 assert(is_array($error) && count($error) >= 1);
                 $this->_sendNotification($request->getUser(), $error[0], NOTIFICATION_TYPE_ERROR, isset($error[1]) ? $error[1] : null);
             }
         }
         // redirect back to the right tab
         $request->redirect(null, null, null, $path, null, $tab);
     } else {
         return parent::executeExportAction($request, $objects, $filter, $tab, $objectsFileNamePart);
     }
 }
Exemplo n.º 4
0
 /**
  * Constructor
  */
 function __construct()
 {
     parent::__construct();
 }
Exemplo n.º 5
0
 /**
  * @copydoc PubObjectsExportPlugin::executeExportAction()
  */
 function executeExportAction($request, $objects, $filter, $tab, $objectsFileNamePart)
 {
     $context = $request->getContext();
     $path = array('plugin', $this->getName());
     import('lib.pkp.classes.file.FileManager');
     $fileManager = new FileManager();
     // Export
     if ($request->getUserVar(EXPORT_ACTION_EXPORT)) {
         $result = $this->_checkForTar();
         if ($result === true) {
             $exportedFiles = array();
             foreach ($objects as $object) {
                 // Get the XML
                 $exportXml = $this->exportXML($object, $filter, $context);
                 // Write the XML to a file.
                 // export file name example: datacite-20160723-160036-articles-1-1.xml
                 $objectFileNamePart = $objectsFileNamePart . '-' . $object->getId();
                 $exportFileName = $this->getExportFileName($this->getExportPath(), $objectFileNamePart, $context, '.xml');
                 $fileManager->writeFile($exportFileName, $exportXml);
                 $exportedFiles[] = $exportFileName;
             }
             // If we have more than one export file we package the files
             // up as a single tar before going on.
             assert(count($exportedFiles) >= 1);
             if (count($exportedFiles) > 1) {
                 // tar file name: e.g. datacite-20160723-160036-articles-1.tar.gz
                 $finalExportFileName = $this->getExportFileName($this->getExportPath(), $objectFileNamePart, $context, '.tar.gz');
                 $this->_tarFiles($this->getExportPath(), $finalExportFileName, $exportedFiles);
                 // remove files
                 foreach ($exportedFiles as $exportedFile) {
                     $fileManager->deleteFile($exportedFile);
                 }
             } else {
                 $finalExportFileName = array_shift($exportedFiles);
             }
             $fileManager->downloadFile($finalExportFileName);
             $fileManager->deleteFile($finalExportFileName);
         } else {
             if (is_array($result)) {
                 foreach ($result as $error) {
                     assert(is_array($error) && count($error) >= 1);
                     $this->_sendNotification($request->getUser(), $error[0], NOTIFICATION_TYPE_ERROR, isset($error[1]) ? $error[1] : null);
                 }
             }
             // redirect back to the right tab
             $request->redirect(null, null, null, $path, null, $tab);
         }
     } elseif ($request->getUserVar(EXPORT_ACTION_DEPOSIT)) {
         $resultErrors = array();
         foreach ($objects as $object) {
             // Get the XML
             $exportXml = $this->exportXML($object, $filter, $context);
             // Write the XML to a file.
             // export file name example: datacite-20160723-160036-articles-1-1.xml
             $objectFileNamePart = $objectsFileNamePart . '-' . $object->getId();
             $exportFileName = $this->getExportFileName($this->getExportPath(), $objectFileNamePart, $context, '.xml');
             $fileManager->writeFile($exportFileName, $exportXml);
             // Deposit the XML file.
             $result = $this->depositXML($object, $context, $exportFileName);
             if (is_array($result)) {
                 $resultErrors[] = $result;
             }
             // Remove all temporary files.
             $fileManager->deleteFile($exportFileName);
         }
         // send notifications
         if (empty($resultErrors)) {
             $this->_sendNotification($request->getUser(), $this->getDepositSuccessNotificationMessageKey(), NOTIFICATION_TYPE_SUCCESS);
         } else {
             foreach ($resultErrors as $error) {
                 foreach ($errors as $error) {
                     assert(is_array($error) && count($error) >= 1);
                     $this->_sendNotification($request->getUser(), $error[0], NOTIFICATION_TYPE_ERROR, isset($error[1]) ? $error[1] : null);
                 }
             }
         }
         // redirect back to the right tab
         $request->redirect(null, null, null, $path, null, $tab);
     } else {
         return parent::executeExportAction($request, $objects, $filter, $tab, $objectsFileNamePart);
     }
 }