diff --git a/drush.services.yml b/drush.services.yml new file mode 100644 index 0000000000000000000000000000000000000000..4d67a5865d2dc9cf649462e935b075d86a02ee21 --- /dev/null +++ b/drush.services.yml @@ -0,0 +1,6 @@ +services: + uw_cfg_common.commands: + class: Drupal\uw_cfg_common\Commands\UwDrushCommands + arguments: ['@entity_type.manager'] + tags: + - { name: drush.command } diff --git a/src/Commands/UwDrushCommands.php b/src/Commands/UwDrushCommands.php new file mode 100644 index 0000000000000000000000000000000000000000..46122f2b46c2306efc64e17ababada2fd39f60e3 --- /dev/null +++ b/src/Commands/UwDrushCommands.php @@ -0,0 +1,59 @@ +<?php + +namespace Drupal\uw_cfg_common\Commands; + +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\uw_cfg_common\UwRoles\UwRoles; +use Drush\Commands\DrushCommands; + +/** + * Drush commands for uw_cfg_common module. + * + * @package Drupal\uw_cfg_common\Commands + */ +class UwDrushCommands extends DrushCommands { + + /** + * Entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + + /** + * {@inheritDoc} + */ + public function __construct(EntityTypeManagerInterface $entityTypeManager) { + $this->entityTypeManager = $entityTypeManager; + } + + /** + * Drush command to update permissions. + * + * @command uwcfgcommon:catalog + * @aliases uwperm + * @usage uwperm + */ + public function updatePermissions() { + + // Get all the role ids in the system. + $rids = UwRoles::getAllRoles(); + + // Step through each rid and set the permissions. + foreach ($rids as $rid) { + + // Get the info about the role. + $uw_role = UwRoles::getUwRole($rid); + + // Set the permissions for the role. + UwRoles::setUwPermissions($uw_role); + + // Set message for specific role setting permissions. + $this->logger()->success('Permissions set for ' . $uw_role['label'] . '.'); + } + + // Set message for command completed. + $this->logger()->success('All permissions set.'); + } + +}