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 10, 2018
1 parent d8eb3d1 commit e2884f6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 13 deletions.
10 changes: 8 additions & 2 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ parameters:
app.service.detailmanager.delimiter: ';'

# To not register any fetchresourcelist plugins, use app.plugins.fetchresourcelist []
app.plugins.fetchresourcelist: ['app:riprap:plugin:fetchresourcelist:from:file']
# app.plugins.fetchresourcelist: ['app:riprap:plugin:fetchresourcelist:from:file']
app.plugins.fetchresourcelist.from.file.paths: ['resources/riprap_resource_ids.txt']
app.plugins.fetchresourcelist.from.drupal.baseurl: ['http://localhost:8000']

# Settings for the app:riprap:plugin:fetchresourcelist:from:drupal plugin.
app.plugins.fetchresourcelist: ['app:riprap:plugin:fetchresourcelist:from:drupal']
app.plugins.fetchresourcelist.from.drupal.baseurl: 'http://localhost:8000'
app.plugins.fetchresourcelist.from.drupal.authorization_headers: ['Authorization: Basic YWRtaW46aXNsYW5kb3Jh'] # admin:islandora
app.plugins.fetchresourcelist.from.drupal.content_types: ['islandora_object']
app.plugins.fetchresourcelist.from.drupal.media_tags: ['/taxonomy/term/2']

# To not register any fetchdigest plugins, use app.plugins.fetchdigest [].
# Currently we only allow one fetchdigest plugin per fixity event (i.e., this
Expand Down
67 changes: 56 additions & 11 deletions src/Command/PluginFetchResourceListFromDrupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;

use Psr\Log\LoggerInterface;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use App\Entity\Event;
use App\Service\FixityEventDetailManager;

Expand All @@ -23,7 +24,12 @@ public function __construct(
FixityEventDetailManager $event_detail = null
) {
$this->params = $params;
$this->input_files = $this->params->get('app.plugins.fetchresourcelist.from.drupal.baseurl');
$this->drupal_base_url = $this->params->get('app.plugins.fetchresourcelist.from.drupal.baseurl');
// An array, we need to loop through and add to guzzle request.
$this->jsonapi_authorization_headers = $this->params->get('app.plugins.fetchresourcelist.from.drupal.authorization_headers');
// For now we only use the first one, not sure how to handle multiple content types.
$this->drupal_content_types = $this->params->get('app.plugins.fetchresourcelist.from.drupal.content_types');
$this->media_tags = $this->params->get('app.plugins.fetchresourcelist.from.drupal.media_tags');

$this->logger = $logger;
$this->event_detail = $event_detail;
Expand All @@ -42,20 +48,59 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
// @todo: See https://github.com/mjordan/riprap/issues/14.

/*
foreach ($this->input_files as $input_file) {
$resource_ids = file($input_file, FILE_IGNORE_NEW_LINES);
foreach ($resource_ids as $resource_id) {
// This is a string containing one resource ID (URL) per line;
$output->writeln($resource_id);
$client = new \GuzzleHttp\Client();
$url = $this->drupal_base_url . '/jsonapi/node/' . $this->drupal_content_types[0];
// First, get JSON:API's first page of nodes, then loop through each one and print it to output.
// curl -v -H 'Authorization: Basic YWRtaW46aXNsYW5kb3Jh' "http://localhost:8000/jsonapi/node/islandora_object?page[offset]=2&page[limit]=1"
$response = $client->request('GET', $url, [
'http_errors' => false,
'headers' => [$this->jsonapi_authorization_headers[0]], // @todo: Loop through this array and add each header.
'query' => ['page[offset]' => '1', 'page[limit]' => '3']
]);
$status_code = $response->getStatusCode();
// var_dump($status_code);
$node_list = (string) $response->getBody();
$node_list_array = json_decode($node_list, true);
// var_dump($node_list_array);

foreach ($node_list_array['data'] as $node) {
$nid = $node['attributes']['nid'];
// var_dump($nid);
// Get the media associated with this node using the Islandora-supplied Manage Media View.
$media_url = $this->drupal_base_url . '/node/' . $nid . '/media';
$media_response = $client->request('GET', $url, [
'http_errors' => false,
// @todo: Split this header out into its own config parameter.
'headers' => [$this->jsonapi_authorization_headers[0]],
'query' => ['_format' => 'json']
]);
$status_code = $media_response->getStatusCode();
// var_dump($status_code);
$media_list = (string) $response->getBody();
$media_list = json_decode($media_list, true);

// Loop through all the media and pick the ones that
// are tagged with terms in $taxonomy_terms_to_check.
foreach ($media_list as $media) {
var_dump($media);
if (count($media->field_tags)) {
foreach ($media->field_tags as $term) {
if (in_array($term->url, $taxonomy_terms_to_check)) {
// @todo: Convert to the equivalent Fedora URL and add to the plugin's output.
// @todo: Add option to not convert to Fedora URL if the site doesn't use Fedora.
// In that case, we need to figure out how to get Drupal's checksum for the file over HTTP.
// var_dump($media->field_media_image[0]->url);
$output->writeln($resource_id);
}
}
}
}
}
*/

}

// $this->logger is null while testing.
if ($this->logger) {
$this->logger->info("PluginPersistToDatabase executed");
$this->logger->info("PluginFetchResourceListFromDrupal executed");
}
}
}

0 comments on commit e2884f6

Please sign in to comment.