From 26099bf167471a31572f2246be01561b931d4a6e Mon Sep 17 00:00:00 2001 From: Mark Jordan Date: Tue, 18 Aug 2020 20:39:16 -0700 Subject: [PATCH] WIP on #44. --- src/Plugin/PluginFetchDigestFromDrupal.php | 73 +++++++++++++++++++ src/Plugin/PluginFetchDigestFromFedoraAPI.php | 4 +- 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/Plugin/PluginFetchDigestFromDrupal.php diff --git a/src/Plugin/PluginFetchDigestFromDrupal.php b/src/Plugin/PluginFetchDigestFromDrupal.php new file mode 100644 index 0000000..58138b4 --- /dev/null +++ b/src/Plugin/PluginFetchDigestFromDrupal.php @@ -0,0 +1,73 @@ +settings['fixity_algorithm'])) { + $this->fixity_algorithm = $this->settings['fixity_algorithm']; + } else { + $this->fixity_algorithm = 'sha1'; + } + + $client = new \GuzzleHttp\Client(); + // @todo: Wrap in try/catch. + + // @todo: Request is to /islandora_riprap/checksum/{file_uuid}/{algorithm}, not to the resource ID as with Fedora. + $url = $resource_id; + if (!strlen($url)) { + if ($this->logger) { + $this->logger->info("PluginFetchDigestFromDrupal exited due to empty resource ID."); + } + return; + } + + $response = $client->request('GET', $url, [ + 'http_errors' => false, + ]); + $status_code = $response->getStatusCode(); + $allowed_codes = array(200); + if (in_array($status_code, $allowed_codes)) { + $response_body = json_decode($response->getBody(), true); + return $response_body[0]->checksum; + } else { + // If the HTTP status code is not in the allowed list, log it. + $this->logger->warning("check_fixity cannot retrieve digest from Drupal.", array( + 'resource_id' => $url, + 'status_code' => $status_code, + )); + return false; + } + + if ($this->event_detail) { + $this->event_detail->add('event_outcome_detail_note', ''); + } + + // $this->logger is null while testing. + if ($this->logger) { + $this->logger->info("PluginFetchDigestFromDrupal executed"); + } + } +} diff --git a/src/Plugin/PluginFetchDigestFromFedoraAPI.php b/src/Plugin/PluginFetchDigestFromFedoraAPI.php index 08eb552..c734d46 100644 --- a/src/Plugin/PluginFetchDigestFromFedoraAPI.php +++ b/src/Plugin/PluginFetchDigestFromFedoraAPI.php @@ -11,7 +11,7 @@ use GuzzleHttp\Exception\RequestException; /** - * Class for the Riprap PluginFetchDigestFromShell plugin. + * Class for the Riprap PluginFetchDigestFromFedoraAPI plugin. */ class PluginFetchDigestFromFedoraAPI extends AbstractFetchDigestPlugin { @@ -68,7 +68,7 @@ public function execute($resource_id) return $digest_header_value; } else { // If the HTTP status code is not in the allowed list, log it. - $this->logger->warning("check_fixity cannot retrieve digest from repository.", array( + $this->logger->warning("check_fixity cannot retrieve digest from Fedora repository.", array( 'resource_id' => $url, 'status_code' => $status_code, ));