Skip to content

Commit

Permalink
fix pubIds not exported via cli/cron
Browse files Browse the repository at this point in the history
  • Loading branch information
ronste committed Aug 20, 2021
1 parent fd8089a commit d8fbf6a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 31 deletions.
8 changes: 2 additions & 6 deletions DNBExportPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ function depositXML($object, $context, $filename) {
return $errors;
}

$fh = Services::get('file')->fs->readStream($filename);
if (!$fh) {
if (!file_exists($filename)) {
$param = __('plugins.importexport.dnb.deposit.error.fileUploadFailed.FileNotFound.param', array('package' => basename($filename), 'articleId' => $object->getFile()->getData('submissionId')));
$errors[] = array('plugins.importexport.dnb.deposit.error.fileUploadFailed', $param);
return $errors;
Expand Down Expand Up @@ -212,7 +211,7 @@ function depositXML($object, $context, $filename) {
if ($curlError) {
// error occured
$param = __('plugins.importexport.dnb.deposit.error.fileUploadFailed.param', array('package' => basename($filename), 'articleId' => $object->getFile()->getData('submissionId'), 'error' => $curlError));
$errors = array('plugins.importexport.dnb.deposit.error.fileUploadFailed', $param);
$errors[] = array('plugins.importexport.dnb.deposit.error.fileUploadFailed', $param);
}
curl_close($curlCh);
fclose($fh);
Expand Down Expand Up @@ -337,9 +336,6 @@ function executeExportAction($request, $submissions, $filter, $tab, $submissions
}
// Remove the generated directories
$fileManager->rmtree($journalExportPath);
// redirect back to the right tab
// TODO @RS this causes an error in the log and doesn't change UI tab
//$request->redirect(null, null, null, $path, null, $tab);
} elseif ($request->getUserVar(EXPORT_ACTION_DEPOSIT)) {
if (!empty($errors)) {
// If there were some deposit errors, display them to the user
Expand Down
3 changes: 3 additions & 0 deletions DNBInfoSender.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DNBInfoSender extends ScheduledTask {
function __construct($args) {
PluginRegistry::loadCategory('importexport');
$plugin = PluginRegistry::getPlugin('importexport', 'DNBExportPlugin'); /* @var $plugin DNBExportPlugin */

$this->_plugin = $plugin;

if (is_a($plugin, 'DNBExportPlugin')) {
Expand Down Expand Up @@ -69,6 +70,8 @@ function executeActions() {
$journals = $this->_getJournals();
$errors = array();
foreach ($journals as $journal) {
// load pubIds for this journal (they are currently not loaded in the base class)
PluginRegistry::loadCategory('pubIds', true, $journal->getId());
// Get not deposited articles
$notDepositedArticles = $plugin->getUnregisteredArticles($journal);
if (!empty($notDepositedArticles)) {
Expand Down
19 changes: 11 additions & 8 deletions README → README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
=============================================================
=== OJS DNB Export Plugin
=== Version: 1.4
=== Author: Bozana Bokan, Ronald Steffen
=== Last update: January 29, 2021
=============================================================

****
OJS DNB Export Plugin
Version: 1.4.1
Author: Bozana Bokan, Ronald Steffen
Last update: August 16, 2021
***
About
-----
This plugin provides the export of article metadata and full texts (in PDF and EPUB format) for their transfer to the German National Library (DNB)
Expand All @@ -28,7 +27,11 @@ For the depositing from within OJS, additionally CURL library is needed.
Installation
------------
Installalion via OJS GUI:
- download dnb-[version].tar.gz from https://github.com/ojsde/dnb/releases
- download dnb-[version].tar.gz from https://github.com/ojsde/dnb/releases. Please alwasy use the latest revision number (.x) of the plugin version corrsponding to your OJS version
| OJS version | plugin version |
| ----------- | ----------------- |
| 3.2 | 1.4.x |
| 3.3 | not yet published |
- install plugin in OJS (Settings -> Website -> plugins -> „Upload a New Plugin“ -> upload dnb-[version].tar.gz)

Installation via command line without Git:
Expand Down
11 changes: 8 additions & 3 deletions README_DE → README_DE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
=============================================================
=== OJS DNB-Export-Plug-In
=== Version: 1.4
=== Version: 1.4.1
=== Autor: Bozana Bokan, Ronald Steffen
=== Letzte Änderung: 29. Januar 2021
=== Letzte Änderung: 16. August 2021
=============================================================

Über
Expand Down Expand Up @@ -32,7 +32,12 @@ Installation über die OJS-Benutzeroberfläche:
- Installation des Plugins im Managementbereich von OJS (Einstellungen -> Website -> Plugins -> „Ein neues Plugin hochladen“ -> dnb-[Version].tar.gz hochladen)

Installation über die Kommandozeile ohne Git:
- Download des Archivs in der gewünschten Version von https://github.com/ojsde/dnb
- Download des Archivs in der gewünschten Version von https://github.com/ojsde/dnb.
Bitte immer die neuste Revisionsnummer (.x) des Plugins für die installierten OJS Version benutzen:
| OJS version | plugin version |
| ----------- | ----------------- |
| 3.2 | 1.4.x |
| 3.3 | not yet published |
- Entpacken des Plugins in das Verzeichnis plugins/importexport
- ggf. Umbenennen des Hauptverzeichnisses in "dnb"
- Aktualisierung der Datenbank (es empfiehlt sich, zuerst ein Backup der Datenbank zu erstellen),
Expand Down
58 changes: 46 additions & 12 deletions tests/functional/FunctionalDNBExportFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# run with 'sh plugins/importexport/dnb/tests/runTests.sh -d' from ojs folder
# This is not an automatic test. A native xml export fiel with the appropriate name and submission ID in your systems has to be placed in the tests folder.
# ATTENTION: Testing the export of pubIds is currently not possible. pubIds plugin category cannot be loaded.

import('lib.pkp.tests.PKPTestCase');
import('classes.issue.Issue');
Expand All @@ -10,9 +11,9 @@
import('plugins.importexport.dnb.filter.DNBXmlFilter');
import('plugins.importexport.dnb.DNBExportPlugin');
import('plugins.importexport.dnb.DNBExportDeployment');
import('plugins.importexport.dnb.DNBInfoSender');
import('lib.pkp.classes.filter.FilterGroup');

# TODO @RS fix registered and unregistered pubIds not loaded into test environment, unregistered pubIds are also not loaded via CLI-ScheduledTasks
import('lib.pkp.classes.plugins.LazyLoadPlugin');

class FunctionalDNBExportFilterTest extends PKPTestCase {

Expand All @@ -25,11 +26,47 @@ class FunctionalDNBExportFilterTest extends PKPTestCase {
# Alternatively you can import an existing xml file from the tests folder and replace correct submission ID assigned in your system in the file name of the existing xml file
public function testXMLExport() {

$contextId = "1"; // We use the first journal by default
// Initialize the request object with a page router
$application = Application::get();
$request = $application->getRequest();

// FIXME: Write and use a CLIRouter here (see classdoc)
import('classes.core.PageRouter');
$router = new PageRouter();
$router->setApplication($application);
$request->setRouter($router);

Registry::set('request', $request);
$router->_contextList = $application->getContextList();
$router->_contextPaths = ['dnb32'];

self::assertTrue($request->getContext() != null);

$contextDao = Application::getContextDAO();
$context =$contextDao->getById($contextId);
$journalFactory = $contextDao->getAll(true);

$journals = array();
while($journal = $journalFactory->next()) {
$contextId = $journal->getId();
// check required plugin settings
// if (!$plugin->getSetting($journalId, 'username') ||
// !$plugin->getSetting($journalId, 'password') ||
// !$plugin->getSetting($journalId, 'folderId') ||
// !$plugin->getSetting($journalId, 'automaticDeposit') ||
// !$plugin->checkPluginSettings($journal)) continue;

$journals[] = $journal;
unset($journal);
}

// load pubIds for this journal (they are currently not loaded via ScheduledTasks)
# TODO @RS fix pubIds not loaded into test environment -> mock request object doesn't have a user
// PluginRegistry::loadCategory('pubIds', true, $contextId); // this currently fails due to moch request object being insufficient -> a mock user would be required
$test = Services::get('publication')->get(11);

$test = Services::get('context')->getMany(['urlPath' => 'dnb32'])->current();

// find publications to test
$publications = Services::get('publication')->getMany([ 'contextId' => $contextId ]);
$testPublications = [];
foreach ($publications as $publication) {
Expand All @@ -42,6 +79,7 @@ public function testXMLExport() {
}
}

// run test for each publication
foreach ($testPublications as $publication) {
$submissionId = $publication->getData('submissionId');
$this->exportXML("plugins/importexport/dnb/tests/FunctionalExportFilterTestSubmission".$submissionId.".xml", $publication);
Expand All @@ -53,11 +91,8 @@ public function testXMLExport() {
# @param string $galleyId current galley ID (if imported might not be the same as is given in the xml file)
private function exportXML($filename, $publication) {

$context = Application::get()->getRequest()->getContext();
$submissionId = $publication->getData('submissionId');
$contextId = "1"; // We use the first journal by default

$contextDao = Application::getContextDAO();
$context =$contextDao->getById($contextId);

// define the submission metadata you expect in the exported file
$exportFile = new DOMDocument();
Expand Down Expand Up @@ -92,9 +127,6 @@ private function exportXML($filename, $publication) {
$submission = $submissionDao->getById($submissionId);
self::assertTrue($submission->getId() == $submissionId);

//TODO @RS FIX pubId not exported because they are not loaded from publication_settings table !!! -> Github Issue
$test = Services::get('publication')->get(11);

$xmlFilter = new DNBXmlFilter(new FilterGroup("galley=>dnb-xml"));
$xmlFilter->setDeployment(new DNBExportDeployment($context, new DNBExportPlugin()));

Expand Down Expand Up @@ -125,7 +157,9 @@ private function exportXML($filename, $publication) {
self::assertTrue($value == $author, "DOI/URN was: ".print_r($value, true)."\nValue should have been: ".$author);
}
} else {
self::assertTrue($entries->length == count($pubIds), "Number of pubIds was: ".$entries->length."\nValue should have been: ".count($pubIds));
// this test currently fails because pubIds cannot be loaded from the mock environment
// TODO @RS fix pubIds not loaded into test environment
// self::assertTrue($entries->length == count($pubIds), "Number of pubIds was: ".$entries->length."\nValue should have been: ".count($pubIds));
}

// language
Expand Down
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<version>
<application>dnb</application>
<type>plugins.importexport</type>
<release>1.4</release>
<date>2021-01-29</date>
<release>1.4.1</release>
<date>2021-08-16</date>
</version>

0 comments on commit d8fbf6a

Please sign in to comment.