Skip to content

Commit

Permalink
import Native xml, restrict review stages
Browse files Browse the repository at this point in the history
  • Loading branch information
withanage committed Dec 12, 2024
1 parent 0e68ad4 commit 882c6ca
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
52 changes: 49 additions & 3 deletions classes/plugins/importexport/PKPImportExportDeployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use APP\facades\Repo;
use APP\publication\Publication;
use APP\submission\Submission;
use DOMDocument;
use DOMXPath;
use Error;
use Exception;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -82,6 +84,9 @@ class PKPImportExportDeployment
/** @var array A list of exported root elements to display to the user after the export is complete */
private $_exportRootEntities;

/** @var array list of custom errors */
private $customErrors = [];

/**
* Constructor
*
Expand All @@ -103,6 +108,16 @@ public function __construct($context, $user = null)
//
// Deployment items for subclasses to override
//

/**
* Get Custom errors
* @return array
*/
public function getCustomErrors(): array
{
return $this->customErrors;
}

/**
* Get the submission node name
*
Expand Down Expand Up @@ -562,7 +577,11 @@ public function import($rootFilter, $importXml)

$result = $currentFilter->execute($importXml);

$dbConnection->commit();
if ($this->isUnsupportedSubmissionStage($importXml)) {
$this->processFailed = true;
} else {
$dbConnection->commit();
}

$this->processResult = $result;
} catch (Error | Exception $e) {
Expand All @@ -573,6 +592,7 @@ public function import($rootFilter, $importXml)
} finally {
$this->xmlValidationErrors = array_filter(libxml_get_errors(), fn (LibXMLError $error) => in_array($error->level, [LIBXML_ERR_ERROR, LIBXML_ERR_FATAL]));
libxml_clear_errors();

}
}

Expand Down Expand Up @@ -677,6 +697,7 @@ public function getWarningsAndErrors()
{
$problems = [];
$objectTypes = $this->getObjectTypes();
$genericError = $objectTypes[PKPApplication::ASSOC_TYPE_NONE];
foreach ($objectTypes as $assocType => $name) {
$foundWarnings = $this->getProcessedObjectsWarnings($assocType);
if (!empty($foundWarnings)) {
Expand All @@ -689,10 +710,12 @@ public function getWarningsAndErrors()
}
}
if (count($validationErrors = $this->getXMLValidationErrors())) {
$validationErrors = array_map(fn (LibXMLError $e) => "Line {$e->line} Column {$e->column}: {$e->message}", $validationErrors);
$genericError = $objectTypes[PKPApplication::ASSOC_TYPE_NONE];
$validationErrors = array_map(fn(LibXMLError $e) => "Line {$e->line} Column {$e->column}: {$e->message}", $validationErrors);
$problems['errors'][$genericError][] = [$validationErrors];
}
if (count($customErrors = $this->getCustomErrors())) {
$problems['errors'][$genericError][] = [$customErrors];
}

return $problems;
}
Expand Down Expand Up @@ -729,6 +752,29 @@ public function isProcessFailed()

return false;
}

/**
* @param DOMDocument $DOMDocument
* @return bool Returns true, if the submission stage is not supported
*/
public function isUnsupportedSubmissionStage(DOMDocument $DOMDocument): bool
{
$unsupportedStage = false;
$xpath = new DOMXPath($DOMDocument);
$xpath->registerNamespace('ns', 'http://pkp.sfu.ca');

foreach (['article', 'monograph', 'preprint'] as $submissionType) {
$reviewStateQuery = '//ns:' . $submissionType . '[@stage="externalReview" or @stage="internalReview"]';
$reviewStages = $xpath->query($reviewStateQuery);
if ($reviewStages->length > 0) {
$unsupportedStage = true;
foreach ($reviewStages as $reviewStage) {
$this->customErrors [] = __("plugins.importexport.common.error.unsupportedStage");
}
}
}
return $unsupportedStage;
}
}

if (!PKP_STRICT_MODE) {
Expand Down
3 changes: 3 additions & 0 deletions locale/en/manager.po
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,9 @@ msgstr ""
msgid "plugins.importexport.common.error.unknownUploader"
msgstr "Unknown uploader {$param}"

msgid "plugins.importexport.common.error.unsupportedStage"
msgstr "Reviewer stage XMLs are not supported."

msgid "plugins.importexport.common.error.temporaryFileFailed"
msgstr "Temporary file {$dest} could not be created from {$source}"

Expand Down

0 comments on commit 882c6ca

Please sign in to comment.