-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathislandora_newspaper_batch.drush.inc
157 lines (147 loc) · 6.64 KB
/
islandora_newspaper_batch.drush.inc
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
<?php
/**
* @file
* Implementation of Drush hooks.
*/
/**
* Implements hook_drush_command().
*/
function islandora_newspaper_batch_drush_command() {
$items = array();
$items['islandora_newspaper_batch_preprocess'] = array(
'aliases' => array('inbp'),
'description' => 'Preprocessed newspaper issues into database entries.',
'drupal dependencies' => array('islandora_batch',
'islandora_newspaper',
'islandora_newspaper_batch',
),
'options' => array(
'type' => array(
'description' => 'Either "directory" or "zip".',
'required' => TRUE,
),
'namespace' => array(
'description' => 'The namespace for objects created by this command. Defaults to namespace set in Fedora config.',
'required' => FALSE,
),
'content_models' => array(
'description' => 'A comma-separated list of content models to assign to the objects. Only applies to the "newspaper issue" level object.',
'value' => 'optional',
),
'parent' => array(
'description' => 'The newspaper object to which the generated items should be added. Only applies to the "newspaper issue" level object. If "directory" and the directory containing the newspaper issue description is a valid PID, it will be set as the parent. If this is specified and itself is a PID, all newspapers issue will be related to the given PID.',
'required' => TRUE,
),
'parent_relationship_uri' => array(
'description' => 'The namespace URI of the relationship to the parent. Defaults to "info:fedora/fedora-system:def/relations-external#".',
'value' => 'optional',
),
'parent_relationship_pred' => array(
'description' => 'The predicate of the relationship to the parent. Defaults to "isMemberOf".',
'value' => 'optional',
),
'create_pdfs' => array(
'description' => 'A flag to cause PDFs to be created in newspaper issues. Page PDF creation is dependant on the configuration within Drupal proper.',
'value' => 'optional',
),
'do_not_generate_ocr' => array(
'description' => 'A flag to disallow conditional OCR generation.',
'value' => 'optional',
),
'do_not_generate_hocr' => array(
'description' => 'A flag to disallow conditional HOCR generation.',
'value' => 'optional',
),
'aggregate_ocr' => array(
'description' => 'A flag to cause OCR to be aggregated to issues, if OCR is also being generated per-page.',
'value' => 'optional',
),
'email_admin' => array(
'description' => 'A flag to notify the site admin when the newspaper issue is fully ingested (depends on Rules being enabled).',
'value' => 'optional',
),
'wait_for_metadata' => array(
'description' => 'A flag to indicate that we should hold off on trying to ingest newspaper issues until we have metadata available for them at the newspaper issue level.',
'value' => 'optional',
),
'directory_dedup' => array(
'description' => 'A flag to indicate that we should avoid repreprocessing newspaper issues which are located in directories.',
),
'output_set_id' => array(
'description' => 'A flag to indicate whether to print the set ID of the preprocessed newspaper issues.',
'value' => 'optional',
),
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_LOGIN,
);
// XXX: The target parameter became reserved in Drush 7 and above, for
// backwards compatibility both will be supported. Not using
// strict-option-handling (http://www.drush.org/en/master/strict-options) as
// it requires manual argument parsing.
if (DRUSH_VERSION >= 7) {
$items['islandora_newspaper_batch_preprocess']['options']['scan_target'] = array(
'description' => 'The target to directory or zip file to scan.',
'required' => TRUE,
);
}
else {
$items['islandora_newspaper_batch_preprocess']['options']['target'] = array(
'description' => 'The target to directory or zip file to scan.',
'required' => TRUE,
);
}
return $items;
}
/**
* Implements hook_drush_command().
*/
function drush_islandora_newspaper_batch_preprocess() {
// XXX: Due to how Drush bootstrapping works, the connection may be created
// without credentials (when your site's front page is
// 'islandora/object/some:object', for example). Resetting to ensure a new
// connection gets created should fix it.
drupal_static_reset('islandora_get_tuque_connection');
$connection = islandora_get_tuque_connection();
$parameters = array(
'type' => drush_get_option('type'),
'namespace' => drush_get_option('namespace'),
'target' => DRUSH_VERSION >= 7 ? drush_get_option('scan_target') : drush_get_option('target'),
'parent' => drush_get_option('parent', 'islandora:newspaperCollection'),
'parent_relationship_uri' => drush_get_option('parent_relationship_uri', 'info:fedora/fedora-system:def/relations-external#'),
'parent_relationship_pred' => drush_get_option('parent_relationship_pred', 'isMemberOf'),
'create_pdfs' => drush_get_option('create_pdfs', FALSE),
'aggregate_ocr' => drush_get_option('aggregate_ocr', FALSE),
'email_admin' => drush_get_option('email_admin', FALSE),
'wait_for_metadata' => drush_get_option('wait_for_metadata', FALSE),
'directory_dedup' => drush_get_option('directory_dedup', FALSE),
);
if ($content_models = drush_get_option('content_models', FALSE)) {
$parameters['content_models'] = explode(',', $content_models);
}
else {
$parameters['content_models'] = array('islandora:newspaperIssueCModel');
}
if (module_exists('islandora_ocr')) {
$parameters['generate_ocr'] = !((bool) drush_get_option('do_not_generate_ocr', FALSE));
$parameters['generate_hocr'] = !((bool) drush_get_option('do_not_generate_hocr', FALSE));
}
$preprocessor = new IslandoraNewspaperBatch($connection, $parameters);
// Pass the preprocessor off to run.
$preprocessed = islandora_batch_handle_preprocessor($preprocessor);
if (drush_get_option('output_set_id', FALSE)) {
drush_print($preprocessor->getSetId());
}
}
/**
* Parent validation.
*/
function drush_islandora_newspaper_batch_preprocess_validate() {
$parent = drush_get_option('parent');
$object = islandora_object_load($parent);
if (!$object) {
return drush_set_error('This is not a valid parent', dt('The specified parent (@parent) was unable to be loaded.', array('@parent' => $parent)));
}
if (!in_array('islandora:newspaperCModel', $object->models)) {
return drush_set_error('Not a newspaper object', dt('The specified parent (@parent) is not a newspaper object.', array('@parent' => $parent)));
}
}