Commit | Line | Data |
---|---|---|
4bcd4c62 TO |
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 | ||
2c17384c TO |
19 | // If the admin activated the module first, and then ran web-based installer, |
20 | // then some hooks (eg hook_menu) may not fire until we fix this flag. | |
21 | $initialized = &drupal_static('civicrm_initialize', FALSE); | |
22 | $failure = &drupal_static('civicrm_initialize_failure', FALSE); | |
23 | $initialized = TRUE; | |
24 | $failure = FALSE; | |
25 | ||
4bcd4c62 TO |
26 | system_rebuild_module_data(); |
27 | module_enable(array('civicrm', 'civicrmtheme')); | |
28 | drupal_flush_all_caches(); | |
29 | civicrm_install_set_drupal_perms(); | |
30 | ||
31 | }, \Civi\Setup::PRIORITY_LATE - 50); | |
32 | ||
33 | function civicrm_install_set_drupal_perms() { | |
34 | if (!function_exists('db_select')) { | |
35 | 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)'); | |
36 | } | |
37 | else { | |
38 | $perms = array( | |
39 | 'access all custom data', | |
40 | 'access uploaded files', | |
41 | 'make online contributions', | |
42 | 'profile create', | |
43 | 'profile edit', | |
44 | 'profile view', | |
45 | 'register for events', | |
46 | 'view event info', | |
47 | 'view event participants', | |
48 | 'access CiviMail subscribe/unsubscribe pages', | |
49 | ); | |
50 | ||
51 | // Adding a permission that has not yet been assigned to a module by | |
52 | // a hook_permission implementation results in a database error. | |
53 | // CRM-9042 | |
54 | $allPerms = array_keys(module_invoke_all('permission')); | |
55 | foreach (array_diff($perms, $allPerms) as $perm) { | |
56 | watchdog('civicrm', | |
57 | 'Cannot grant the %perm permission because it does not yet exist.', | |
58 | array('%perm' => $perm), | |
59 | WATCHDOG_ERROR | |
60 | ); | |
61 | } | |
62 | $perms = array_intersect($perms, $allPerms); | |
63 | user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, $perms); | |
64 | user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, $perms); | |
65 | } | |
66 | } |