-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseadl_delete_bad_jp2.php
46 lines (40 loc) · 1.18 KB
/
seadl_delete_bad_jp2.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
#!/usr/bin/env drush
/*
Script to delete the bad jp2 datastreams.
4/15/2021
*/
<?php
$tuquePath = libraries_get_path('tuque') . '/*.php'; foreach ( glob($tuquePath) as $filename) {
require_once($filename);
}
$serializer = new FedoraApiSerializer();
$cache = new SimpleCache();
$connection = new RepositoryConnection('fedora_url', 'user', 'password');
$api = new FedoraApi($connection, $serializer);
$repository = new FedoraRepository($api, $cache);
$count = 1;
$csv = array_map('str_getcsv', file('/file/path/jp2_pids.csv'));
foreach ($csv as $row) {
$id = $row[0];
$file_name = $row[1];
$object = $repository->getObject($id);
if (!$object) {
drupal_set_message("Fedora Object isn't in the repo!");
} else {
foreach ($object as $datastream) {
if ($datastream->id == 'JP2') {
print $count . "\n";
$count += 1;
print "PID: " . $id;
print "\nDSID: " . $datastream->id;
print "\nLabel: " . $datastream->label;
print "\nMimetype: " . $datastream->mimetype;
print "\n\n";
$dsid = $datastream->id;
print "Deleting " . $id . " " . $dsid . " file\n\n";
$object->purgeDatastream($dsid);
}
}
}
}
?>