From 59f8744a4317dbe4f7ce7cdecd209ea0f720e1f2 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Thu, 23 May 2013 05:03:23 +0200 Subject: [PATCH 1/4] 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. --- islandora.module | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/islandora.module b/islandora.module index 79672625..df17e65f 100644 --- a/islandora.module +++ b/islandora.module @@ -951,6 +951,63 @@ function islandora_add_object(AbstractObject &$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. * From 4c90c17e5acca701ff7bf711bf5abb4892409435 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Mon, 3 Jun 2013 16:01:56 +0200 Subject: [PATCH 2/4] Adam's recommendations. --- islandora.module | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/islandora.module b/islandora.module index df17e65f..5bf67aba 100644 --- a/islandora.module +++ b/islandora.module @@ -979,30 +979,17 @@ function islandora_copy_object(AbstractObject $object) { $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); + $clone->ingestDatastream($datastream); } - foreach ($datastream_properties as $property) { - if (isset($object[$dsid]->$property)) { - $clone[$dsid]->$property = $object[$dsid]->$property; - } + 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; From 277a109ebc31c2869b6d8700564feeac7d1ec11f Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 5 Jun 2013 12:23:46 -0300 Subject: [PATCH 3/4] Force islandora to be present in the allowed namespaces at all times. --- includes/utilities.inc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index cdbf8daa..32b05158 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -256,8 +256,8 @@ function islandora_get_namespace($id) { */ function islandora_namespace_accessible($id) { if (variable_get('islandora_namespace_restriction_enforced', FALSE)) { - $namespace = islandora_get_namespace($id) . ':'; - $allowed_namespaces = explode(" ", variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); + $namespace = islandora_get_namespace($id); + $allowed_namespaces = islandora_get_allowed_namespaces(); return in_array($namespace, $allowed_namespaces); } return TRUE; @@ -712,7 +712,13 @@ function islandora_get_allowed_namespaces() { $matches = array(); $allowed_namespaces = variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora:'); preg_match_all('/([A-Za-z0-9-\.]+):/', $allowed_namespaces, $matches); - return $matches[1]; + $accessible_namespaces = $matches[1]; + // Ensure that the "islandora" namespace is explicitly allowed + // no matter what happens. + if (!in_array('islandora', $accessible_namespaces)) { + $accessible_namespaces[] = 'islandora'; + } + return $accessible_namespaces; } /** From d04c00fd50a17deff314de48ac1fd23ecfde1c16 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Fri, 7 Jun 2013 10:29:07 -0300 Subject: [PATCH 4/4] Use the utility function as opposed to re-defining a query. --- includes/content_model.autocomplete.inc | 28 +++---------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/includes/content_model.autocomplete.inc b/includes/content_model.autocomplete.inc index c6fd34df..67923e9e 100644 --- a/includes/content_model.autocomplete.inc +++ b/includes/content_model.autocomplete.inc @@ -28,37 +28,15 @@ function islandora_content_model_autocomplete($string) { * Gets a map of form names suitable for use as select #options. */ function islandora_get_content_model_names() { - $results = islandora_query_content_models(); + module_load_include('inc', 'islandora', 'includes/utilities'); + $results = islandora_get_content_models(); $ret = array(); foreach ($results as $result) { - $ret[$result['model']['value']] = "{$result['label']['value']} ({$result['model']['value']})"; + $ret[$result['pid']] = "{$result['label']} ({$result['pid']})"; } return $ret; } -/** - * Perform a resource index query to determine get a list of content models. - * - * Only returns content models with at least one subscribing object. - * - * @return array - * An array of RI results, as given by the Tuque RI query interface. - */ -function islandora_query_content_models() { - $connection = islandora_get_tuque_connection(); - if ($connection) { - $query = 'select $model $label from <#ri> where - $model and $model $label - minus $model - minus $model - minus $model - minus $model '; - $results = $connection->repository->ri->itqlQuery($query); - return $results; - } - return array(); -} - /** * Minor array transformation. *