-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhelfi_platform_config.install
195 lines (167 loc) · 5.64 KB
/
helfi_platform_config.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/**
* @file
* Contains installation hooks for HELfi platform config module.
*/
use Drupal\user\Entity\User;
/**
* UHF-9113: Remove obsolete hotjar permission.
*/
function helfi_platform_config_update_9301(): void {
helfi_platform_config_remove_permissions_from_all_roles([
'administer hotjar settings',
]);
}
/**
* Config_filter becomes obsolete after config_ignore 3.x upgrade.
*/
function helfi_platform_config_update_9302(): void {
$module_installer = \Drupal::service('module_installer');
if (\Drupal::moduleHandler()->moduleExists('config_filter')) {
$module_installer->uninstall(['config_filter']);
}
}
/**
* Create an email address for all read_only users missing the email address.
*/
function helfi_platform_config_update_9303(): void {
$query = \Drupal::entityQuery('user');
$usersIds = $query->accessCheck(FALSE)
->condition('status', 1)
->condition('roles', ['read_only'])
->execute();
if (!$usersIds) {
return;
}
$userEntities = User::loadMultiple($usersIds);
foreach ($userEntities as $user) {
if (!$user->getEmail()) {
$randomString = substr(md5(rand()), 0, 6);
$email = "[email protected]";
$user->setEmail($email);
$user->save();
}
}
}
/**
* Include front page in custom simple_sitemap links.
*/
function helfi_platform_config_update_9304() : void {
if (!\Drupal::moduleHandler()->moduleExists('simple_sitemap')) {
return;
}
$config = \Drupal::configFactory()->getEditable('simple_sitemap.custom_links.default');
$links = $config->get('links') ?? [];
$links = array_filter($links, fn (array $link) => $link['path'] !== '/');
$links[] = ['path' => '/', 'priority' => '1.0', 'changefreq' => 'daily'];
$config->set('links', $links)
->save();
}
/**
* UHF-9761: Remove the user inquiry -popup that is no longer used.
*/
function helfi_platform_config_update_9306() : void {
$config_factory = Drupal::configFactory();
// Make sure the configuration is present.
if (!$config_factory->get('block.block.hdbt_subtheme_user_inquiry')->isNew()) {
// Remove the user inquiry block.
$config_factory->getEditable('block.block.hdbt_subtheme_user_inquiry')->delete();
}
}
/**
* UHF-9312: Remove config filter, prepare hal and rdf removal.
*/
function helfi_platform_config_update_9307() : void {
$module_installer = \Drupal::service('module_installer');
$environmentResolver = \Drupal::getContainer()->get('helfi_api_base.environment_resolver');
try {
$environmentResolver->getActiveEnvironment();
}
catch (\InvalidArgumentException) {
return;
}
// If config filter would be enabled for some reason.
// Prevents 'Currently using Missing or invalid module'.
$config = \Drupal::configFactory()->getEditable('core.extension');
$enabled_modules = $config->get('module') ?? [];
if (isset($enabled_modules['config_filter'])) {
unset($enabled_modules['config_filter']);
$config->set('module', $enabled_modules);
$config->save();
\Drupal::service('extension.list.module')->reset();
\Drupal::moduleHandler()->invokeAll('rebuild');
$module_installer->uninstall(['config_filter']);
}
// Disable hal & rdf modules.
foreach (['hal', 'rdf'] as $module_name) {
if (\Drupal::moduleHandler()->moduleExists($module_name)) {
$module_installer->uninstall([$module_name]);
}
}
}
/**
* UHF-10063: Enable help module to prevent errors during twig:compile.
*/
function helfi_platform_config_update_9308() : void {
$module_installer = \Drupal::service('module_installer');
// Enable help module.
if (!\Drupal::moduleHandler()->moduleExists('help')) {
$module_installer->install(['help']);
}
}
/**
* Rerun hal/rdf module disabling since the first one did not run.
*/
function helfi_platform_config_update_9309() {
helfi_platform_config_update_9307();
}
/**
* UHF-9708: Enable helfi_node_survey module.
*/
function helfi_platform_config_update_9310() : void {
$module_installer = \Drupal::service('module_installer');
// Enable helfi_node_survey module.
if (!\Drupal::moduleHandler()->moduleExists('helfi_node_survey')) {
$module_installer->install(['helfi_node_survey']);
}
}
/**
* UHF-9708: Fix "Mismatched entity and/or field definitions" for published_at.
*/
function helfi_platform_config_update_9311(): void {
if (!\Drupal::moduleHandler()->moduleExists('publication_date')) {
return;
}
$changeList = \Drupal::entityDefinitionUpdateManager()->getChangeList();
// Check if field storage definition for published_at is missing.
if (isset($changeList['node']['field_storage_definitions']['published_at'])) {
$entity_type = \Drupal::entityTypeManager()
->getStorage('node')
->getEntityType();
if ($field = publication_date_entity_base_field_info($entity_type)['published_at'] ?? NULL) {
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('published_at', 'node', 'publication_date', $field);
}
}
}
/**
* UHF-9708: Enable helfi_users module.
*/
function helfi_platform_config_update_9312() : void {
helfi_platform_config_remove_permissions_from_all_roles([
'delete user accounts',
]);
if (!\Drupal::moduleHandler()->moduleExists('helfi_users')) {
\Drupal::service('module_installer')->install(['helfi_users']);
}
}
/**
* UHF-10259: Enable helfi_paragraphs_curated_event_list module.
*/
function helfi_platform_config_update_9313() : void {
$module_installer = \Drupal::service('module_installer');
// Enable helfi_paragraphs_curated_event_list.
if (!\Drupal::moduleHandler()->moduleExists('helfi_paragraphs_curated_event_list')) {
$module_installer->install(['helfi_paragraphs_curated_event_list']);
}
}