Skip to content

Commit

Permalink
Work on #14.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Dec 30, 2018
1 parent 5bdd669 commit 8abb37a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
11 changes: 8 additions & 3 deletions src/Command/CheckFixityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
$num_successful_events = 0;
$num_failed_events = 0;
foreach ($resource_ids as $resource_id) {
// If the resource ID is empty, don't continue.
if (!strlen($resource_id)) {
continue;
}
$uuid4 = Uuid::uuid4();
$event_uuid = $uuid4->toString();
$now_iso8601 = date(\DateTime::ISO8601);

$event_detail = '';

// Print output and log it.
$this->logger->info("check_fixity ran.", array('event_uuid' => $event_uuid));

// Execute plugins that persist event data. We execute them twice and pass in an 'operation' option,
// once to get the last digest for the resource and again to persist the event resulting from comparing
// that digest with a new one.
Expand Down Expand Up @@ -252,11 +253,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
);
}
}

// Print output and log it.
// $this->logger->info("check_fixity ran.", array('event_uuid' => $event_uuid));
}

$fixity_check = $stopwatch->stop('fixity_check');
$duration = $fixity_check->getDuration(); // milliseconds
$duration = $duration / 1000; // seconds

$output->writeln("Riprap checked $num_resource_ids resources ($num_successful_events successful events, " .
"$num_failed_events failed events) in $duration seconds.");
}
Expand Down
8 changes: 7 additions & 1 deletion src/Command/PluginFetchDigestFromFedoraAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$client = new \GuzzleHttp\Client();
// @todo: Wrap in try/catch.
$url = $input->getOption('resource_id');
if (!strlen($url)) {
if ($this->logger) {
$this->logger->info("PluginFetchDigestFromFedoraAPI exited due to empty resource ID.");
}
return;
}

$response = $client->request($this->http_method, $url, [
'http_errors' => false,
Expand Down Expand Up @@ -85,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// $this->logger is null while testing.
if ($this->logger) {
$this->logger->info("PluginPersistToDatabase executed");
$this->logger->info("PluginFetchDigestFromFedoraAPI executed");
}
}
}
33 changes: 25 additions & 8 deletions src/Command/PluginFetchResourceListFromDrupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
// get checked immediately after they are added/updated.
'query' => ['page[offset]' => $page_offset, 'page[limit]' => $this->page_size, 'sort' => '-changed']
]);
var_dump($page_offset);
var_dump($this->page_size);

$status_code = $response->getStatusCode();
$node_list = (string) $response->getBody();
$node_list_array = json_decode($node_list, true);
var_dump($node_list_array['links']);

if ($status_code === 200) {
$this->setPageOffset($page_offset, $node_list_array['links']);
Expand All @@ -93,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

foreach ($node_list_array['data'] as $node) {
$nid = $node['attributes']['nid'];
$nid = $node['attributes']['nid'];
// Get the media associated with this node using the Islandora-supplied Manage Media View.
$media_client = new \GuzzleHttp\Client();
$media_url = $this->drupal_base_url . '/node/' . $nid . '/media';
Expand All @@ -106,6 +104,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
$media_list = (string) $media_response->getBody();
$media_list = json_decode($media_list, true);

if (count($media_list) === 0) {
if ($this->logger) {
$this->logger->info("PluginFetchResourceListFromDrupal is skipping node with an empty media list.",
array(
'Node ID' => $nid
)
);
}
continue;
}

// Loop through all the media and pick the ones that are tagged with terms in $taxonomy_terms_to_check.
foreach ($media_list as $media) {
if (count($media['field_media_use'])) {
Expand All @@ -118,19 +127,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (isset($media['field_media_image'])) {
$fedora_url = $this->getFedoraUrl($media['field_media_image'][0]['target_uuid']);
// This is a string containing one resource ID (URL) per line;
$output->writeln($fedora_url);
if (strlen($fedora_url)) {
$output->writeln($fedora_url);
}
} else {
$fedora_url = $this->getFedoraUrl($media['field_media_file'][0]['target_uuid']);
// This is a string containing one resource ID (URL) per line;
$output->writeln($fedora_url);
if (strlen($fedora_url)) {
$output->writeln($fedora_url);
}
}
} else {
if (isset($media['field_media_image'])) {
// This is a string containing one resource ID (URL) per line;
$output->writeln($media['field_media_image'][0]['url']);
if (strlen($media['field_media_image'][0]['url'])) {
$output->writeln($media['field_media_image'][0]['url']);
}
} else {
// This is a string containing one resource ID (URL) per line;
$output->writeln($media['field_media_file'][0]['url']);
if (strlen($media['field_media_file'][0]['url'])) {
$output->writeln($media['field_media_file'][0]['url']);
}
}
}
}
Expand Down

0 comments on commit 8abb37a

Please sign in to comment.