-
Notifications
You must be signed in to change notification settings - Fork 2
/
islandora_rdm.install
executable file
·109 lines (102 loc) · 2.69 KB
/
islandora_rdm.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* @file
* To test the services that Islandora uses.
*/
use Drupal\Core\Site\Settings;
use Drupal\field\Entity\FieldConfig;
use Drupal\taxonomy\Entity\Term;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
/**
* Implements hook_requirements().
*/
function islandora_rdm_requirements($phase) {
$requirements = [];
if ($phase == 'runtime') {
$requirements += check_fedora_service();
$requirements += check_bigdata_service();
}
return $requirements;
}
/**
* A function to check the Fedora service.
*/
function check_fedora_service() {
$array = [];
$message = "";
$settings_flysystem = settings::get('flysystem', '');
$fedora_server_URL = $settings_flysystem['fedora']['config']['root'];
// Make an HTTP request; Get the client service class.
$client = \Drupal::httpClient();
try {
$request = $client->get($fedora_server_URL);
$message = "Working well";
$array = [
'fedora_server_check' => [
'title' => t('Fedora Server'),
'value' => $message,
'severity' => REQUIREMENT_OK,
],
];
}
catch (ClientException $e1) {
$e_response = (string) $e1->getCode();
if ($e_response == "404") {
$message = "Server not found";
$array = [
'fedora_server_check' => [
'title' => t('Fedora Server'),
'value' => $message,
'description' => $e1->getMessage(),
'severity' => REQUIREMENT_ERROR,
],
];
}
}
catch (ConnectException $e2) {
$message = "Connection refused";
$array = [
'fedora_server_check' => [
'title' => t('Fedora Server'),
'value' => $message,
'description' => $e2->getMessage(),
'severity' => REQUIREMENT_ERROR,
],
];
}
return $array;
}
/**
* A function to check the big data query service.
*/
function check_bigdata_service() {
$array = [];
try {
$all_count = 'SELECT (COUNT(?s) AS ?triples) WHERE { ?s ?p ?o }';
$sparql_service = \Drupal::service('islandora_rdm.sparqlqueryrunner');
// Get count of all triples.
$results = $sparql_service->getQueryResults($all_count);
$message = $results[0]->triples->value;
$array = [
'bigdata_check' => [
'title' => t('Big Data'),
'value' => 'COUNT Query returned ' . $message . ' results',
'severity' => REQUIREMENT_OK,
],
];
return $array;
}
catch (RequestException $e3) {
$array = [
'bigdata_check' => [
'title' => t('Big Data'),
'value' => 'Unavailable',
'description' => $e3->getMessage(),
'severity' => REQUIREMENT_ERROR,
],
];
return $array;
}
}