Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import Native xml, restrict review stages #10697

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions classes/plugins/importexport/PKPImportExportDeployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
use LibXMLError;
use PKP\context\Context;
use PKP\core\PKPApplication;
use PKP\db\DAORegistry;
use PKP\submission\reviewRound\ReviewRound;
use PKP\user\User;
use DOMDocument;
use DOMXPath;

class PKPImportExportDeployment
{
Expand Down Expand Up @@ -286,6 +290,7 @@ public function getProcessedObjectsErrors($assocType)
}
return null;
}

/**
* Get the processed objects errors.
*
Expand Down Expand Up @@ -561,17 +566,17 @@ public function import($rootFilter, $importXml)
libxml_use_internal_errors(true);

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

$dbConnection->commit();

$this->processResult = $result;
} catch (Error | Exception $e) {

$this->addReviewStage($importXml);
} catch (Error|Exception $e) {
$this->addError(PKPApplication::ASSOC_TYPE_NONE, 0, $e->getMessage());
$dbConnection->rollBack();

$this->processFailed = true;
} finally {
$this->xmlValidationErrors = array_filter(libxml_get_errors(), fn (LibXMLError $error) => in_array($error->level, [LIBXML_ERR_ERROR, LIBXML_ERR_FATAL]));
$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 @@ -609,7 +614,7 @@ public function export($rootFilter, $exportObjects, $opts = [])
}

$this->processResult = $result;
} catch (Error | Exception $e) {
} catch (Error|Exception $e) {
$this->addError(PKPApplication::ASSOC_TYPE_NONE, 0, $e->getMessage());

$this->processFailed = true;
Expand Down Expand Up @@ -647,12 +652,12 @@ protected function getObjectTypes()
}

/**
* Get object type string.
*
* @param mixed $assocType int or null (optional)
*
* @return mixed string or array
*/
* Get object type string.
*
* @param mixed $assocType int or null (optional)
*
* @return mixed string or array
*/
public function getObjectTypeString($assocType = null)
{
$objectTypes = $this->getObjectTypes();
Expand Down Expand Up @@ -689,7 +694,7 @@ public function getWarningsAndErrors()
}
}
if (count($validationErrors = $this->getXMLValidationErrors())) {
$validationErrors = array_map(fn (LibXMLError $e) => "Line {$e->line} Column {$e->column}: {$e->message}", $validationErrors);
$validationErrors = array_map(fn(LibXMLError $e) => "Line {$e->line} Column {$e->column}: {$e->message}", $validationErrors);
$genericError = $objectTypes[PKPApplication::ASSOC_TYPE_NONE];
$problems['errors'][$genericError][] = [$validationErrors];
}
Expand Down Expand Up @@ -729,6 +734,35 @@ public function isProcessFailed()

return false;
}


/**
* Add reviewer stage from an import XML
* @param DOMDocument $document
*/
public function addReviewStage(DOMDocument $document): void
{
if ($this->processResult) {
$xpath = new DOMXPath($document);
$xpath->registerNamespace('ns', 'http://pkp.sfu.ca');

foreach (['article', 'monograph', 'preprint'] as $submissionType) {
$reviewStateQuery = '//ns:' . $submissionType . '[@stage="externalReview" or @stage="internalReview"]';
$isReviewStageSubmission = $xpath->query($reviewStateQuery);

if ($isReviewStageSubmission->length > 0) {
$reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO');
$submission = $this->processResult[0];
$reviewRound = $reviewRoundDao->build(
$submission->getId(),
$submission->getData('stageId'),
ReviewRound::REVIEW_ROUND_STATUS_PENDING_REVIEWERS,
);
}
}
}

}
}

if (!PKP_STRICT_MODE) {
Expand Down