Browse Source

Added new function islandora_copy_object() can copy existing/new fedora objects.

It's a bit leaky in that it makes assumptions about the members that will exist
on AbstractObjects, but we can't make cloning work at the moment as it doesn't
really work well with inheritance, every decendent would have to define __clone
functions properly and I figured a wrapper function like this would be easier
to support in the long term, until we make the movement to decorated objects.
pull/341/head
Nigel Banks 11 years ago
parent
commit
59f8744a43
  1. 57
      islandora.module

57
islandora.module

@ -951,6 +951,63 @@ function islandora_add_object(AbstractObject &$object) {
return $object->repository->ingestObject($object); return $object->repository->ingestObject($object);
} }
/**
* Creates a new object with the same properties as the old.
*
* @todo Make Tuque objects support cloneing.
*
* @param AbstractObject $object
* An existing or new Fedora Object.
*
* @return AbstractObject
* The new Fedora Object with properties identical to the object given. This
* returned object is not automatically ingested.
*/
function islandora_copy_object(AbstractObject $object) {
$clone = $object->repository->constructObject($object->id);
$object_properties = array(
'state',
'createdDate',
'lastModifiedDate',
'label',
'owner',
'logMessage',
);
// Copy Properties.
foreach ($object_properties as $property) {
if (isset($object->$property)) {
$clone->$property = $object->$property;
}
}
$datastream_properties = array(
'label',
'versionable',
'state',
'mimetype',
'format',
'size',
'checksum',
'checksumType',
'createdDate',
'content',
'url',
'location',
);
// Copy Datastreams.
foreach ($object as $dsid => $datastream) {
if (empty($clone[$dsid])) {
$ds = $clone->constructDatastream($dsid, $datastream->controlGroup);
$clone->ingestDatastream($ds);
}
foreach ($datastream_properties as $property) {
if (isset($object[$dsid]->$property)) {
$clone[$dsid]->$property = $object[$dsid]->$property;
}
}
}
return $clone;
}
/** /**
* Delete's or purges the given object. * Delete's or purges the given object.
* *

Loading…
Cancel
Save