diff --git a/composer.json b/composer.json index b4336bc..e6fda1b 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "extra": { "drush": { "services": { + "drush.11.6-12.5.yml": ">=11.6", "drush.10.services.yml": "^10 || ^11" } } diff --git a/drush.10.services.yml b/drush.10.services.yml index d1b1859..4c5e8ef 100644 --- a/drush.10.services.yml +++ b/drush.10.services.yml @@ -28,6 +28,7 @@ services: arguments: - '@account_switcher' - '@entity_type.manager' + - '@logger.islandora_drush_utils' tags: - name: drush.command islandora_drush_utils.command.user_wrapping_alterer: diff --git a/drush.11.6-12.5.yml b/drush.11.6-12.5.yml new file mode 100644 index 0000000..94b8965 --- /dev/null +++ b/drush.11.6-12.5.yml @@ -0,0 +1,6 @@ +--- +# XXX: Command files are expected to make use of newer methods of instantiation, +# such as: +# - create() method as of Drush 11.6; or, +# - autowiring as of Drush 12.5 +services: {} diff --git a/islandora_drush_utils.module b/islandora_drush_utils.module index 38ba004..8c5cda8 100644 --- a/islandora_drush_utils.module +++ b/islandora_drush_utils.module @@ -8,7 +8,7 @@ /** * Implements hook_batch_alter(). */ -function islandora_drush_utils_batch_alter(&$batch) { +function islandora_drush_utils_batch_alter(array &$batch) : void { // Better preservation messsaging. foreach ($batch['sets'] as &$set) { if (!isset($set['operations'])) { @@ -59,24 +59,24 @@ function islandora_drush_utils_batch_alter(&$batch) { if (is_string($callable)) { return trim($callable); } - elseif (is_array($callable)) { + + if (is_array($callable)) { if (is_object($callable[0])) { return sprintf("(%s instance)::%s", get_class($callable[0]), trim($callable[1])); } - else { - return sprintf("%s::%s", trim($callable[0]), trim($callable[1])); - } + + return sprintf("%s::%s", trim($callable[0]), trim($callable[1])); } - elseif ($callable instanceof Closure) { + + if ($callable instanceof Closure) { return 'closure'; } - else { - return 'unknown'; - } + + return 'unknown'; }; - $wrap_op = function ($op) use ($user, $logger, $namer) { + $wrap_op = static function ($op) use ($user, $logger, $namer) { $func = reset($op); if ($func !== '_islandora_drush_utils_user_wrapped_batch_op') { $logger->debug('Wrapping @func with @wrapper to maintain the user (@uid).', @@ -93,9 +93,8 @@ function islandora_drush_utils_batch_alter(&$batch) { ], ]; } - else { - return $op; - } + + return $op; }; foreach ($batch['sets'] as &$set) { @@ -108,7 +107,7 @@ function islandora_drush_utils_batch_alter(&$batch) { /** * Wrap batch op with user. */ -function _islandora_drush_utils_user_wrapped_batch_op($id, $info, &$context) { +function _islandora_drush_utils_user_wrapped_batch_op(int|string $id, array $info, array &$context) { $switcher = \Drupal::service('account_switcher'); try { $user = \Drupal::service('entity_type.manager') diff --git a/src/Drush/Commands/UserWrapperCommands.php b/src/Drush/Commands/UserWrapperCommands.php index 5e2e645..7011afc 100644 --- a/src/Drush/Commands/UserWrapperCommands.php +++ b/src/Drush/Commands/UserWrapperCommands.php @@ -9,10 +9,11 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountSwitcherInterface; -use Psr\Log\LoggerAwareInterface; -use Psr\Log\LoggerAwareTrait; +use Drush\Commands\AutowireTrait; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -23,9 +24,9 @@ * "@islandora_drush_utils-user-wrap" annotation to use it where we want * to. */ -class UserWrapperCommands implements LoggerAwareInterface, ContainerInjectionInterface { +class UserWrapperCommands implements ContainerInjectionInterface { - use LoggerAwareTrait; + use AutowireTrait; /** * The user to which we will switch. @@ -42,6 +43,8 @@ class UserWrapperCommands implements LoggerAwareInterface, ContainerInjectionInt public function __construct( protected AccountSwitcherInterface $switcher, protected EntityTypeManagerInterface $entityTypeManager, + #[Autowire(service: 'logger.islandora_drush_utils')] + protected LoggerInterface $logger, protected $debug = FALSE, ) { } @@ -53,6 +56,7 @@ public static function create(ContainerInterface $container) { return new static( $container->get('account_switcher'), $container->get('entity_type.manager'), + $container->get('logger.islandora_drush_utils'), FALSE, ); }