-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelfi_proxy.install
74 lines (65 loc) · 1.92 KB
/
helfi_proxy.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
<?php
/**
* @file
* Contains helfi_proxy installation procedure.
*/
declare(strict_types=1);
/**
* Implements hook_install().
*/
function helfi_proxy_install() {
\Drupal::service('module_installer')->install(['redirect']);
\Drupal::configFactory()
->getEditable('redirect.settings')
// Make sure route normalizer is enabled.
->set('route_normalizer_enabled', TRUE)
->save();
}
/**
* Enable and configure 'redirect' module.
*/
function helfi_proxy_update_9001() : void {
helfi_proxy_install();
}
/**
* Enable asset purge configuration.
*/
function helfi_proxy_update_9002() : void {
if (!\Drupal::moduleHandler()->moduleExists('varnish_purger')) {
return;
}
/** @var \Drupal\Core\Config\ConfigInstallerInterface $configInstaller */
$configInstaller = \Drupal::service('config.installer');
$configInstaller->installDefaultConfig('module', 'helfi_proxy');
// Re-installing the default configuration does not install purge
// configuration for some reason.
$plugins = \Drupal::configFactory()->getEditable('purge.plugins');
$purgers = $plugins->get('purgers');
if (!array_filter($purgers, fn (array $item) => $item['instance_id'] === 'assets')) {
$purgers[] = [
'instance_id' => 'assets',
'plugin_id' => 'varnish',
'order_index' => 4,
];
$plugins->set('purgers', $purgers)
->save();
}
$loggers = \Drupal::configFactory()->getEditable('purge.logger_channels');
$channels = $loggers->get('channels');
if (!array_filter($channels, fn (array $item) => $item['id'] === 'purger_varnish_assets')) {
$channels[] = [
'id' => 'purger_varnish_assets',
'grants' => [0, 2, 3],
];
}
$loggers->set('channels', $channels)
->save();
}
/**
* Remove unused 'robots_header_enabled' config.
*/
function helfi_proxy_update_9003() : void {
\Drupal::configFactory()->getEditable('helfi_proxy.settings')
->clear('robots_header_enabled')
->save();
}