forked from mjordan/islandora_bagger_integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislandora_bagger_integration.install
65 lines (60 loc) · 2.54 KB
/
islandora_bagger_integration.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
<?php
/**
* Implements hook_requirements().
*/
function islandora_bagger_integration_requirements($phase) {
$requirements = [];
if ($phase == 'runtime') {
$config = \Drupal::config('islandora_bagger_integration.settings');
$mode = $config->get('islandora_bagger_mode');
// If in remote mode, check whether Islandora Bagger's endpoint is available.
if ($mode == 'remote') {
$bagger_endpoint = $config->get('islandora_bagger_rest_endpoint');
$bagger_response_code = 0;
try {
$client = \Drupal::httpClient();
// Assumes Islandora Bagger requires no authentication (e.g., it's behind the Symfony or other firewall).
$response = $client->request('GET', $bagger_endpoint);
$bagger_response_code = $response->getStatusCode();
}
catch (Exception $e) {
\Drupal::logger('islandora_bagger_integration')->error($e->getMessage());
}
finally {
if ($bagger_response_code == 200) {
$requirements['islandora_bagger_integration_microservice_available'] = [
'title' => t("Islandora Bagger Integration"),
'description' => t("Islandora Bagger is running at @endpoint", array('@endpoint' => $bagger_endpoint)),
'severity' => REQUIREMENT_INFO,
];
}
else {
$requirements['islandora_bagger_integration_microservice_available'] = [
'title' => t("Islandora Bagger Integration"),
'description' => t("Islandora Bagger not found or is not running at @endpoint", array('@endpoint' => $bagger_endpoint)),
'severity' => REQUIREMENT_ERROR,
];
}
}
}
// If in local mode, check whether Islandora Bagger's installation directory exists.
if ($mode == 'local') {
$bagger_directory = $config->get('islandora_bagger_local_bagger_directory');
if (file_exists($bagger_directory)) {
$requirements['islandora_bagger_integration_directory_exists'] = [
'title' => t("Islandora Bagger Integration"),
'description' => t("Islandora Bagger is installed at @directory", array('@directory' => $bagger_directory)),
'severity' => REQUIREMENT_INFO,
];
}
else {
$requirements['islandora_bagger_integration_directory_exists'] = [
'title' => t("Islandora Bagger Integration"),
'description' => t("Islandora Bagger not installed at @directory", array('@directory' => $bagger_directory)),
'severity' => REQUIREMENT_ERROR,
];
}
}
}
return $requirements;
}