This script adds the ability to use drush to generate missing derivatives. This looks for nodes without a service file (the hint that a derivative wasn't generated) and triggers the derivative actions.
Note: that drush commands that trigger actions should also specify the site url. E.g. drush -l https://islandora.traefik.me scr /var/www/drupal/vendor/drush/drush/src/Utils/generate-image-derivatives.php
. Otherwise the messages alpaca receives includes paths like "default/node//media/add/" and it doesn't know what to do with that. I should have mentioned that before.
- Original Script: https://gist.github.com/seth-shaw-unlv/2b6dc74b4b1b988b4224b12ceac06953
- Chat discussion: https://islandora.slack.com/archives/CM6F4C4VA/p1649085505531249
wget https://gist.githubusercontent.com/DonRichards/cc6025eced330c325b4af96a15bf2cb4/raw/1f6f84b61d76ebf63ab9b148ae45c010f13d58ec/generate-image-derivatives.php
chmod +x generate-image-derivatives.php
chmod 755 generate-image-derivatives.php
chown nginx: generate-image-derivatives.php
mv generate-image-derivatives.php /var/www/drupal/vendor/drush/drush/src/Utils/generate-image-derivatives.php
drush -l https://islandora.traefik.me scr /var/www/drupal/vendor/drush/drush/src/Utils/generate-image-derivatives.php
-
Added
accessCheck(FALSE)
to entity queries:- For
taxonomy_term
entity queries, theaccessCheck(FALSE)
method was added to explicitly disable access checking.
$original_tid = reset( \Drupal::entityQuery('taxonomy_term') ->condition('field_external_uri', 'http://pcdm.org/use#OriginalFile') ->accessCheck(FALSE) ->execute() ); $intermediate_tid = reset( \Drupal::entityQuery('taxonomy_term') ->condition('field_external_uri', 'http://pcdm.org/use#IntermediateFile') ->accessCheck(FALSE) ->execute() ); $service_tid = reset( \Drupal::entityQuery('taxonomy_term') ->condition('field_external_uri', 'http://pcdm.org/use#ServiceFile') ->accessCheck(FALSE) ->execute() );
- For
-
Added a check to ensure the
node
is loaded before calling methods on it:- Before executing actions on the
node
, added a check to ensure that thenode
is notnull
.
foreach ($results as $nid) { $node = \Drupal::entityTypeManager()->getStorage('node')->load($nid); if ($node) { // Check if the node is loaded successfully $action = (in_array($nid, $nodes_w_intermediates)) ? $intermediate_action : $original_action; printf("Performing '%s' on '%s' at %s\n", $action->id(), $node->toUrl()->toString(), date(DATE_ATOM)); $action->execute([$node]); } else { printf("Node with ID '%s' could not be loaded\n", $nid); } }
- Before executing actions on the
These changes ensure that the script handles access checks explicitly and prevents errors when attempting to call methods on null
objects.