Merge pull request #17374 from totten/master-setlocale
[civicrm-core.git] / setup / plugins / installDatabase / FlushDrupal.civi-setup.php
1 <?php
2 /**
3 * @file
4 *
5 * Finalize any extra CMS changes in Drupal.
6 */
7
8 if (!defined('CIVI_SETUP')) {
9 exit("Installation plugins must only be loaded by the installer.\n");
10 }
11
12 \Civi\Setup::dispatcher()
13 ->addListener('civi.setup.installDatabase', function (\Civi\Setup\Event\InstallDatabaseEvent $e) {
14 if ($e->getModel()->cms !== 'Drupal') {
15 return;
16 }
17 \Civi\Setup::log()->info(sprintf('[%s] Flush CMS metadata', basename(__FILE__)));
18
19 system_rebuild_module_data();
20 module_enable(array('civicrm', 'civicrmtheme'));
21 drupal_flush_all_caches();
22 civicrm_install_set_drupal_perms();
23
24 }, \Civi\Setup::PRIORITY_LATE - 50);
25
26 function civicrm_install_set_drupal_perms() {
27 if (!function_exists('db_select')) {
28 db_query('UPDATE {permission} SET perm = CONCAT( perm, \', access CiviMail subscribe/unsubscribe pages, access all custom data, access uploaded files, make online contributions, profile listings and forms, register for events, view event info, view event participants\') WHERE rid IN (1, 2)');
29 }
30 else {
31 $perms = array(
32 'access all custom data',
33 'access uploaded files',
34 'make online contributions',
35 'profile create',
36 'profile edit',
37 'profile view',
38 'register for events',
39 'view event info',
40 'view event participants',
41 'access CiviMail subscribe/unsubscribe pages',
42 );
43
44 // Adding a permission that has not yet been assigned to a module by
45 // a hook_permission implementation results in a database error.
46 // CRM-9042
47 $allPerms = array_keys(module_invoke_all('permission'));
48 foreach (array_diff($perms, $allPerms) as $perm) {
49 watchdog('civicrm',
50 'Cannot grant the %perm permission because it does not yet exist.',
51 array('%perm' => $perm),
52 WATCHDOG_ERROR
53 );
54 }
55 $perms = array_intersect($perms, $allPerms);
56 user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, $perms);
57 user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, $perms);
58 }
59 }