Skip to content

Commit

Permalink
Add reviewer stage for an export XML
Browse files Browse the repository at this point in the history
  • Loading branch information
withanage committed Dec 26, 2024
1 parent 4788455 commit a06dfdd
Showing 1 changed file with 46 additions and 12 deletions.
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

0 comments on commit a06dfdd

Please sign in to comment.