-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathislandora_check_datastreams.module
executable file
·264 lines (245 loc) · 9.85 KB
/
islandora_check_datastreams.module
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
/**
* @file
* islandora_check_datastreams
*
*
* Copyright 2017 Leiden University Library
*
* This file is part of islandora_check_datastreams.
*
* islandora_check_datastreams is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Permissions.
define('ISLANDORA_CHECK_DATASTREAMS_GENERATE', 'Generate missing datastreams');
define('ISLANDORA_CHECK_DATASTREAMS_CHILDREN', 'Check children of an object');
/**
* Implements hook_menu().
*/
function islandora_check_datastreams_menu() {
return array(
'admin/islandora/check_datastreams/object/%/datastream/%/generate' => array(
'title' => 'Generate missing datastream',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_check_datastreams_generate_form', 4, 6),
'file' => 'includes/admin.form.inc',
'access arguments' => array(ISLANDORA_CHECK_DATASTREAMS_GENERATE),
),
'admin/islandora/check_datastreams/object/%/datastream/%/regenerate' => array(
'title' => 'Regenerate datastream',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_check_datastreams_generate_form', 4, 6, TRUE),
'file' => 'includes/admin.form.inc',
'access arguments' => array(ISLANDORA_CHECK_DATASTREAMS_GENERATE),
),
'admin/islandora/check_datastreams/check_children' => array(
'title' => 'Check children of an object or batch',
'type' => MENU_SUGGESTED_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_check_datastreams_children_form'),
'file' => 'includes/admin.form.inc',
'access arguments' => array(ISLANDORA_CHECK_DATASTREAMS_CHILDREN),
),
'admin/islandora/check_datastreams/check_children/%/%' => array(
'title' => 'Check children of an object or batch',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_check_datastreams_children_form', 4, 5),
'file' => 'includes/admin.form.inc',
'access arguments' => array(ISLANDORA_CHECK_DATASTREAMS_CHILDREN),
),
'islandora_batch/reports/queue/%islandora_batch_set/check_datastreams' => array(
'title' => 'Check datastreams of batch',
'type' => MENU_LOCAL_ACTION,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'islandora_check_datastreams_children_form',
3,
'batch',
),
'file' => 'includes/admin.form.inc',
'access arguments' => array(ISLANDORA_CHECK_DATASTREAMS_CHILDREN),
),
'admin/reports/islandora_batch_queue/%islandora_batch_set/check_datastreams' => array(
'title' => 'Check datastreams of batch',
'type' => MENU_LOCAL_ACTION,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'islandora_check_datastreams_children_form',
3,
'batch',
),
'file' => 'includes/admin.form.inc',
'access arguments' => array(ISLANDORA_CHECK_DATASTREAMS_CHILDREN),
),
);
}
/**
* Implements hook_permission().
*/
function islandora_check_datastreams_permission() {
return array(
ISLANDORA_CHECK_DATASTREAMS_GENERATE => array(
'title' => t('Generate missing datastreams'),
'description' => t('Generate missing datastreams'),
),
ISLANDORA_CHECK_DATASTREAMS_CHILDREN => array(
'title' => t('Check children of an object'),
'description' => t('Check children of an object'),
),
);
}
/**
* Implements hook_theme_registry_alter().
*/
function islandora_check_datastreams_theme_registry_alter(&$theme_registry) {
$module_path = drupal_get_path('module', 'islandora_check_datastreams');
$templatepath = $module_path . '/theme';
$theme_registry['islandora_default_edit']['template'] = 'ubl-object-edit';
$theme_registry['islandora_default_edit']['path'] = $templatepath;
}
/**
* Implements hook_preprocess_theme().
*/
function islandora_check_datastreams_preprocess_islandora_default_edit(array &$variables) {
$islandora_object = $variables['islandora_object'];
$rows = array();
$info = islandora_check_datastreams_datastream_property_info($islandora_object, TRUE);
foreach ($info as $dsid => $dsinfo) {
if (!$dsinfo['available'] || (isset($dsinfo['include']) && $dsinfo['include'])) {
$row = array();
$row[] = array(
'class' => 'datastream-id',
'data' => $dsid,
);
$row[] = array(
'class' => 'datastream-required',
'data' => $dsinfo['required'] ? t('required') : t('optional'),
);
$remark = isset($dsinfo['remark']) ? $dsinfo['remark'] : ($dsinfo['required'] ? t('Missing required datastream') : t('-'));
$row[] = array(
'class' => 'datastream-remarks',
'data' => $remark,
);
$row[] = array(
'class' => 'datastream-operations',
'data' => ($dsinfo['generatable'] && isset($dsinfo['generatelink'])) ? $dsinfo['generatelink'] : '',
);
$rows[] = $row;
}
}
if (count($rows) > 0) {
$header = array();
$header[] = array('data' => t('ID'));
$header[] = array('data' => t('Required'));
$header[] = array('data' => t('Remarks'));
$header[] = array('data' => t('Operations'));
$caption = t('Missing datastreams and properties');
$table = array(
'colgroups' => NULL,
'sticky' => TRUE,
'empty' => 'Error loading datastreams',
'caption' => $caption,
'header' => $header,
'rows' => $rows,
'attributes' => array('class' => array('check-datastreams')),
);
$variables['check_ds_table'] = $table;
}
if (in_array('islandora:bookCModel', $islandora_object->models)) {
$variables['check_ds_children'] = l(t('Check the pages of this book'), 'admin/islandora/check_datastreams/check_children/' . $islandora_object->id . '/' . 'book');
}
elseif (in_array('islandora:collectionCModel', $islandora_object->models)) {
$variables['check_ds_children'] = l(t('Check the items of this collection'), 'admin/islandora/check_datastreams/check_children/' . $islandora_object->id . '/' . 'collection');
}
elseif (in_array('islandora:compoundCModel', $islandora_object->models)) {
$variables['check_ds_children'] = l(t('Check the items of this compound'), 'admin/islandora/check_datastreams/check_children/' . $islandora_object->id . '/' . 'compound');
}
elseif (in_array('islandora:newspaperCModel', $islandora_object->models)) {
$variables['check_ds_children'] = l(t('Check the issues of this newspaper'), 'admin/islandora/check_datastreams/check_children/' . $islandora_object->id . '/' . 'newspaper');
}
elseif (in_array('islandora:newspaperIssueCModel', $islandora_object->models)) {
$variables['check_ds_children'] = l(t('Check the pages of this issue'), 'admin/islandora/check_datastreams/check_children/' . $islandora_object->id . '/' . 'issue');
}
}
/**
* Implements hook_hook_info().
*/
function islandora_check_datastreams_hook_info() {
return array(
'check_datastreams_info' => array(
'group' => 'check_datastreams',
),
);
}
/**
* Helper function to retrieve the info for how to check datastreams.
*/
function islandora_check_datastreams_datastream_property_info($object) {
module_load_include('inc', 'islandora', 'includes/utilities');
static $cache = array();
if (!isset($cache[$object->id])) {
$output = array();
// Call hook check_datastreams_info.
$hooks = islandora_build_hook_list('check_datastreams_info', $object->models);
foreach ($hooks as $hook) {
$temp = module_invoke_all($hook, $object);
if (!empty($temp)) {
$output = array_merge_recursive($output, $temp);
}
}
// Setup the defaults.
foreach ($output as $dsid => $bydsid) {
foreach ($bydsid as $what => $result) {
if (is_array($result) && isset($result['function'])) {
$function = $result['function'];
if (isset($result['file'])) {
$file = $result['file'];
require_once $file;
}
if (function_exists($function)) {
$output[$dsid][$what] = call_user_func($function, $object, $dsid);
}
}
}
if (!isset($bydsid['available'])) {
$output[$dsid]['available'] = isset($object[$dsid]);
}
if (!isset($bydsid['required'])) {
$models = $object->models;
$dsreqs = islandora_get_datastreams_requirements_from_models($models);
$output[$dsid]['required'] = !(isset($dsreqs[$dsid]['optional']) && $dsreqs[$dsid]['optional']);
}
if (!isset($bydsid['generatable'])) {
$output[$dsid]['generatable'] = FALSE;
}
if (!isset($bydsid['generatelink'])) {
if (isset($output[$dsid]['regeneratable']) && $output[$dsid]['regeneratable']) {
$url = 'admin/islandora/check_datastreams/object/' . $object->id . '/datastream/' . $dsid . '/regenerate';
$output[$dsid]['generatelink'] = l(t('regenerate'), $url);
}
elseif ($output[$dsid]['generatable']) {
$url = 'admin/islandora/check_datastreams/object/' . $object->id . '/datastream/' . $dsid . '/generate';
$output[$dsid]['generatelink'] = l(t('generate'), $url);
}
}
}
// Call hook check_datastreams_info alter.
drupal_alter($hooks, $object, $output);
$cache[$object->id] = $output;
}
return $cache[$object->id];
}