-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathislandora_compound_batch.drush.inc
137 lines (129 loc) · 5.87 KB
/
islandora_compound_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
<?php
/**
* @file
* Implementation of Drush hooks.
*/
/**
* Implements hook_drush_command().
*/
function islandora_compound_batch_drush_command() {
$items = array();
$items['islandora_compound_batch_preprocess'] = array(
'aliases' => array('icbp'),
'description' => 'Preprocess compound objects into database entries.',
/*'drupal dependencies' => array('islandora_batch', 'islandora_solution_pack_compound'),*/
'drupal dependencies' => array('islandora_batch'),
'examples' => array(
format_string('drush -v icbp --user=admin --content_models=islandora:sp_large_image_cmodel --namespace=yul --parent=yul:F0433 --@target=/tmp/batch_ingest/ --icbp_verbose=TRUE',
array(
'@target' => DRUSH_VERSION >= 7 ? 'scan_target' : 'target',
)),
),
'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' => 'Defines the (single) content model to apply to child data files that have a specific extension. Use format "ext::cmodel_pid.',
'value' => 'optional',
),
'parent' => array(
'description' => 'The collection to which the generated items should be added. If "directory" and the directory containing the object description is a valid PID, it will be set as the parent. If this is specified and itself is a PID, all compound objects will be related to the given PID.',
'required' => TRUE,
),
'icbp_verbose' => array(
'description' => 'Prints out additional information to the console if set to TRUE.',
'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 "isMemberOf".',
'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_compound_batch_preprocess']['options']['scan_target'] = array(
'description' => 'The target to directory or zip file to scan. Requires the full path to your archive from root directory. e.g. /var/www/drupal/sites/archive.zip',
'required' => TRUE,
);
}
else {
$items['islandora_compound_batch_preprocess']['options']['target'] = array(
'description' => 'The target to directory or zip file to scan. Requires the full path to your archive from root directory. e.g. /var/www/drupal/sites/archive.zip',
'required' => TRUE,
);
}
$items['islandora_compound_batch_prune_relationships'] = array(
'aliases' => array('icbpr'),
'description' => 'Removes rows from the islandora_compound_batch table that no longer have a batch associated with them.',
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_LOGIN,
);
return $items;
}
/**
* Implements hook_drush_command().
*/
function drush_islandora_compound_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:compoundCollection'),
'content_models' => drush_get_option('content_models'),
'icbp_verbose' => drush_get_option('icbp_verbose'),
'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'),
);
// Pass the preprocessor off to run.
$preprocessor = new IslandoraCompoundBatchPreprocessor($connection, $parameters);
$preprocessed = islandora_batch_handle_preprocessor($preprocessor);
drush_log(t("SetId: @s", array('@s' => $preprocessor->getSetId())), "ok");
}
/**
* Parent validation.
*/
function drush_islandora_compound_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:compoundCModel', $object->models)) {
return drush_set_error('Not a compound object',
dt('The specified parent (@parent) is not a compound object.',
array('@parent' => $parent)));
}*/
}
/**
* Implements hook_drush_command().
*/
function drush_islandora_compound_batch_prune_relationships() {
// Delete all the rows from {islandora_compound_batch} that do not have
// corresponding rows in {islandora_batch_set}.
$result = db_query("DELETE icb FROM {islandora_compound_batch} icb LEFT JOIN {islandora_batch_set} o ON icb.batch_id = o.id WHERE o.id IS NULL");
$num_deleted = $result->rowCount();
drush_log(t("Deleted @n rows from islandora_compound_batch", array('@n' => $num_deleted)), "ok");
}