-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopenfed.install
374 lines (325 loc) · 12.2 KB
/
openfed.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
/**
* @file
* Install, uninstall and update hooks for Openfed.
*/
/**
* Implements hook_requirements().
*/
function openfed_requirements($phase) {
$return = [];
$moduleHandler = \Drupal::service('module_handler');
switch ($phase) {
case 'update':
// If this is an update from 8.x-8.x we must be sure this is using at
// least 8.x-8.7. This is a requirement for a smooth update of
// taxonomy_access_fix so we check its update hooks.
if ($moduleHandler->moduleExists('taxonomy_access_fix')) {
$taxonomy_access_fix_schema = drupal_get_installed_schema_version('taxonomy_access_fix');
$openfed_schema = drupal_get_installed_schema_version('openfed');
if (version_compare($openfed_schema, 8800, '<=') && version_compare($taxonomy_access_fix_schema, 8201, '<=')) {
$return['openfed_update_check'] = [
'title' => t('Openfed: Update Check'),
'severity' => REQUIREMENT_ERROR,
'value' => t('Taxonomy Access fix is enabled and you are trying to update Openfed from a version older than 8.x-8.7. This is not supported, please update to Openfed 8.x-8.7 first.'),
];
}
}
break;
case 'runtime':
// Scheduled updates: check if this is enable. If so, we should throw an error
// because this module is not well maintained and supported.
if ($moduleHandler->moduleExists('scheduled_updates')) {
$return['openfed_scheduled_updated_check'] = [
'title' => t('Openfed: Scheduled Updates'),
'severity' => REQUIREMENT_ERROR,
'value' => t('Scheduled Updates is enabled but not supported so it will be removed before Openfed9. Use Scheduler instead.'),
];
}
// Sharemessage: check if this is enable. If so, we should throw an error
// because this won't be supported by Openfed anymore.
if ($moduleHandler->moduleExists('sharemessage')) {
$return['openfed_sharemessage_check'] = [
'title' => t('Openfed: Share Message'),
'severity' => REQUIREMENT_ERROR,
'value' => t('Share Message is enabled but not supported so it will be removed before Openfed9. Use Openfed Social instead.'),
];
}
break;
}
return $return;
}
/**
* Implements hook_update_dependencies().
*/
function openfed_update_dependencies() {
$dependencies = [];
if (\Drupal::moduleHandler()->moduleExists('media_entity')) {
// Ensure that media_entity_update_8201() runs before openfed_update_8601().
$dependencies['openfed'][8601] = [
'media_entity' => 8201,
];
// Ensure that openfed_update_8602() and openfed_update_8603() runs before
// media_entity_update_8201().
$dependencies['media_entity'][8201] = [
'openfed' => 8603,
];
}
return $dependencies;
}
/**
* Removed in Openfed 8.x-5.0.
*
* Formely fixed the problem with file_entity module when upgrading from 8.3.x
* to 8.4.x.
*
* @deprecated
*/
function openfed_update_8201(&$sandbox) {
}
/**
* Removed in Openfed 8.x-5.0.
*
* Formely updated file entity configuration with a new generic file entity.
* Read more: http://drupal.org/node/2927468.
*
* @deprecated
*/
function openfed_update_8202(&$sandbox) {
}
/**
* Removed in Openfed 8.x-5.0.
*
* Formely updated default config due to the new Openfed SVG File field.
*
* @deprecated
*/
function openfed_update_8203(&$sandbox) {
}
/**
* Removed in Openfed 8.x-5.0.
*
* Formely fixed entity.definitions.bundle_field_map key store with old bundles.
*
* @deprecated
*/
function openfed_update_8401(&$sandbox) {
}
/**
* Formely updated configs related to core.base_field_override.media.* with the
* new default_value_callback when upgrading from 8.5.x to 8.6.x, since media
* is now part of the core.
*/
function openfed_update_8601(&$sandbox) {
$message = '';
// Gets the Config Factory service.
$config_factory = \Drupal::configFactory();
// Gets the list of media entity bundles.
/** @var \Drupal\Core\Entity\EntityTypeBundleInfo $media_bundles_info */
$media_bundles_info = \Drupal::service('entity_type.bundle.info')
->getBundleInfo('media');
// Make sure there are media bundles.
if (!empty($media_bundles_info)) {
foreach (array_keys($media_bundles_info) as $bundle_name) {
// Make sure the configuration exists.
if (in_array("core.base_field_override.media.{$bundle_name}.uid", $config_factory->listAll("core.base_field_override.media"))) {
// Gets the editable configuration.
$config = $config_factory->getEditable("core.base_field_override.media.{$bundle_name}.uid");
// Sets the new default_value_callback method.
$config->set('default_value_callback', 'Drupal\media\Entity\Media::getCurrentUserId');
// Saves the configuration.
$config->save(TRUE);
$message .= "Config of $bundle_name was updated.\n";
}
}
}
return $message;
}
/**
* This update will make sure that media_entity_document is uninstalled before
* starting media updates.
*/
function openfed_update_8602(&$sandbox) {
$message = '';
$uninstall_status = \Drupal::service('module_installer')
->uninstall(['media_entity_document']);
if ($uninstall_status) {
$message .= 'Media Entity Document was uninstalled successfully';
}
else {
\Drupal::database()->delete('key_value')
->condition('collection', 'system.schema')
->condition('name', 'media_entity_document')
->execute();
$message .= 'Media Entity Document was removed.';
}
return $message;
}
/**
* This update will make sure that media_entity_image is uninstalled before
* starting media updates.
*/
function openfed_update_8603(&$sandbox) {
$message = '';
$uninstall_status = \Drupal::service('module_installer')
->uninstall(['media_entity_image']);
if ($uninstall_status) {
$message .= 'Media Entity Image was uninstalled successfully';
}
else {
\Drupal::database()->delete('key_value')
->condition('collection', 'system.schema')
->condition('name', 'media_entity_image')
->execute();
$message .= 'Media Entity Image was removed.';
}
return $message;
}
/**
* Update menu_block configs due to patch update.
*/
function openfed_update_8701() {
// Update used to change the config created with a previous patch. This new
// config is still not in a stable release but it was already commited to
// menu_block dev branch.
if (\Drupal::moduleHandler()->moduleExists('menu_block')) {
$config_factory = \Drupal::configFactory();
$count_custom_trails = 0;
// This piece will work for block configs.
foreach ($config_factory->listAll('block.block.') as $block_config_name) {
$block = $config_factory->getEditable($block_config_name);
// Check if this is a menu_block.
$plugin = $block->get('plugin');
if (strpos($plugin, 'menu_block:') === 0) {
// Do the updates.
$settings = $block->get('settings');
// The following code will update from the old settings, provided by a
// previous patch, to new settings matching the latest dev version.
if (strpos($settings['parent'], 'active_trail_custom')) {
// This is a fallback since the new patch doesn't really have this option.
$settings['parent'] = str_replace('active_trail_custom', '', $settings['parent']);
$settings['expand'] = 0;
$settings['follow'] = 0;
$settings['follow_parent'] = 'child'; // this is not important
$count_custom_trails++;
unset($settings['custom_level']);
}
else {
if (strpos($settings['parent'], 'active_trail_parent')) {
$settings['parent'] = str_replace('active_trail', '', $settings['parent']);
$settings['follow'] = 1;
$settings['follow_parent'] = 'child';
}
else {
if (strpos($settings['parent'], 'active_trail')) {
$settings['parent'] = str_replace('active_trail', '', $settings['parent']);
$settings['follow'] = 1;
$settings['follow_parent'] = 'active';
}
}
}
unset($settings['custom_level']);
unset($settings['hide_children']);
unset($settings['expand_only_active_trails']);
$block->set('settings', $settings);
// Mark the resulting configuration as trusted data. This avoids issues with
// future schema changes.
$block->save(TRUE);
}
}
// This piece will work for page_variants.
// This piece will work for block configs.
foreach ($config_factory->listAll('page_manager.page_variant.') as $variant_config_name) {
$variant = $config_factory->getEditable($variant_config_name);
// Check if this is a menu_block.
$variant_settings = $variant->get('variant_settings');
if (isset($variant_settings['blocks'])) {
foreach ($variant_settings['blocks'] as &$panel_block) {
if ($panel_block['provider'] == 'menu_block') {
// The following code will update from the old settings, provided by
// a previous patch, to new settings matching the latest dev
// version.
if (strpos($panel_block['parent'], 'active_trail_custom')) {
// This is a fallback since the new patch doesn't really have this option.
$panel_block['parent'] = str_replace('active_trail_custom', '', $panel_block['parent']);
$panel_block['expand'] = 0;
$panel_block['follow'] = 0;
$panel_block['follow_parent'] = 'child'; // this is not important
$count_custom_trails++;
unset($panel_block['custom_level']);
}
else {
if (strpos($panel_block['parent'], 'active_trail_parent')) {
$panel_block['parent'] = str_replace('active_trail_parent', '', $panel_block['parent']);
$panel_block['follow'] = 1;
$panel_block['follow_parent'] = 'child';
}
else {
if (strpos($panel_block['parent'], 'active_trail')) {
$panel_block['parent'] = str_replace('active_trail', '', $panel_block['parent']);
$panel_block['follow'] = 1;
$panel_block['follow_parent'] = 'active';
}
}
}
unset($panel_block['custom_level']);
unset($panel_block['hide_children']);
unset($panel_block['expand_only_active_trails']);
}
}
$variant->set('variant_settings', $variant_settings);
// Mark the resulting configuration as trusted data. This avoids issues
// with future schema changes.
$variant->save(TRUE);
}
}
$message = t('Block settings updated.');
if ($count_custom_trails > 0) {
$message .= ' ' . t('There were :count custom active trails updated.', [':count' => $count_custom_trails]);
}
return $message;
}
return t('Menu Block is not installed.');
}
/**
* This update will make sure that media_entity is uninstalled, avoiding errors
* on some installations.
*/
function openfed_update_8702(&$sandbox) {
$message = '';
$uninstall_status = \Drupal::service('module_installer')
->uninstall(['media_entity']);
if ($uninstall_status) {
$message .= 'Media Entity was uninstalled successfully';
}
else {
\Drupal::database()->delete('key_value')
->condition('collection', 'system.schema')
->condition('name', 'media_entity')
->execute();
$message .= 'Media Entity was removed.';
}
return $message;
}
/**
* This update will update pathauto settings, adding missing safe token.
*/
function openfed_update_8800(&$sandbox) {
$message = '';
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('pathauto.settings');
$safe_tokens = $config->get('safe_tokens');
if (!in_array('node:field_menulink:join-parents-path', $safe_tokens)) {
$config->set('safe_tokens', array_merge($safe_tokens, ['node:field_menulink:join-parents-path']))
->save(TRUE);
$message .= 'Pathauto safe tokens updated.';
}
return $message;
}
/**
* This update will force the use of Openfed8 9.11 before updating to Openfed8
* 10.0.
*/
function openfed_update_8900() {
return t('You can now update to Openfed 8.x-10.0.');
}