-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathislandora_dump_datastreams.module
115 lines (110 loc) · 4.82 KB
/
islandora_dump_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
<?php
/**
* @file
* Module file.
*/
/**
* Implements hook_menu().
*/
function islandora_dump_datastreams_menu() {
$items = array();
$items['admin/islandora/tools/dump_datastreams'] = array(
'title' => 'Islandora Dump Datastreams',
'description' => 'Configure the Islandora Dump Datastreams module.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_dump_datastreams_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Admin settings form builder.
*/
function islandora_dump_datastreams_admin_settings() {
$form['islandora_dump_datastreams_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable dumping of objects and their datastreams.'),
'#default_value' => variable_get('islandora_dump_datastreams_enable', 0),
'#description' => t('Only check this box if you want to dump objects
and datastreams, such as during batch ingests.'),
);
$form['islandora_dump_datastreams_log_dumps'] = array(
'#type' => 'checkbox',
'#title' => t('Log dumps to watchdog.'),
'#default_value' => variable_get('islandora_dump_datastreams_log_dumps', 0),
'#description' => t('Object PIDs will be logged, not datastream IDs.'),
);
$output_dir = variable_get('islandora_dump_datastreams_output_dir', '/tmp');
if (is_writable($output_dir)) {
$output_dir_message = '<br /><img src="' . url('misc/watchdog-ok.png') . '"/>' . t('Output directory @dir is ready.', array('@dir' => $output_dir));
}
else {
$output_dir_message = '<br /><img src="' . url('misc/watchdog-error.png') . '"/>' . t('Output directory @dir does not exist or is not writable by the web server.');
}
$form['islandora_dump_datastreams_output_dir'] = array(
'#title' => t('Output directory'),
'#type' => 'textfield',
'#size' => 100,
'#default_value' => variable_get('islandora_dump_datastreams_output_dir', '/tmp'),
'#description' => t("Absolute path to directory where objects will be dumped. Must exist. Note that object-level directories are given world-readable permissions. " . $output_dir_message),
'#maxlength' => 255,
);
$form['islandora_dump_datastreams_skip_dsids'] = array(
'#title' => t('DSIDs to exclude'),
'#type' => 'textfield',
'#size' => 100,
'#default_value' => variable_get('islandora_dump_datastreams_skip_dsids', 'RELS-EXT,RELS-INT,DC'),
'#description' => t("Comma-separated list of datastream IDs to not dump. You generally want to skip DC, RELS-EXT, and RELS-INT as they contain nonportable data (like PIDs)."),
'#maxlength' => 255,
);
module_load_include('inc', 'islandora_dump_datastreams', 'includes/utilities');
$cmodels = islandora_dump_datastreams_get_cmodels();
$form['islandora_dump_datastreams_cmodel'] = array(
'#type' => 'select',
'#title' => t('Curent content model'),
'#options' => $cmodels,
'#default_value' => variable_get('islandora_dump_datastreams_cmodel', ''),
'#description' => t('Select the content model that applies to objects you want to dump. You should change this to match the content model of the objects you are ingesting.'),
);
return system_settings_form($form);
}
/**
* Implements hook_islandora_object_ingested().
*/
function islandora_dump_datastreams_islandora_object_ingested(AbstractObject $object) {
if (!variable_get('islandora_dump_datastreams_enable', 0)) {
return;
}
if (!in_array(variable_get('islandora_dump_datastreams_cmodel', ''), $object->models)) {
return;
}
module_load_include('inc', 'islandora_dump_datastreams', 'includes/utilities');
switch (TRUE) {
case (in_array('islandora:newspaperIssueCModel', $object->models)):
case (in_array('islandora:bookCModel', $object->models)):
islandora_dump_datastreams_dump_paged_parent_object($object);
default:
// For single-file content models like basic image, PDF, etc.
islandora_dump_datastreams_dump_single($object);
}
}
/**
* Implements hook_islandora_datastream_ingested().
*/
function islandora_dump_datastreams_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) {
// We process book and newspaper page datastreams using their own function.
if (in_array('islandora:pageCModel', $object->models) ||
in_array('islandora:newspaperPageCModel', $object->models)) {
module_load_include('inc', 'islandora_dump_datastreams', 'includes/utilities');
islandora_dump_datastreams_dump_paged_children_datastream($object, $datastream);
}
if (!variable_get('islandora_dump_datastreams_enable', 0)) {
return;
}
if (!in_array(variable_get('islandora_dump_datastreams_cmodel', ''), $object->models)) {
return;
}
module_load_include('inc', 'islandora_dump_datastreams', 'includes/utilities');
islandora_dump_datastreams_dump_datastream($object, $datastream);
}