-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_checksum_audit.module
143 lines (125 loc) · 4.45 KB
/
islandora_checksum_audit.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
<?php
/**
* @file
* The Islandora Checksum Audit module file.
*/
/**
* Implements hook_menu().
*/
function islandora_checksum_audit_menu() {
$items = array();
$items['islandora/object/%islandora_object/manage/checksum_audit_details/%'] = array(
'title callback' => 'islandora_checksum_audit_details_title',
'title arguments' => array(2, 5),
'page callback' => 'islandora_checksum_audit_details',
'access arguments' => array(ISLANDORA_METADATA_EDIT),
'type' => MENU_NORMAL_ITEM,
'page arguments' => array(2, 5),
);
return $items;
}
/**
* Implements hook_admin_paths_alter().
*/
function islandora_checksum_audit_admin_paths_alter(&$paths) {
$paths['islandora/object/%islandora_object/manage/checksum_audit_details/%'] = TRUE;
}
/**
* Page callback.
*
* @param AbstractObject $islandora_object
* The Islandora object.
* @param string $dsid
* The datastream ID.
*
* @return string
* The overlay page content.
*/
function islandora_checksum_audit_details(AbstractObject $islandora_object, $dsid) {
$dsid = trim($dsid);
module_load_include('inc', 'islandora_checksum_audit', 'includes/utilities');
$foxml = islandora_checksum_audit_get_foxml($islandora_object->id);
$fixity_checks = islandora_checksum_audit_get_fixity_checks($foxml);
$header = array(
'audit_id' => t('Audit record ID'),
'date' => t('Date'),
'event' => t('Event'),
);
if (isset($fixity_checks[$dsid]['valid'])) {
$valid_subset = $fixity_checks[$dsid]['valid'];
$valid_rows = array();
foreach ($valid_subset as $valid_id => $valid_details) {
$valid_rows[] = array(
'audit_id' => $valid_id,
'date' => $valid_details['date'],
'event' => $valid_details['event'],
);
}
}
if (isset($fixity_checks[$dsid]['invalid'])) {
$invalid_subset = $fixity_checks[$dsid]['invalid'];
$invalid_rows = array();
foreach ($invalid_subset as $invalid_id => $invalid_details) {
$invalid_rows[] = array(
'audit_id' => $invalid_id,
'date' => $invalid_details['date'],
'event' => $invalid_details['event'],
);
}
}
$output = '';
if (isset($fixity_checks[$dsid]['valid'])) {
$output .= '<h4>' . t('Successful validation events') . '</h4>';
$output .= theme('table', array('header' => $header, 'rows' => $valid_rows));
}
if (isset($fixity_checks[$dsid]['invalid'])) {
$output .= '<h4>' . t('Failed validation events') . '</h4>';
$output .= theme('table', array('header' => $header, 'rows' => $invalid_rows));
}
return $output;
}
/**
* Page title callback function.
*/
function islandora_checksum_audit_details_title(AbstractObject $islandora_object, $dsid) {
return t('Checksum events for @pid / @dsid', array('@pid' => $islandora_object->id, '@dsid' => $dsid));
}
/**
* Theme preprocess function.
*/
function islandora_checksum_audit_preprocess_islandora_default_edit(&$variables) {
module_load_include('inc', 'islandora_checksum_audit', 'includes/utilities');
$variables['datastream_table']['header'][] = array('data' => t('Checksum audit'));
$islandora_object = $variables['islandora_object'];
$rows = $variables['datastream_table']['rows'];
$foxml = islandora_checksum_audit_get_foxml($islandora_object->id);
$fixity_checks = islandora_checksum_audit_get_fixity_checks($foxml);
foreach ($islandora_object as $ds) {
$data = '';
if (isset($fixity_checks[$ds->id])) {
if (isset($fixity_checks[$ds->id]['valid'])) {
$num_valid_fixity_checks = count($fixity_checks[$ds->id]['valid']);
$link = l(t('events'), 'islandora/object/' . $islandora_object->id . '/manage/checksum_audit_details/' . $ds->id);
$data = '<img src="/misc/watchdog-ok.png" /> (' . $num_valid_fixity_checks . ' ' . $link . ')';
}
if (isset($fixity_checks[$ds->id]['invalid'])) {
$num_invalid_fixity_checks = count($fixity_checks[$ds->id]['invalid']);
$link = l(t('events'), 'islandora/object/' . $islandora_object->id . '/manage/checksum_audit_details/' . $ds->id);
$data .= '<br /><img src="/misc/watchdog-warning.png" /> (' . $num_invalid_fixity_checks . ' ' . $link . ')';
}
}
else {
$num_fixity_checks = 0;
$data = '';
}
$checksum_data = array(
'class' => 'datastream-checksum-audit',
'data' => $data,
);
$checksums[] = $checksum_data;
}
for ($i = 0; $i < count($rows); $i++) {
$rows[$i][] = $checksums[$i];
}
$variables['datastream_table']['rows'] = $rows;
}