Skip to content

Commit

Permalink
pkp#10127 WIP add DepositOrcidSubmissionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ewhanson committed Jul 24, 2024
1 parent c75a8af commit 66a7b5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions classes/orcid/OrcidManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ public static function removeOrcidAccessToken(Author $author, bool $updateAuthor
/**
* Write out log message at the INFO level.
*/
public static function logInfo(string $message): void
public static function logInfo(string $message, ?Context $context = null): void
{
if (self::getLogLevel() !== self::LOG_LEVEL_INFO) {
if (self::getLogLevel($context) !== self::LOG_LEVEL_INFO) {
return;
}
self::writeLog($message, self::LOG_LEVEL_INFO);
Expand All @@ -348,9 +348,9 @@ public static function logInfo(string $message): void
/**
* Write out log message at the ERROR level.
*/
public static function logError(string $message): void
public static function logError(string $message, ?Context $context = null): void
{
if (self::getLogLevel() !== self::LOG_LEVEL_ERROR) {
if (self::getLogLevel($context) !== self::LOG_LEVEL_ERROR) {
return;
}
self::writeLog($message, self::LOG_LEVEL_ERROR);
Expand Down
24 changes: 12 additions & 12 deletions jobs/orcid/DepositOrcidSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function handle()
'Authorization' => 'Bearer ' . $this->author->getData('orcidAccessToken')
];

OrcidManager::logInfo("{$method} {$uri}");
OrcidManager::logInfo('Header: ' . var_export($headers, true));
OrcidManager::logInfo("{$method} {$uri}", $this->context);
OrcidManager::logInfo('Header: ' . var_export($headers, true), $this->context);

$httpClient = Application::get()->getHttpClient();
try {
Expand All @@ -81,53 +81,53 @@ public function handle()
);
} catch (ClientException $exception) {
$reason = $exception->getResponse()->getBody();
OrcidManager::logError("Publication fail: {$reason}");
OrcidManager::logError("Publication fail: {$reason}", $this->context);

$this->fail($exception);
}
$httpStatus = $response->getStatusCode();
OrcidManager::logInfo("Response status: {$httpStatus}");
OrcidManager::logInfo("Response status: {$httpStatus}", $this->context);
$responseHeaders = $response->getHeaders();

switch ($httpStatus) {
case 200:
// Work updated
OrcidManager::logInfo("Work updated in profile, putCode: {$putCode}");
OrcidManager::logInfo("Work updated in profile, putCode: {$putCode}", $this->context);
break;
case 201:
$location = $responseHeaders['Location'][0];
// Extract the ORCID work put code for updates/deletion.
$putCode = intval(basename(parse_url($location, PHP_URL_PATH)));
OrcidManager::logInfo("Work added to profile, putCode: {$putCode}");
OrcidManager::logInfo("Work added to profile, putCode: {$putCode}", $this->context);
$this->author->setData('orcidWorkPutCode', $putCode);
Repo::author()->dao->update($this->author);
break;
case 401:
// invalid access token, token was revoked
$error = json_decode($response->getBody(), true);
if ($error['error'] === 'invalid_token') {
OrcidManager::logError($error['error_description'] . ', deleting orcidAccessToken from author');
OrcidManager::logError($error['error_description'] . ', deleting orcidAccessToken from author', $this->context);
OrcidManager::removeOrcidAccessToken($this->author);
}
break;
case 403:
OrcidManager::logError('Work update forbidden: ' . $response->getBody());
OrcidManager::logError('Work update forbidden: ' . $response->getBody(), $this->context);
break;
case 404:
// a work has been deleted from a ORCID record. putCode is no longer valid.
if ($method === 'PUT') {
OrcidManager::logError('Work deleted from ORCID record, deleting putCode form author');
OrcidManager::logError('Work deleted from ORCID record, deleting putCode form author', $this->context);
$this->author->setData('orcidWorkPutCode', null);
Repo::author()->dao->update($this->author);
} else {
OrcidManager::logError("Unexpected status {$httpStatus} response, body: " . $response->getBody());
OrcidManager::logError("Unexpected status {$httpStatus} response, body: " . $response->getBody(), $this->context);
}
break;
case 409:
OrcidManager::logError('Work already added to profile, response body: ' . $response->getBody());
OrcidManager::logError('Work already added to profile, response body: ' . $response->getBody(), $this->context);
break;
default:
OrcidManager::logError("Unexpected status {$httpStatus} response, body: " . $response->getBody());
OrcidManager::logError("Unexpected status {$httpStatus} response, body: " . $response->getBody(), $this->context);
}
}
}

0 comments on commit 66a7b5c

Please sign in to comment.