-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscratch.php
61 lines (44 loc) · 1.45 KB
/
scratch.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
#!/usr/bin/env drush
#<?php
# include all Tuque php files
$tuquePath = libraries_get_path('tuque') . '/*.php';
foreach ( glob($tuquePath) as $filename) {
require_once($filename);
}
# 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());
$pid = 'islandora:3';
try {
$object = $repository->getObject($pid);
}
catch (Exception $e) {
drush_print("\n\n**********####### ERROR #######*********");
drush_print("***Could not get object $pid from repo***\n\n");
return;
}
$modsDatastream = islandora_datastream_load('MODS', $object);
// equivalent
$modsDatastream = $object['MODS'];
$modsxml = $modsDatastream->content;
// equivalent
$modsxml = $modsDatastream->getContent();
drush_print("******OLD XML*******\n");
drush_print($modsxml);
drush_print('*****END OLD XML*******');
return;
$mods = simplexml_load_string($modsxml);
drush_print($mods->name->namePart);
$mods->name->namePart = "Test Name";
$modsEdit = $mods->asXML();
drush_print("\n\n******NEW XML*******\n");
drush_print($modsEdit);
drush_print("*****END NEW XML*******\n");
# ingest new datastream into the repo
$modsDatastream->setContentFromString($modsEdit);
$object->ingestDatastream($modsDatastream);