-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathislandora_book_batch.drush.inc
127 lines (118 loc) · 4.77 KB
/
islandora_book_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
<?php
/**
* @file
* Implementation of Drush hooks.
*/
/**
* Implements hook_drush_command().
*/
function islandora_book_batch_drush_command() {
$items = array();
$items['islandora_book_batch_preprocess'] = array(
'aliases' => array('ibbp'),
'description' => 'Preprocessed books into database entries.',
'drupal dependencies' => array('islandora_batch',
'islandora_book',
'islandora_book_batch'),
'options' => array(
'type' => array(
'description' => 'Either "directory" or "zip".',
'required' => TRUE,
),
'target' => array(
'description' => 'The target to directory or zip file to scan.',
'required' => TRUE,
),
'namespace' => array(
'description' => 'The namespace for objects created by this command. Defaults to namespce 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 "book" level object.',
'value' => 'optional',
),
'parent' => array(
'description' => 'The collection to which the generated items should ' .
'be added. Only applies to the "book" level object. If ' .
'"directory" and the directory containing the book description is ' .
'a valid PID, it will be set as the parent. If this is specified ' .
'and itself is a PID, all books will be related to the given PID.',
'value' => 'optional',
),
'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 "isMemberOfCollection".',
'value' => 'optional',
),
'create_pdfs' => array(
'description' => 'A flag to cause PDFs to be created in books. Page PDF creation is dependant on the configuration within Drupal proper.',
'value' => 'optional',
),
'do_not_generate_ocr' => array(
'description' => 'A flag to allow for conditional OCR generation.',
'value' => 'optional',
),
'email_admin' => array(
'description' => 'A flag to notify the site admin when the book 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 books until we have metadata available for them' .
'at the book level.',
'value' => 'optional',
),
'directory_dedup' => array(
'description' => 'A flag to indicate that we should avoid ' .
'repreprocessing books which are located in directories.',
),
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_LOGIN,
);
return $items;
}
/**
* Implements hook_drush_command().
*/
function drush_islandora_book_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_get_option('target'),
'parent' => drush_get_option('parent', 'islandora:bookCollection'),
'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', 'isMemberOfCollection'),
'create_pdfs' => drush_get_option('create_pdfs', 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:bookCModel');
}
if ($do_not_generate = drush_get_option('do_not_generate_ocr', FALSE)) {
$parameters['generate_ocr'] = FALSE;
}
else {
$parameters['generate_ocr'] = TRUE;
}
$preprocessor = new IslandoraBookBatch($connection, $parameters);
// Pass the preprocessor off to run.
$preprocessed = islandora_batch_handle_preprocessor($preprocessor);
}