Browse Source

Fix errors being reported during purge relationships

If the RELS-{IN,EX}T file didn't exist, we would encounter errors.  Now, we
check that there's an actual file there before attempting to act on it.
pull/161/head
Adam Vessey 12 years ago
parent
commit
24ffc477ec
  1. 19
      api/fedora_item.inc

19
api/fedora_item.inc

@ -389,17 +389,18 @@ RDF;
* Whether or not this operation has produced any changes in the RELS-EXT
*/
function purge_relationships($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = FALSE) {
$relsext = $this->get_datastream_dissemination('RELS-EXT');
$relsext = trim($this->get_datastream_dissemination('RELS-EXT'));
$relsextxml = new DomDocument();
$relsextxml->loadXML($relsext);
$relsextxml = new DOMDocument();
$modified = FALSE;
if ($relsext && $relsextxml->loadXML($relsext)) {
$rels = $relsextxml->getElementsByTagNameNS($namespaceURI, $relationship);
if (!empty($rels)) {
// iterate backwards so if we delete something our pointer doesn't get out of sync
for ($i = $rels->length; $i > 0; $i--) {
$rel = $rels->item($i - 1);
// foreach ($rels as $rel) { // moving forward like this caused iteration errors when something was deleted
// foreach ($rels as $rel) { // moving forward like this caused iteration errors when something was deleted
if (//If either no object is specified, or the object matches (in either the literal or URI case), remove this node from it's parent, and mark as changed.
empty($object) ||
(($literal_value == RELS_TYPE_URI) && $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) ||
@ -416,7 +417,7 @@ RDF;
if ($modified) {
$this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml');
}
}
//Return whether or not we've introduced any changes.
return $modified;
}
@ -433,11 +434,11 @@ RDF;
$dsid = $f_prefix . $this->pid . '/' . $dsid;
}
$relsint = $this->get_datastream_dissemination('RELS-INT');
$relsxml = new DOMDocument();
$relsxml->loadXML($relsint);
$relsint = trim($this->get_datastream_dissemination('RELS-INT'));
$modified = FALSE;
if ($relsint && $relsxml->loadXML($relsint)) {
$descs = $relsxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description');
$description = NULL;
@ -467,11 +468,11 @@ RDF;
}
}
//Save changes.
if ($modified) {
$this->modify_datastream($relsxml->saveXML(), 'RELS-INT', "Fedora Datastream Relationship Metadata", 'text/xml');
}
}
//Return whether or not we've introduced any changes.
return $modified;

Loading…
Cancel
Save