forked from bibliotechy/islandora_checksum
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathislandora_checksum.drush.inc
70 lines (67 loc) · 2.31 KB
/
islandora_checksum.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
<?php
/**
* @file
* Drush command for enabling checksums.
*/
/**
* Implements hook_drush_command().
*/
function islandora_checksum_drush_command() {
return array(
'islandora-checksum-update-checksums' => array(
'aliases' => array('icuc'),
'description' => dt('Updates the checksumType setting for datastreams of objects in the given collection.'),
'drupal dependencies' => array(
'islandora_checksum',
),
'options' => array(
'collections' => array(
'description' => dt('A comma-separated list of collection PIDs to update checksums in.'),
'required' => TRUE,
),
'dsids' => array(
'description' => dt('A comma-separated list of DSIDs to update on the given collection. Omit to use the default configured ones.'),
'required' => FALSE,
),
'checksum' => array(
'description' => dt('The checksum configuration to apply to the datastreams found. Omit to use the default configured value. Valid options are DISABLED, MD5, SHA-1, SHA-256, SHA-384, and SHA-512.'),
'required' => FALSE,
),
'limit' => array(
'description' => dt('The number of checksums to apply in each iteration of the batches. Defaults to 10.'),
'required' => FALSE,
),
),
'examples' => array(
'Update basic image checksums to SHA-512' => 'drush islandora-checksum-update-checksums --collection=islandora:sp_basic_image_collection --checksum=SHA-512',
),
),
);
}
/**
* Sets the batch for updating checksums.
*/
function drush_islandora_checksum_update_checksums() {
$collection_pids = explode(',', trim(drush_get_option('collections')));
$dsids = drush_get_option('dsids', array());
if (!is_array($dsids)) {
$dsids = explode(',', trim($dsids));
}
$limit = drush_get_option('limit', 10);
$batch = FALSE;
foreach ($collection_pids as $collection_pid) {
$collection = islandora_object_load($collection_pid);
if (!$collection) {
drush_print(dt('No such collection !id; skipping ...', array(
'!id' => $collection_pid,
)));
}
else {
batch_set(islandora_checksum_get_collection_checksum_update_batch($collection_pid, $limit, $dsids));
$batch = TRUE;
}
}
if ($batch) {
drush_backend_batch_process();
}
}