Browse Source

Updated the wildcard load functions

Updated the wildcard load functions to work more like core drupal does, reversing some previous changes.
pull/203/head
jonathangreen 12 years ago
parent
commit
cf1beabd5c
  1. 19
      includes/IslandoraTuque.inc
  2. 38
      includes/globals.inc
  3. 2
      includes/solution_packs.inc
  4. 84
      islandora.module

19
includes/IslandoraTuque.inc

@ -74,3 +74,22 @@ class IslandoraTuque {
drupal_set_message(filter_xss($message), 'error', FALSE);
}
}
/**
* Just a wrapper around fetchings the IslandoraTuque object, with some very
* basic error logging.
*
* @return IslandoraTuque
* A IslandoraTuque instance
*/
function islandora_get_tuque_connection() {
$tuque = &drupal_static(__FUNCTION__);
if (!$tuque) {
try {
$tuque = new IslandoraTuque();
} catch (Exception $e) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error');
}
}
return $tuque;
}

38
includes/globals.inc

@ -26,40 +26,6 @@ function islandora_get_tuque_connection() {
return $tuque;
}
/**
* Gets the given object if found, NULL if it is inaccessible and FALSE if it
* was not found.
*
* @param string $object_id
* The identifier of the object to get.
*
* @return FedoraObject
* The object if found, NULL if it is inaccessible and FALSE if it was not
* found.
*/
function islandora_get_object_by_id($object_id) {
$tuque = islandora_get_tuque_connection();
if ($tuque) {
try {
$object = $tuque->repository->getObject($object_id);
drupal_alter('islandora_object', $object);
return $object;
} catch (Exception $e) {
if ($e->getCode() == '404') {
return FALSE;
}
else {
return NULL;
}
}
}
else {
IslandoraTuque::getError();
}
// Assuming access denied in all other cases for now.
return NULL;
}
/**
* Ingest the given object into Fedora calling its pre/post hooks as well.
*
@ -274,7 +240,7 @@ function islandora_get_parents_from_rels_ext(FedoraObject $object) {
// @todo some logging would be nice, not sure what this throws.
return array();
}
$collections = array_map(function($o) { return islandora_get_object_by_id($o['object']['value']); }, $collections);
$collections = array_map(function($o) { return islandora_object_load($o['object']['value']); }, $collections);
return array_filter($collections);
}
@ -338,7 +304,7 @@ function islandora_get_datastreams_requirements(FedoraObject $object) {
function islandora_get_datastreams_requirements_from_models(array $models) {
$dsids = array();
foreach ($models as $model) {
$model = islandora_get_object_by_id($model);
$model = islandora_object_load($model);
$dsids += islandora_get_datastreams_requirements_from_content_model($model);
}
// The AUDIT Datastream can not really be added, so it can't really be missing.

2
includes/solution_packs.inc

@ -226,7 +226,7 @@ function islandora_batch_reingest_object($object_model, &$context) {
$object_query = $connection->api->a->findObjects('query', 'pid=' . $pid);
$reinstall = FALSE;
if (!empty($object_query['results'])) {
$object = islandora_get_object_by_id($pid);
$object = islandora_object_load($pid);
if (isset($object)) {
islandora_delete_object($object);
}

84
islandora.module

@ -160,7 +160,7 @@ function islandora_menu() {
'file' => 'includes/datastream.inc',
'access callback' => 'islandora_object_datastream_access_callback',
'access arguments' => array(FEDORA_VIEW, 2, 4),
'load arguments' => array('%map'),
'load arguments' => array(2),
);
$items['islandora/object/%islandora_object/datastream/%islandora_datastream/view'] = array(
'title' => 'View datastream',
@ -174,7 +174,7 @@ function islandora_menu() {
'file' => 'includes/datastream.inc',
'access callback' => 'islandora_object_datastream_access_callback',
'access arguments' => array(FEDORA_VIEW, 2, 4),
'load arguments' => array('%map'),
'load arguments' => array(2),
);
$items['islandora/object/%islandora_object/datastream/%islandora_datastream/edit'] = array(
'title' => 'Edit datastream',
@ -184,7 +184,7 @@ function islandora_menu() {
'file' => 'includes/datastream.inc',
'access callback' => 'islandora_object_datastream_access_callback',
'access arguments' => array(FEDORA_METADATA_EDIT, 2, 4),
'load arguments' => array('%map'),
'load arguments' => array(2),
);
$items['islandora/object/%islandora_object/datastream/%islandora_datastream/delete'] = array(
'title' => 'Delete data stream',
@ -194,7 +194,7 @@ function islandora_menu() {
'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_datastream_access_callback',
'access arguments' => array(FEDORA_PURGE, 2, 4),
'load arguments' => array('%map'),
'load arguments' => array(2),
);
$items['islandora/ingest'] = array(
'title' => 'Add an Object',
@ -459,21 +459,6 @@ function islandora_default_islandora_view_object($object) {
* A helper function to get a connection and return an object for objects
* specified in the menu path as '%islandora_object'.
*
* This should only be used by the Drupal menu wildcard system!
*
* When this function returns FALSE the Drupal menu system will issues a
* "page not found" error, when this function returns NULL, the access function
* is expected to check for the given object and return false generating a
* "accesss denied" error.
*
* This will currently display a message if the repository is inaccessable,
* ideally this would redirect to another page in such a case,
* as the access function will not be aware of this fact and will trigger
* the display of the "access denied" page.
*
* @todo When the repository down this should return a 500 error or a
* site offline notice. Currently only displays a message.
*
* @param string $object_id
* The pid of an object in the menu path identified by '%islandora_object'.
*
@ -487,34 +472,32 @@ function islandora_default_islandora_view_object($object) {
* drupal_access_denied().
*/
function islandora_object_load($object_id) {
static $object = NULL, $load_failed = FALSE; // Assume inaccessible.
if ($load_failed || isset($object)) {
return $object;
}
$object = islandora_get_object_by_id($object_id); // Either NULL or FALSE.
if (!isset($object)) {
module_load_include('inc', 'islandora', 'includes/utilities');
if (islandora_describe_repository() === FALSE) {
drupal_set_message(t('The repository is not availible please contact the administrator.'), 'error');
$tuque = islandora_get_tuque_connection();
if ($tuque) {
try {
$object = $tuque->repository->getObject($object_id);
drupal_alter('islandora_object', $object);
return $object;
} catch (Exception $e) {
if ($e->getCode() == '404') {
return FALSE;
}
else {
return NULL;
}
}
$load_failed = TRUE;
}
return $object;
else {
IslandoraTuque::getError();
}
// Assuming access denied in all other cases for now.
return NULL;
}
/**
* A helper function to get an datastream specified as '%islandora_datastream'
* for the object specified in the menu path as '%islandora_object'.
*
* This should only be used by the Drupal menu wildcard system!
*
* The following settings are required for any menu paths which intent to use
* this auto loader.
*
* @code
* 'load arguments' => array('%map'),
* @endcode
*
* Its up to the access callbacks and menu callbacks to trigger
* drupal_access_denied() when appropriate.
*
@ -522,24 +505,21 @@ function islandora_object_load($object_id) {
* The dsid of the datastream specified as '%islandora_datastream' to fetch
* from the given object in the menu path identified by '%islandora_object'.
*
* $param string $object_id
* The object to load the datastream from.
*
* @return FedoraDatastream
* If the given datastream ID exists then this returns a FedoraDatastream
* object, otherwise it returns NULL which triggers drupal_page_not_found().
*/
function islandora_datastream_load($datastream_id, $map) {
static $datastream = NULL, $load_failed = FALSE;
if ($load_failed || isset($datastream)) {
return $datastream;
}
foreach ($map as $element) {
$is_fedora_object = is_object($element) && strtolower(get_class($element)) == 'fedoraobject';
if ($is_fedora_object && isset($element[$datastream_id])) {
$datastream = $element[$datastream_id];
return $datastream;
}
function islandora_datastream_load($datastream_id, $object_id) {
$object = islandora_object_load($object_id);
if(!$object) {
return NULL;
}
$load_failed = TRUE;
return $datastream;
return $object[$datastream_id];
}
/**

Loading…
Cancel
Save