-
Notifications
You must be signed in to change notification settings - Fork 0
/
arangodb.install
56 lines (48 loc) · 1.63 KB
/
arangodb.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
<?php
/**
* @file
* Install/uninstall hooks.
*/
declare(strict_types = 1);
use ArangoDBClient\CollectionHandler as ArangoDbCollectionHandler;
use Drupal\arangodb\Utils;
use Drupal\Core\Cache\Cache;
/**
* Implements hook_requirements().
*
* @phpstan-param drupal-core-requirements-phase $phase
*
* @phpstan-return array<string, drupal-core-requirement>
*/
function arangodb_requirements($phase): array {
$return = [];
if ($phase === 'runtime') {
$binMapping = Utils::groupCacheBinsByConnections(Cache::getBins());
foreach ($binMapping as $connectionId => $info) {
/** @var \ArangoDBClient\Connection $connection */
$connection = $info['connection'];
$collectionHandler = new ArangoDbCollectionHandler($connection);
$uri = Utils::connectionUri($connection->getOptions());
$return["arangodb_connection_{$connectionId}"] = [
'severity' => REQUIREMENT_OK,
'title' => t('ArangoDB: Connection OK'),
'value' => $uri,
'description' => [
'#theme' => 'item_list',
'#title' => t('Affected cache bins'),
'#items' => $info['binNames'],
],
];
try {
// @todo May that collection is not exists yet.
$collectionHandler->count(reset($info['binNames']));
}
catch (\Throwable $exception) {
$return["arangodb_connection_{$connectionId}"]['severity'] = REQUIREMENT_ERROR;
$return["arangodb_connection_{$connectionId}"]['title'] = t('ArangoDB: Connection failed');
$return["arangodb_connection_{$connectionId}"]['value'] .= ' | ' . $exception->getMessage();
}
}
}
return $return;
}