Merge pull request #17683 from agh1/memberdetailreportautorenew
[civicrm-core.git] / setup / plugins / installDatabase / FlushBackdrop.civi-setup.php
CommitLineData
4bcd4c62
TO
1<?php
2/**
3 * @file
4 *
5 * Configure settings on the newly populated database.
6 */
7
8if (!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 !== 'Backdrop') {
15 return;
16 }
17 \Civi\Setup::log()->info(sprintf('[%s] Flush CMS metadata', basename(__FILE__)));
18
ec3d5dff
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 = &backdrop_static('civicrm_initialize', FALSE);
22 $failure = &backdrop_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 backdrop_flush_all_caches();
29 civicrm_install_set_backdrop_perms();
30 }, \Civi\Setup::PRIORITY_LATE + 50);
31
32function civicrm_install_set_backdrop_perms() {
33 $perms = array(
34 'access all custom data',
35 'access uploaded files',
36 'make online contributions',
37 'profile create',
38 'profile edit',
39 'profile view',
40 'register for events',
41 'view event info',
42 'view event participants',
43 'access CiviMail subscribe/unsubscribe pages',
44 );
45
46 // Adding a permission that has not yet been assigned to a module by
47 // a hook_permission implementation results in a database error.
48 // CRM-9042
49 $allPerms = array_keys(module_invoke_all('permission'));
50 foreach (array_diff($perms, $allPerms) as $perm) {
51 watchdog('civicrm',
52 'Cannot grant the %perm permission because it does not yet exist.',
53 array('%perm' => $perm),
54 WATCHDOG_ERROR
55 );
56 }
57 $perms = array_intersect($perms, $allPerms);
58 user_role_grant_permissions(BACKDROP_AUTHENTICATED_ROLE, $perms);
59 user_role_grant_permissions(BACKDROP_ANONYMOUS_ROLE, $perms);
60}