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 11, 2018
1 parent e2884f6 commit 9832337
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
5 changes: 3 additions & 2 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ parameters:
# 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.json_authorization_headers: ['Authorization: Basic YWRtaW46aXNsYW5kb3Jh'] # admin:islandora
app.plugins.fetchresourcelist.from.drupal.media_auth: ['admin', 'islandora']
app.plugins.fetchresourcelist.from.drupal.content_types: ['islandora_object']
app.plugins.fetchresourcelist.from.drupal.media_tags: ['/taxonomy/term/2']
app.plugins.fetchresourcelist.from.drupal.media_tags: ['/taxonomy/term/15']

# 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
32 changes: 18 additions & 14 deletions src/Command/PluginFetchResourceListFromDrupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function __construct(
$this->params = $params;
$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');
$this->jsonapi_authorization_headers = $this->params->get('app.plugins.fetchresourcelist.from.drupal.json_authorization_headers');
$this->media_auth = $this->params->get('app.plugins.fetchresourcelist.from.drupal.media_auth');
// 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');
Expand Down Expand Up @@ -67,30 +68,30 @@ protected function execute(InputInterface $input, OutputInterface $output)
$nid = $node['attributes']['nid'];
// var_dump($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';
$media_response = $client->request('GET', $url, [
$media_response = $media_client->request('GET', $media_url, [
'http_errors' => false,
// @todo: Split this header out into its own config parameter.
'headers' => [$this->jsonapi_authorization_headers[0]],
'auth' => $this->media_auth,
'query' => ['_format' => 'json']
]);
$status_code = $media_response->getStatusCode();
// var_dump($status_code);
$media_list = (string) $response->getBody();
$media_status_code = $media_response->getStatusCode();
$media_list = (string) $media_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.
// var_dump($media);
if (count($media['field_media_use'])) {
foreach ($media['field_media_use'] as $term) {
if (in_array($term['url'], $this->media_tags)) {
// @todo: Convert to the equivalent Fedora URL and add to the plugin's output by querying Gemini.
// 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);
// $output->writeln($media['field_media_image'][0]['url']);
var_dump($media['field_media_image'][0]['url']);
}
}
}
Expand All @@ -102,5 +103,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($this->logger) {
$this->logger->info("PluginFetchResourceListFromDrupal executed");
}

// during development, so downstream plugins aren't fired.
exit;
}
}

0 comments on commit 9832337

Please sign in to comment.