From f2bca91a5023a09fd9b0f7ebccf84e648fee1dcb Mon Sep 17 00:00:00 2001 From: Eric Bremner <ebremner@uwaterloo.ca> Date: Fri, 23 Jul 2021 15:19:30 +0000 Subject: [PATCH] ISTWCMS-4954: add drush command to set permissions --- drush.services.yml | 6 ++++ src/Commands/UwDrushCommands.php | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 drush.services.yml create mode 100644 src/Commands/UwDrushCommands.php diff --git a/drush.services.yml b/drush.services.yml new file mode 100644 index 00000000..4d67a586 --- /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 00000000..46122f2b --- /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.'); + } + +} -- GitLab