Repository navigation
Expand file tree
/
Copy pathdecionis.install
More file actions
95 lines (86 loc) · 3.03 KB
/
Copy pathdecionis.install
File metadata and controls
95 lines (86 loc) · 3.03 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
<?php
/**
* @file
* Install, update and requirements for Decionis.
*/
declare(strict_types=1);
use Drupal\decionis\Gate\Migration;
use Drupal\decionis\Connect\Migration as ConnectionMigration;
use Drupal\Core\Hook\Attribute\LegacyRequirementsHook;
use Drupal\decionis\Hook\CoreHooks;
use Drupal\decionis\Report\Environment;
use Drupal\decionis\Report\Severity;
/**
* Implements hook_install().
*/
function decionis_install(): void {
Migration::update();
}
/**
* Implements hook_requirements().
*
* Drupal 11.3+ skips this function: \Drupal\decionis\Install\Requirements\Checks
* and the requirements hooks on \Drupal\decionis\Hook\CoreHooks replace it.
*/
#[LegacyRequirementsHook]
function decionis_requirements(string $phase): array {
if ($phase === 'install') {
// The install phase runs before this module's namespace is registered.
if (!class_exists(Severity::class)) {
require_once __DIR__ . '/src/Report/Severity.php';
}
if (!class_exists(Environment::class)) {
require_once __DIR__ . '/src/Report/Environment.php';
}
return Environment::requirements();
}
$hooks = \Drupal::service(CoreHooks::class);
return $phase === 'runtime' ? $hooks->runtimeRequirements() : $hooks->updateRequirements();
}
/**
* Implements hook_uninstall().
*/
function decionis_uninstall(): void {
$state = \Drupal::state();
foreach (['decionis.entitlement', 'decionis.connect', 'decionis.connection', 'decionis.secret.decionis_api_key', 'decionis.secret.decionis_site_key', 'decionis.safe_mode', 'decionis.safe_mode_checked', 'decionis_commerce.policy', 'decionis_commerce.policy_pending'] as $key) {
$state->delete($key);
}
$store = \Drupal::keyValue('state');
// Drupal 10's key-value API has no keys-only enumeration method.
$keys = method_exists($store, 'getAllKeys') ? $store->getAllKeys() : array_keys($store->getAll());
$selections = [];
foreach ($keys as $key) {
if (is_string($key) && str_starts_with($key, 'decionis.enforcement.')) {
$selections[] = $key;
}
}
$state->deleteMultiple($selections);
$storage = \Drupal::entityTypeManager()->getStorage('key');
foreach (['decionis_api_key', 'decionis_site_key'] as $id) {
$storage->load($id)?->delete();
}
}
/**
* Installs the approval queue (decionis_hold).
*/
function decionis_update_10001(): string {
$manager = \Drupal::entityDefinitionUpdateManager();
if ($manager->getEntityType('decionis_hold') === NULL) {
$manager->installEntityType(\Drupal::entityTypeManager()->getDefinition('decionis_hold'));
return 'Installed the Decionis approval queue.';
}
return 'The Decionis approval queue was already installed.';
}
/**
* Installs deferred Shadow observations and replay identity constraints.
*/
function decionis_update_10002(): string {
Migration::update();
return 'Installed deferred Shadow observations and replay identity constraints.';
}
/**
* Preserves connection identity across imports and binds credentials to this site.
*/
function decionis_update_10003(): string {
return ConnectionMigration::run();
}