Skip to content

Commit

Permalink
pkp/pkp-lib#10388 Thank Reviewer action crashes on main
Browse files Browse the repository at this point in the history
  • Loading branch information
ewhanson committed Sep 12, 2024
1 parent fb003ab commit 7eed764
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion classes/orcid/actions/SendReviewToOrcid.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class SendReviewToOrcid extends PKPSendReviewToOrcid
/** @inheritDoc */
public function execute(): void
{
dispatch(new DepositOrcidReview($this->submission, $this->context, $this->reviewAssignment));
dispatch(new DepositOrcidReview($this->reviewAssignment->getId()));
}
}
28 changes: 15 additions & 13 deletions jobs/orcid/DepositOrcidReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,57 @@
use APP\core\Application;
use APP\facades\Repo;
use APP\orcid\OrcidReview;
use APP\submission\Submission;
use Carbon\Carbon;
use GuzzleHttp\Exception\ClientException;
use PKP\config\Config;
use PKP\context\Context;
use PKP\jobs\BaseJob;
use PKP\orcid\OrcidManager;
use PKP\submission\reviewAssignment\ReviewAssignment;

class DepositOrcidReview extends BaseJob
{
public function __construct(
private Submission $submission,
private Context $context,
private ReviewAssignment $reviewAssignment,
private int $reviewAssignmentId
) {
parent::__construct();
}

/**
* @inheritDoc
*/
public function handle()
public function handle(): void
{
$reviewAssignment = Repo::reviewAssignment()->get($this->reviewAssignmentId);
if ($reviewAssignment === null) {
$this->fail('Review assignment does not exist.');
}

$submission = Repo::submission()->get($reviewAssignment->getSubmissionId());
$context = Application::getContextDAO()->getById($submission->getData('contextId'));

// If the application is set to sandbox mode, it will not reach out to external services
if (Config::getVar('general', 'sandbox', false)) {
$this->fail('Application is set to sandbox mode and will not interact with the ORCID service');
return;
}

if (!OrcidManager::isMemberApiEnabled($this->context)) {
if (!OrcidManager::isMemberApiEnabled($context)) {
return;
}

if (!OrcidManager::getCity($this->context) || !OrcidManager::getCountry($this->context)) {
if (!OrcidManager::getCity($context) || !OrcidManager::getCountry($context)) {
return;
}

$reviewer = Repo::user()->get($this->reviewAssignment->getData('reviewerId'));
$reviewer = Repo::user()->get($reviewAssignment->getData('reviewerId'));

if ($reviewer->getOrcid() && $reviewer->getData('orcidAccessToken')) {
$orcidAccessExpiresOn = Carbon::parse($reviewer->getData('orcidAccessExpiresOn'));
if ($orcidAccessExpiresOn->isFuture()) {
# Extract only the ORCID from the stored ORCID uri
$orcid = basename(parse_url($reviewer->getOrcid(), PHP_URL_PATH));

$orcidReview = new OrcidReview($this->submission, $this->reviewAssignment, $this->context);
$orcidReview = new OrcidReview($submission, $reviewAssignment, $context);

$uri = OrcidManager::getApiPath($this->context) . OrcidManager::ORCID_API_VERSION_URL . $orcid . '/' . OrcidManager::ORCID_REVIEW_URL;
$uri = OrcidManager::getApiPath($context) . OrcidManager::ORCID_API_VERSION_URL . $orcid . '/' . OrcidManager::ORCID_REVIEW_URL;
$method = 'POST';
if ($putCode = $reviewer->getData('orcidReviewPutCode')) {
$uri .= '/' . $putCode;
Expand Down

0 comments on commit 7eed764

Please sign in to comment.