/** * Create packages for any deposits that don't have any or have been updated */ function _processNeedPackaging(&$journal) { $depositDao =& DAORegistry::getDAO('DepositDAO'); $depositQueue =& $depositDao->getNeedPackaging($journal->getId()); $fileManager = new JournalFileManager($journal); $plnDir = $fileManager->filesDir . PLN_PLUGIN_ARCHIVE_FOLDER; // make sure the pln work directory exists // TOOD: use FileManager calls instead of PHP ones where possible if ($fileManager->fileExists($plnDir, 'dir') !== true) { $fileManager->mkdirtree($plnDir); } // loop though all of the deposits that need packaging while ($deposit =& $depositQueue->next()) { $depositPackage = new DepositPackage($deposit, $this); $depositPackage->packageDeposit(); unset($deposit); } }
function manage($verb, $args, &$message) { if (!parent::manage($verb, $args, $message)) { return false; } $journal =& Request::getJournal(); $templateMgr =& TemplateManager::getManager(); $templateMgr->register_function('plugin_url', array(&$this, 'smartyPluginUrl')); $this->import('XMLGalleySettingsForm'); $form = new XMLGalleySettingsForm($this, $journal->getId()); switch ($verb) { case 'test': // test external XSLT renderer $xsltRenderer = $this->getSetting($journal->getId(), 'XSLTrenderer'); if ($xsltRenderer == "external") { // get command for external XSLT tool $xsltCommand = $this->getSetting($journal->getId(), 'externalXSLT'); // get test XML/XSL files $xmlFile = dirname($_SERVER['SCRIPT_FILENAME']) . DIRECTORY_SEPARATOR . $this->getPluginPath() . '/transform/test.xml'; $xslFile = $this->getPluginPath() . '/transform/test.xsl'; // create a testing article galley object (to access the XSLT render method) $this->import('ArticleXMLGalley'); $xmlGalley = new ArticleXMLGalley($this->getName()); // transform the XML using whatever XSLT processor we have available $result = $xmlGalley->transformXSLT($xmlFile, $xslFile, $xsltCommand); // check the result if (trim(preg_replace("/\\s+/", " ", $result)) != "Open Journal Systems Success") { $form->addError('content', Locale::translate('plugins.generic.xmlGalley.settings.externalXSLTFailure')); } else { $templateMgr->assign('testSuccess', true); } } case 'settings': Locale::requireComponents(array(LOCALE_COMPONENT_APPLICATION_COMMON, LOCALE_COMPONENT_PKP_MANAGER)); // if we are updating XSLT settings or switching XSL sheets if (Request::getUserVar('save')) { $form->readInputData(); $form->initData(); if ($form->validate()) { $form->execute(); } $form->display(); // if we are uploading a custom XSL sheet } elseif (Request::getUserVar('uploadCustomXSL')) { $form->readInputData(); import('classes.file.JournalFileManager'); // if the a valid custom XSL is uploaded, process it $fileManager = new JournalFileManager($journal); if ($fileManager->uploadedFileExists('customXSL')) { // check type and extension -- should be text/xml and xsl, respectively $type = $fileManager->getUploadedFileType('customXSL'); $fileName = $fileManager->getUploadedFileName('customXSL'); $extension = strtolower($fileManager->getExtension($fileName)); if (($type == 'text/xml' || $type == 'text/xml' || $type == 'application/xml' || $type == 'application/xslt+xml') && $extension == 'xsl') { // if there is an existing XSL file, delete it from the journal files folder $existingFile = $this->getSetting($journal->getId(), 'customXSL'); if (!empty($existingFile) && $fileManager->fileExists($fileManager->filesDir . $existingFile)) { $fileManager->deleteFile($existingFile); } // upload the file into the journal files folder $fileManager->uploadFile('customXSL', $fileName); // update the plugin and form settings $this->updateSetting($journal->getId(), 'XSLstylesheet', 'custom'); $this->updateSetting($journal->getId(), 'customXSL', $fileName); } else { $form->addError('content', Locale::translate('plugins.generic.xmlGalley.settings.customXSLInvalid')); } } else { $form->addError('content', Locale::translate('plugins.generic.xmlGalley.settings.customXSLRequired')); } // re-populate the form values with the new settings $form->initData(); $form->display(); // if we are deleting an existing custom XSL sheet } elseif (Request::getUserVar('deleteCustomXSL')) { import('classes.file.JournalFileManager'); // if the a valid custom XSL is uploaded, process it $fileManager = new JournalFileManager($journal); // delete the file from the journal files folder $fileName = $this->getSetting($journal->getId(), 'customXSL'); if (!empty($fileName)) { $fileManager->deleteFile($fileName); } // update the plugin and form settings $this->updateSetting($journal->getId(), 'XSLstylesheet', 'NLM'); $this->updateSetting($journal->getId(), 'customXSL', ''); $form->initData(); $form->display(); } else { $form->initData(); $form->display(); } return true; default: // Unknown management verb assert(false); return false; } }
/** * Package a deposit for transfer to and retrieval by the PLN. */ function packageDeposit() { $depositDao =& DAORegistry::getDAO('DepositDAO'); $journalDao =& DAORegistry::getDAO('JournalDAO'); $fileManager = new JournalFileManager($journalDao->getById($this->_deposit->getJournalId())); $plnDir = $fileManager->filesDir . PLN_PLUGIN_ARCHIVE_FOLDER; // make sure the pln work directory exists if ($fileManager->fileExists($plnDir, 'dir') !== true) { $fileManager->mkdir($plnDir); } // make a location for our work and clear it out if it's there $depositDir = $plnDir . DIRECTORY_SEPARATOR . $this->_deposit->getUUID(); if ($fileManager->fileExists($depositDir, 'dir')) { $fileManager->rmtree($depositDir); } $fileManager->mkdir($depositDir); if (!$fileManager->fileExists($this->generatePackage())) { $this->_deposit->setLocalFailureStatus(); $depositDao->updateDeposit($this->_deposit); return; } if (!$fileManager->fileExists($this->generateAtomDocument())) { $this->_deposit->setLocalFailureStatus(); $depositDao->updateDeposit($this->_deposit); return; } // update the deposit's status $this->_deposit->setPackagedStatus(); $depositDao->updateDeposit($this->_deposit); }