Browse Source

Merge branch '7.x' of git://github.com/Islandora/islandora into 7.x

pull/353/head
Nelson Hart 11 years ago
parent
commit
93b06432f1
  1. 28
      includes/content_model.autocomplete.inc
  2. 12
      includes/utilities.inc
  3. 44
      islandora.module

28
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. * Gets a map of form names suitable for use as select #options.
*/ */
function islandora_get_content_model_names() { 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(); $ret = array();
foreach ($results as $result) { foreach ($results as $result) {
$ret[$result['model']['value']] = "{$result['label']['value']} ({$result['model']['value']})"; $ret[$result['pid']] = "{$result['label']} ({$result['pid']})";
} }
return $ret; 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 <fedora-model:hasModel> <info:fedora/fedora-system:ContentModel-3.0> and $model <fedora-model:label> $label
minus $model <mulgara:is><info:fedora/fedora-system:FedoraObject-3.0>
minus $model <mulgara:is><info:fedora/fedora-system:ContentModel-3.0>
minus $model <mulgara:is><info:fedora/fedora-system:ServiceDefinition-3.0>
minus $model <mulgara:is><info:fedora/fedora-system:ServiceDeployment-3.0>';
$results = $connection->repository->ri->itqlQuery($query);
return $results;
}
return array();
}
/** /**
* Minor array transformation. * Minor array transformation.
* *

12
includes/utilities.inc

@ -256,8 +256,8 @@ function islandora_get_namespace($id) {
*/ */
function islandora_namespace_accessible($id) { function islandora_namespace_accessible($id) {
if (variable_get('islandora_namespace_restriction_enforced', FALSE)) { if (variable_get('islandora_namespace_restriction_enforced', FALSE)) {
$namespace = islandora_get_namespace($id) . ':'; $namespace = islandora_get_namespace($id);
$allowed_namespaces = explode(" ", variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); $allowed_namespaces = islandora_get_allowed_namespaces();
return in_array($namespace, $allowed_namespaces); return in_array($namespace, $allowed_namespaces);
} }
return TRUE; return TRUE;
@ -712,7 +712,13 @@ function islandora_get_allowed_namespaces() {
$matches = array(); $matches = array();
$allowed_namespaces = variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora:'); $allowed_namespaces = variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora:');
preg_match_all('/([A-Za-z0-9-\.]+):/', $allowed_namespaces, $matches); 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;
} }
/** /**

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