Created
October 17, 2017 12:59
-
-
Save br2490/5402df2a095f7ee9b58ff7a412dcdbdc to your computer and use it in GitHub Desktop.
Update Islandora Compound Objects Relationships
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requires devel (doesn't need to be enabled). | |
// Head to https://<host.domain.tld>/devel/php to EXECUTE THIS LIVE. | |
// Just want to see the data this will spit out? Comment out lines | |
// starting with "$res" and "$res2" which are the only calls making actual modification. | |
$pid = 'BC15-14:852'; // This is your compound object's PID. | |
$compound = islandora_compound_object_get_parts($pid); | |
if (empty($compound)) { | |
// Not Compound. | |
return FALSE; | |
} | |
$parent = array_shift($compound); | |
if (!$parent = islandora_object_load($parent)) { | |
// Couldn't load Object. | |
return FALSE; | |
} | |
if (empty($compound)) { | |
// No Children. | |
return FALSE; | |
} | |
$new_collection = $parent->id; | |
$old_collection = $parent->getParents(); | |
$old_collection = array_shift($old_collection); | |
dpm($old_collection, 'old collection'); | |
dpm($new_collection, 'new collection target'); | |
foreach($compound as $child) { | |
if (!$child = islandora_object_load($child)) { | |
// Couldn't load Object. | |
return FALSE; | |
} | |
dpm($child->getParents(), "{$child->id} before"); | |
// Remove the old relationship. | |
$res = $child->relationships->remove(FEDORA_RELS_EXT_URI, 'isMemberOf', $old_collection); | |
// Add the correct relationship. | |
$res2 = $child->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOf', $new_collection); | |
dpm($child->getParents(), "{$child->id} after (rem: $res & add: $res2)"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment