-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrupal_cache_protection.install
More file actions
125 lines (116 loc) · 3.54 KB
/
Copy pathdrupal_cache_protection.install
File metadata and controls
125 lines (116 loc) · 3.54 KB
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
<?php
/**
* @file
* Install / update / requirements hooks for drupal_cache_protection.
*/
declare(strict_types=1);
/**
* Implements hook_install().
*
* Initializes the warmer subsystem: snapshot host capabilities, set the
* default strategy (post_response if prewarming is available, disabled
* otherwise), and clear any prior probe record. The survival probe
* itself runs asynchronously on the next cron tick.
*/
function drupal_cache_protection_install(): void {
\Drupal::service('drupal_cache_protection.warmer')->reset();
}
/**
* Implements hook_uninstall().
*/
function drupal_cache_protection_uninstall(): void {
$state = \Drupal::state();
$state->delete('drupal_cache_protection.warmer.strategy');
$state->delete('drupal_cache_protection.warmer.capabilities');
$state->delete('drupal_cache_protection.warmer.probe');
}
/**
* Implements hook_requirements().
*/
function drupal_cache_protection_requirements(string $phase): array {
if ($phase !== 'runtime') {
return [];
}
if (!\Drupal::hasService('drupal_cache_protection.warmer')) {
return [];
}
$requirements = \Drupal::service('drupal_cache_protection.warmer')->getRequirements();
$severityMap = [
'ok' => REQUIREMENT_OK,
'warning' => REQUIREMENT_WARNING,
'error' => REQUIREMENT_ERROR,
'info' => REQUIREMENT_INFO,
];
foreach ($requirements as &$req) {
if (isset($req['severity']) && is_string($req['severity'])) {
$req['severity'] = $severityMap[$req['severity']] ?? REQUIREMENT_INFO;
}
}
return $requirements;
}
/**
* Add UTM parameters to strip_params.
*/
function drupal_cache_protection_update_10001(): string {
$config = \Drupal::configFactory()->getEditable('drupal_cache_protection.settings');
$current = $config->get('strip_params') ?? [];
$additions = [
'utm_source',
'utm_medium',
'utm_campaign',
'utm_term',
'utm_content',
'utm_id',
];
$merged = array_values(array_unique(array_merge($current, $additions)));
if ($merged === $current) {
return 'UTM parameters already present in strip_params; no changes.';
}
$config->set('strip_params', $merged)->save();
return 'Added UTM parameters to strip_params.';
}
/**
* Add ttclid (TikTok click ID) to strip_params.
*/
function drupal_cache_protection_update_10002(): string {
$config = \Drupal::configFactory()->getEditable('drupal_cache_protection.settings');
$current = $config->get('strip_params') ?? [];
if (in_array('ttclid', $current, TRUE)) {
return 'ttclid already present in strip_params; no changes.';
}
$config->set('strip_params', array_merge($current, ['ttclid']))->save();
return 'Added ttclid to strip_params.';
}
/**
* Backfill HubSpot tracking params into strip_params.
*
* These shipped in the default config but never had an update hook, so sites
* installed before they were added are missing them.
*/
function drupal_cache_protection_update_10003(): string {
$config = \Drupal::configFactory()->getEditable('drupal_cache_protection.settings');
$current = $config->get('strip_params') ?? [];
$additions = [
'hsa_acc',
'hsa_cam',
'hsa_grp',
'hsa_ad',
'hsa_kw',
'hsa_mt',
'hsa_net',
'hsa_src',
'hsa_tgt',
'hsa_ver',
'_hsmi',
'_hsenc',
'__hstc',
'__hssc',
'__hsfp',
];
$merged = array_values(array_unique(array_merge($current, $additions)));
if ($merged === $current) {
return 'HubSpot parameters already present in strip_params; no changes.';
}
$config->set('strip_params', $merged)->save();
return 'Added HubSpot parameters to strip_params.';
}