Browse Source

Merge pull request #341 from nigelgbanks/7.x-copy-objects

Added new function islandora_copy_object() can copy existing/new fedora objects.
pull/353/merge
Adam 12 years ago
parent
commit
63c3b7b27d
  1. 44
      islandora.module

44
islandora.module

@ -963,6 +963,50 @@ 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;
}
}
// Copy Datastreams.
foreach ($object as $dsid => $datastream) {
if (empty($clone[$dsid])) {
$clone->ingestDatastream($datastream);
}
else {
// Get the content into a file, and add the file.
$temp_file = drupal_tempnam('temporary://', 'datastream');
$datastream->getContent($temp_file);
$clone[$dsid]->setContentFromFile($temp_file);
drupal_unlink($temp_file);
}
}
return $clone;
}
/** /**
* Delete's or purges the given object. * Delete's or purges the given object.
* *

Loading…
Cancel
Save