forked from mjordan/islandora_bagger_integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_bagger_integration.install
151 lines (144 loc) · 5.08 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?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,
];
}
}
}
elseif ($phase == 'update') {
if (!\Drupal::moduleHandler()->moduleExists('getjwtonlogin')) {
$requirements['islandora_bagger_integration_getjwtonlogin_enabled'] = [
'title' => t("Islandora Bagger Integration"),
'description' => t("Islandora Bagger now requires the <a href=\"https://drupal.org/project/getjwtonlogin\">Get JWT on Login</a> module."),
'severity' => REQUIREMENT_ERROR,
];
}
}
return $requirements;
}
/**
* Implements hook_schema().
*/
function islandora_bagger_integration_schema() {
$schema = [];
$schema['islandora_bagger_integration_bag_log'] = [
'description' => 'Records Bags generated by Islandora Bagger.',
'fields' => [
'id' => [
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary key.',
],
'nid' => [
'description' => 'The ID of the node the Bag was created for.',
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
],
'ip_address' => [
'description' => 'The IP address of the harvester.',
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
],
'created' => [
'description' => 'A timestamp indicating when the record was created.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'user' => [
'description' => 'The user ID from the Bagger config file.',
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
],
'bag_name' => [
'description' => 'The name of the Bag.',
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
],
'hash_algorithm' => [
'description' => 'The hash algorithm used to create the Bag.',
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
],
'bagit_version' => [
'description' => 'The Bagit version number.',
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
],
'bag_info' => [
'description' => 'The contents of the bag_info.txt file.',
'type' => 'text',
'not null' => TRUE,
],
'manifest' => [
'description' => 'The contents of the manifest file corresponding to the hash_algorithm.',
'type' => 'text',
'not null' => TRUE,
],
'fetch' => [
'description' => 'The contents of the fetch.txt file.',
'type' => 'text',
'not null' => TRUE,
],
],
'primary key' => ['id'],
];
return $schema;
}