-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_batch_modify.module
197 lines (182 loc) · 6.87 KB
/
islandora_batch_modify.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
<?php
/**
* @file
* Modify existing items in batch
*
*
* Copyright 2017 Leiden University Library
*
* This file is part of islandora_batch_modify.
*
* islandora_batch_modify 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_BATCH_MODIFY_FROM_ZIP', 'Batch Modify');
/**
* Implements hook_menu().
*/
function islandora_batch_modify_menu() {
return array(
'islandora_batch_modify' => array(
'title' => 'Batch Modify',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_batch_modify_import_form'),
'file' => 'includes/zip_import.form.inc',
'access arguments' => array(ISLANDORA_BATCH_MODIFY_FROM_ZIP),
),
);
}
/**
* Implements hook_permission().
*/
function islandora_batch_modify_permission() {
return array(
ISLANDORA_BATCH_MODIFY_FROM_ZIP => array(
'title' => t('Batch Modify'),
'description' => t('Modify items in batch from a CSV or ZIP file'),
),
);
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function islandora_batch_modify_form_system_modules_alter(&$form, &$form_state, $form_id) {
$form['modules']['Islandora Tools']['islandora_batch_modify']['links']['configure'] = array(
'#type' => 'link',
'#title' => t('Configure'),
'#href' => 'islandora_batch_modify',
'#options' => array(
'attributes' => array(
'class' => array('module-link', 'module-link-configure'),
'title' => t('Setup a batch modify of items'),
),
),
);
}
/**
* Implements hook_generate_extra_derivatives().
*/
function islandora_batch_modify_generate_extra_derivatives($object, $what, $options) {
if ($what === 'HDL') {
if (module_load_include('inc', 'islandora_handle', 'includes/derivatives') !== FALSE) {
$options += array('destination_dsid' => 'MODS');
$force = (isset($options['force']) && $options['force']);
if (function_exists('islandora_handle_append_handle_from_configuration')) {
$result = islandora_handle_append_handle_from_configuration($object, $force, $options);
}
elseif (function_exists('islandora_handle_append_handles_from_configuration')) {
$result = islandora_handle_append_handles_from_configuration($object, $force, $options);
}
if (isset($result['success'])) {
if ($result['success'] === TRUE) {
islandora_handle_add_to_dc_datastream($object);
}
}
return array($result);
}
}
}
/**
* Implements hook_generate_extra_derivatives().
*/
function islandora_batch_modify_islandora_pagecmodel_generate_extra_derivatives($object, $what, $options) {
return _islandora_batch_modify_pages_generate_extra_derivatives($object, $what, $options);
}
/**
* Implements hook_generate_extra_derivatives().
*/
function islandora_batch_modify_islandora_newspaperpagecmodel_generate_extra_derivatives($object, $what, $options) {
return _islandora_batch_modify_pages_generate_extra_derivatives($object, $what, $options);
}
/**
* Helper function to implement extra derivatives for pages.
*/
function _islandora_batch_modify_pages_generate_extra_derivatives($object, $what, $options) {
if ($what === 'DIMENSIONS') {
if ($object['JP2']) {
if (module_load_include('inc', 'islandora_paged_content', 'includes/utilities') !== FALSE) {
islandora_paged_content_add_dimensions_relationships($object, isset($options['force']) ? $options['force'] : FALSE);
return array(array('success' => TRUE, 'message' => t('Dimensions successfully generated.')));
}
}
}
elseif ($what === 'PDF') {
if (module_load_include('inc', 'islandora_paged_content', 'includes/utilities')) {
if (islandora_paged_content_page_derive_pdf_datastream($object, $options)) {
return array(array('success' => TRUE, 'message' => t('PDF successfully generated.')));
}
}
}
}
/**
* Implements hook_generate_extra_derivatives().
*/
function islandora_batch_modify_islandora_bookcmodel_generate_extra_derivatives($object, $what, $options) {
return _islandora_batch_modify_pdf_aggregate_pages($object, $what, $options);
}
/**
* Implements hook_generate_extra_derivatives().
*/
function islandora_batch_modify_islandora_newspaperissuecmodel_generate_extra_derivatives($object, $what, $options) {
return _islandora_batch_modify_pdf_aggregate_pages($object, $what, $options);
}
/**
* Helper function to aggregate pdf pages.
*/
function _islandora_batch_modify_pdf_aggregate_pages($object, $what, $options) {
if ($what === 'PDF') {
if (module_load_include('inc', 'islandora_paged_content', 'includes/utilities') && module_load_include('inc', 'islandora_paged_content', 'includes/batch')) {
$pageids = array_keys(islandora_paged_content_get_pages($object));
// Create and collect PDF's for pages.
$pdf_files = array();
foreach ($pageids as $pageid) {
$page = islandora_object_load($pageid);
if (isset($page['PDF'])) {
$pdf_file = drupal_realpath("temporary://{$page->id}_PDF.pdf");
if ($page['PDF']->getContent($pdf_file)) {
$pdf_files[] = $pdf_file;
}
}
else {
$pdf_file = islandora_paged_content_page_derive_pdf($page, $options);
if ($pdf_file) {
islandora_paged_content_update_datastream($page, $pdf_file, 'PDF');
$pdf_files[] = $pdf_file;
}
}
}
// Combine the page PDF's into one big PDF.
$pdf_file = drupal_realpath("temporary://{$object->id}_PDF.pdf");
islandora_paged_content_pdf_combine($pdf_files, $pdf_file);
islandora_paged_content_update_datastream($object, $pdf_file, 'PDF');
// Clean up temporary files.
file_unmanaged_delete($pdf_file);
foreach ($pdf_files as $pdf_file) {
file_unmanaged_delete($pdf_file);
}
return array(array('success' => TRUE, 'message' => t('PDF successfully generated.')));
}
}
}
/**
* Implements hook_generate_extra_derivatives().
*/
function islandora_batch_modify_islandora_compoundcmodel_generate_extra_derivatives($object, $what, $options) {
if ($what === 'TN') {
if (module_load_include('inc', 'islandora_compound_object', 'includes/derivatives')) {
return islandora_compound_object_create_thumbnail($object, isset($options['force']) ? $options['force'] : FALSE);
}
}
}