From 40d5632a25086d7c963538f2b6daf2a2546e16a6 Mon Sep 17 00:00:00 2001 From: Allen Shaw Date: Mon, 1 Feb 2016 13:02:56 -0600 Subject: [PATCH] Moved system flush from setup.sh to first-run; added permissionEmails() and upgradePermissions() in CRM_Core_Permission_Drupal8. --- CRM/Core/Permission/Drupal8.php | 45 ++++++++++++++++++++++++++ Civi/Core/Container.php | 1 + Civi/Core/DatabaseInitializer.php | 53 +++++++++++++++++++++++++++++++ bin/setup.sh | 3 -- 4 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 Civi/Core/DatabaseInitializer.php diff --git a/CRM/Core/Permission/Drupal8.php b/CRM/Core/Permission/Drupal8.php index 3b7d69a513..58b9cae7ad 100644 --- a/CRM/Core/Permission/Drupal8.php +++ b/CRM/Core/Permission/Drupal8.php @@ -61,4 +61,49 @@ class CRM_Core_Permission_Drupal8 extends CRM_Core_Permission_DrupalBase { return \Drupal::currentUser()->hasPermission($str); } + /** + * Get all the contact emails for users that have a specific permission. + * + * @param string $permissionName + * Name of the permission we are interested in. + * + * @return string + * a comma separated list of email addresses + */ + public function permissionEmails($permissionName) { + static $_cache = array(); + + if (isset($_cache[$permissionName])) { + return $_cache[$permissionName]; + } + + $role_ids = array_map( + function (\Drupal\user\RoleInterface $role) { + return $role->id(); + }, user_roles(TRUE, $permissionName) + ); + $users = \Drupal::entityTypeManager()->getStorage('user')->loadByProperties(array('roles' => $role_ids)); + $uids = array_keys($users); + + $_cache[$permissionName] = self::getContactEmails($uids); + return $_cache[$permissionName]; + } + + /** + * @inheritDoc + */ + public function upgradePermissions($permissions) { + $civicrm_perms = array_keys(CRM_Core_Permission::getCorePermissions()); + if (empty($civicrm_perms)) { + throw new CRM_Core_Exception("Cannot upgrade permissions: permission list missing"); + } + + $roles = user_roles(TRUE); + foreach ($roles as $role) { + foreach ($civicrm_perms as $permission) { + $role->revokePermission($permission); + } + } + } + } diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index fdcf1b1559..68404a6028 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -226,6 +226,7 @@ class Container { public function createEventDispatcher($container) { $dispatcher = new ContainerAwareEventDispatcher($container); $dispatcher->addListener(SystemInstallEvent::EVENT_NAME, array('\Civi\Core\InstallationCanary', 'check')); + $dispatcher->addListener(SystemInstallEvent::EVENT_NAME, array('\Civi\Core\DatabaseInitializer', 'initialize')); $dispatcher->addListener('hook_civicrm_post::Activity', array('\Civi\CCase\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_post::Case', array('\Civi\CCase\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_caseChange', array('\Civi\CCase\Events', 'delegateToXmlListeners')); diff --git a/Civi/Core/DatabaseInitializer.php b/Civi/Core/DatabaseInitializer.php new file mode 100644 index 0000000000..91ead0c6d4 --- /dev/null +++ b/Civi/Core/DatabaseInitializer.php @@ -0,0 +1,53 @@ + 3, + 'triggers' => 1, + 'session' => 1, + ); + civicrm_api('System', 'flush', $api_params); + } + +} diff --git a/bin/setup.sh b/bin/setup.sh index b242dc4ae1..fc59804214 100755 --- a/bin/setup.sh +++ b/bin/setup.sh @@ -228,9 +228,6 @@ fi if [ -n "$DO_FLUSH" ]; then pushd "$CALLEDPATH/.." - # run the cli script to build the menu and the triggers - "$PHP5PATH"php bin/cli.php -e System -a flush --triggers 1 --session 1 - # reset config_backend and userFrameworkResourceURL which gets set # when config object is initialized $MYSQLCMD -e "UPDATE civicrm_domain SET config_backend = NULL; UPDATE civicrm_setting SET value = NULL WHERE name = 'userFrameworkResourceURL';" -- 2.25.1