-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapc_storage.install
87 lines (73 loc) · 2.63 KB
/
apc_storage.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
<?php
/**
* @file
* Install, update, and uninstall hooks for the APC Storage module.
*/
declare(strict_types=1);
/**
* Implements hook_requirements().
*/
function apc_storage_requirements($phase): array {
// Ensure translations don't break at install time.
$t = get_t();
$requirements['apc_storage'] = array(
'title' => $t('APC Storage'),
);
if (extension_loaded('apcu')) {
$apcu_version = phpversion('apcu');
if ($apcu_version === FALSE) {
$severity = drupal_is_cli() ? REQUIREMENT_INFO : REQUIREMENT_ERROR;
$requirements['apc_storage']['description'] = $t(
'The APC Storage module requires the APCu extension.'
);
$requirements['apc_storage']['severity'] = $severity;
return $requirements;
}
$required_version_installed = version_compare($apcu_version, '5.1.17', '>=');
if (!$required_version_installed) {
$requirements['apc_storage']['description'] = $t(
'The APC Storage module requires the APCu extension version 5.1.17 or higher; version %apcu_version is currently installed.',
array('%apcu_version' => $apcu_version)
);
$requirements['apc_storage']['severity'] = REQUIREMENT_ERROR;
return $requirements;
}
if (apcu_enabled() && $phase == 'runtime') {
$cache = apcu_cache_info(TRUE);
$num_entries = $cache['num_entries'] ?? 0;
$start_time = $cache['start_time'] ?? time();
$mem_size = $cache['mem_size'] ?? 0;
$requirements['apc_storage']['description'] = $t(
'The APCu extension has been running for !duration. It contains !num_entries entries and uses !memory_size of memory.',
array(
'!duration' => format_interval(time() - $start_time),
'!num_entries' => $num_entries,
'!memory_size' => format_size($mem_size),
)
);
$requirements['apc_storage']['severity'] = REQUIREMENT_INFO;
}
elseif (!apcu_enabled()) {
$severity = drupal_is_cli() ? REQUIREMENT_INFO : REQUIREMENT_ERROR;
$requirements['apc_storage']['description'] = $t(
'The APC Storage module requires the APCu extension.'
);
$requirements['apc']['severity'] = $severity;
}
}
else {
$requirements['apc_storage']['description'] = $t(
'The APC Storage module requires the <a href="!apcu_link">APCu</a> extension.',
array('!apcu_link' => 'https://www.php.net/apcu')
);
$requirements['apc_storage']['severity'] = REQUIREMENT_ERROR;
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function apc_uninstall(): void {
ApcStorageCache::deleteAllStoredData();
ApcStorageLock::deleteAllStoredData();
}