forked from linnovate/openideal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idea.install
84 lines (69 loc) · 2.42 KB
/
idea.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* @file
* Install, update and uninstall functions for the idea install profile.
*/
use Drupal\user\Entity\User;
use Symfony\Component\HttpFoundation\Request;
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function idea_install() {
// Assign user 1 the "administrator" role.
// @see standard_install().
$user = User::load(1);
$user->roles[] = 'administrator';
$user->save();
// Install 'openideal_content' module.
\Drupal::service('module_installer')->install(['openideal_content']);
// Force set the administerusersbyrole configuration in fact
// the module change it during installation of profile.
// @todo Further investigation.
\Drupal::configFactory()->getEditable('administerusersbyrole.settings')->set('roles', ['manager' => 'safe'])->save();
// To avoid issues with importing of configurations set system.site
// config programmatically.
\Drupal::configFactory()->getEditable('system.site')
->set('name', 'OpenideaL')
->set('slogan', 'Ideas, challenges, news')
->set('page', ['front' => '/home'])
->save();
drupal_register_shutdown_function('_idea_rebuild_cache');
}
/**
* Force rebuild all Drupal's caches.
*
* Rules require clearing the cache to rebuild the container and register
* new rules events. Clearing cache in hook_install() didn't help, that's
* why it was moved to shutdown function.
*/
function _idea_rebuild_cache() {
$loader = require DRUPAL_ROOT . '/autoload.php';
include_once DRUPAL_ROOT . '/core/includes/utility.inc';
$request = Request::createFromGlobals();
// Clear user cache for all major platforms.
$user_caches = [
'apcu_clear_cache',
'wincache_ucache_clear',
'xcache_clear_cache',
];
array_map('call_user_func', array_filter($user_caches, 'is_callable'));
drupal_rebuild($loader, $request);
}
/**
* Configuration update.
*/
function idea_update_8001() {
if (!\Drupal::moduleHandler()->moduleExists('update_helper')) {
\Drupal::service('module_installer')->install(['update_helper']);
}
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper->executeUpdate('idea', 'idea_update_8001');
// Output logged messages to related channel of update execution.
return $updateHelper->logger()->output();
}