-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregenFITSdata.php
121 lines (100 loc) · 3.82 KB
/
regenFITSdata.php
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
#!/usr/bin/env drush
#<?php
/**
* This script is intended to force the regeneration of FITS
* metadata for all items in the given collection
*
* Usage: pass the name of the collection to the script as the first argument
*
* Example: drush php-script regentFITSdata.php collection_name
*
* @author Paul Church
* @date June 2014
*/
# grab the first user supplied parameter as the name of the collection
$collection = drush_shift();
if (!$collection) {
drush_print("***Error: please provide the name of the collection as the first argument");
drush_print("Example: drush php-script regenFITSdata.php islandora:collection_name_here");
return;
}
# include all Tuque php files
$tuquePath = libraries_get_path('tuque') . '/*.php';
foreach ( glob($tuquePath) as $filename) {
require_once($filename);
}
# Include the file from islandora_fits module that regens the FITS data for us
require_once('/var/www/drupal/htdocs/sites/all/modules/islandora_fits/includes/derivatives.inc');
# repository connection parameters
$url = 'localhost:8080/fedora';
$username = 'fedoraAdmin';
$password = 'fedoraAdmin';
# set up connection and repository variables
$connection = new RepositoryConnection($url, $username, $password);
$api = new FedoraApi($connection);
$repository = new FedoraRepository($api, new SimpleCache());
# query to grab all pdf collection objects from the repository
$sparqlQuery = "SELECT ?s
FROM <#ri>
WHERE {
?s <info:fedora/fedora-system:def/relations-external#isMemberOfCollection>
<info:fedora/$collection> .
}";
# run query
drush_print("\nQuerying repository for all PDF objects...");
$allPDFObjects = $repository->ri->sparqlQuery($sparqlQuery);
drush_print("Query complete\n");
// check number of objects in the collection to make sure we have some
$totalNumObjects = count($allPDFObjects);
if ($totalNumObjects <= 0) {
drush_print("***Error: no objects found in the given collection. Check the collection name.");
drush_print("***No processing was completed. Exiting.");
return;
}
else {
drush_print("There are $totalNumObjects objects to be processed");
}
// establish a counter for how many objects we edit
$objectsChanged = 0;
drush_print("\nBeginning main processing loop\n");
for ($counter = 0; $counter < $totalNumObjects; $counter++) {
// grab the next object from the result set
$theObject = $allPDFObjects[$counter];
// increment the counter shown to the user
$realCount = $counter + 1;
drush_print("Processing record $realCount of $totalNumObjects");
// grab the PID value from the object array
$objectPID = $theObject['s']['value'];
# try to fetch PID from repo
try {
$object = $repository->getObject($objectPID);
}
catch (Exception $e) {
drush_print("\n\n**********####### ERROR #######*********");
drush_print("***Could not get object $objectPID from repo***\n\n");
continue;
}
// forces generation/regeneration of FITS data
$forceGeneration = TRUE;
// the magic call?
$result = islandora_fits_create_techmd($object, $forceGeneration, array(
'source_dsid' => 'OBJ',
'destination_dsid' => 'TECHMD',
'weight' => '0',
'function' => array(
'islandora_fits_create_techmd',
),
'file' => drupal_get_path('module', 'islandora_fits') . '/includes/derivatives.inc',
));
// check to make sure the result was successful as reported by the function
if ($result['success'] == 1) {
$objectsChanged++;
}
else {
print("\n\n**ERROR generating FITS data for $objectPID\n");
print_r($result);
}
}
drush_print("Main processing loop complete");
drush_print("$objectsChanged out of $totalNumObjects objects were updated");
echo "\n\nAll operations complete\n";