-
Notifications
You must be signed in to change notification settings - Fork 0
/
bay_platform_dependencies.install
100 lines (88 loc) · 3.05 KB
/
bay_platform_dependencies.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
<?php
/**
* @file
* Install, update and uninstall functions for the bay-platform-dependencies module.
*/
use Drush\Drush;
/**
* Implements hook_install().
*/
function bay_platform_dependencies_install() {
\Drupal::messenger()->addStatus(__FUNCTION__);
}
/**
* Implements hook_uninstall().
*/
function bay_platform_dependencies_uninstall() {
\Drupal::messenger()->addStatus(__FUNCTION__);
}
/**
* Update section purger plugin to sectionbundled
*/
function bay_platform_dependencies_update_10001() {
$config_factory = \Drupal::configFactory();
// Update section purger plugin settings
$purge_plugins_config = $config_factory->getEditable('purge.plugins');
$purgers = $purge_plugins_config->get('purgers');
if (is_array($purgers)) {
foreach ($purgers as &$purger) {
// Only update plugin_id for section purger
if (isset($purger['plugin_id']) && $purger['plugin_id'] === "section") {
// Update the plugin_id to section bundled
$purger['plugin_id'] = 'sectionbundled';
$purge_plugins_config->set('purgers', $purgers);
$purge_plugins_config->save();
break;
}
}
}
// Update section purger logger channels settings
$purge_logger_channels_config = $config_factory->getEditable('purge.logger_channels');
$channels = $purge_logger_channels_config->get('channels');
if (is_array($channels)) {
foreach ($channels as &$channel) {
// Only update channel id for section purger
if (isset($channel['id']) && strpos($channel['id'], "purger_section_") === 0) {
// Update the id to section bundled
// channel id is in the format of purger_section_{purger_id}
$parts = explode('_', $channel['id']);
$purger_id = end($parts);
$channel['id'] = "purger_sectionbundled_{$purger_id}";
$purge_logger_channels_config->set('channels', $channels);
$purge_logger_channels_config->save();
break;
}
}
}
}
/**
* Enable section purge module with new name change.
*/
function bay_platform_dependencies_update_10002() {
// Update section purger plugin settings.
$source_config = \Drupal::config('section_purger.settings.8714ff77fc');
$source_config_values = $source_config->get();
// Check if module is both installed and enabled.
if (\Drupal::moduleHandler()->moduleExists('section_purger')) {
// If exists, uninstall module.
\Drupal::service('module_installer')->uninstall(['section_purger']);
}
// Replace 'section_purger' with 'section_purge'.
\Drupal::service('module_installer')->install(['section_purge']);
$config = \Drupal::configFactory()->getEditable('section_purge.settings.8714ff77fc');
$config->setData($source_config_values);
$config->save();
}
/**
* Enable bay_monitoring.
*/
function bay_platform_dependencies_update_10003() {
\Drupal::service('module_installer')->install(['bay_monitoring']);
}
/**
* Install the Section sensor.
*/
function bay_platform_dependencies_update_10004() {
$process = Drush::drush(Drush::aliasManager()->getSelf(), 'section_purger:install_sensor');
$process->run();
}