Browse Source

Merge pull request #209 from nigelgbanks/7.x

Fix potential white screen problems with instantiating IslandoraTuque.
pull/210/head
Jonathan Green 12 years ago
parent
commit
74f1f13bb0
  1. 11
      admin/islandora.admin.inc
  2. 26
      includes/IslandoraTuque.inc
  3. 21
      includes/solution_packs.inc
  4. 18
      includes/utilities.inc
  5. 41
      islandora.module

11
admin/islandora.admin.inc

@ -16,11 +16,6 @@ function islandora_repository_admin($form, &$form_state) {
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
drupal_add_css(drupal_get_path('module', 'islandora') . '/css/islandora.admin.css'); drupal_add_css(drupal_get_path('module', 'islandora') . '/css/islandora.admin.css');
if (!IslandoraTuque::exists()) {
IslandoraTuque::getError();
return;
}
$form = array(); $form = array();
if (isset($form_state['values']['islandora_base_url'])) { if (isset($form_state['values']['islandora_base_url'])) {
$url = $form_state['values']['islandora_base_url']; $url = $form_state['values']['islandora_base_url'];
@ -29,7 +24,11 @@ function islandora_repository_admin($form, &$form_state) {
$url = variable_get('islandora_base_url', 'http://localhost:8080/fedora'); $url = variable_get('islandora_base_url', 'http://localhost:8080/fedora');
} }
$connection = new IslandoraTuque(NULL, $url); $connection = islandora_get_tuque_connection(NULL, $url);
if (!$connection) {
return;
}
try { try {
$info = $connection->api->a->describeRepository(); $info = $connection->api->a->describeRepository();
} }

26
includes/IslandoraTuque.inc

@ -78,6 +78,7 @@ class IslandoraTuque {
} }
if (self::exists()) { if (self::exists()) {
module_load_include('inc', 'islandora', 'includes/IslandoraTuqueWrapper');
$this->connection = new IslandoraRepositoryConnection($url, $user_string, $pass_string); $this->connection = new IslandoraRepositoryConnection($url, $user_string, $pass_string);
$this->connection->reuseConnection = TRUE; $this->connection->reuseConnection = TRUE;
$this->api = new IslandoraFedoraApi($this->connection); $this->api = new IslandoraFedoraApi($this->connection);
@ -97,28 +98,3 @@ class IslandoraTuque {
drupal_set_message(filter_xss($message), 'error', FALSE); 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) {
if (IslandoraTuque::exists()) {
require_once(__DIR__ . '/IslandoraTuqueWrapper.inc');
try {
$tuque = new IslandoraTuque();
} catch (Exception $e) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error');
}
}
else {
return NULL;
}
}
return $tuque;
}

21
includes/solution_packs.inc

@ -203,18 +203,11 @@ function islandora_solution_pack_form_submit($form, &$form_state) {
*/ */
function islandora_batch_reingest_object($object_model, &$context) { function islandora_batch_reingest_object($object_model, &$context) {
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
global $user;
global $base_url; global $base_url;
// new connection $connection = islandora_get_tuque_connection();
try { if (!$connection) {
$connection = new IslandoraTuque($user);
}
catch (Exception $e) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error');
return; return;
} }
if (!empty($object_model) && is_array($object_model)) { if (!empty($object_model) && is_array($object_model)) {
$pid = $object_model['pid']; $pid = $object_model['pid'];
if (!islandora_is_valid_pid($pid)) { if (!islandora_is_valid_pid($pid)) {
@ -293,15 +286,7 @@ function islandora_install_solution_pack($module_name = NULL, $op = 'install') {
return; return;
} }
// create new connection $connection = islandora_get_tuque_connection();
try {
$connection = new IslandoraTuque($user);
}
catch (Exception $e) {
drupal_set_message(st('Unable to connect to the repository %e', array('%e' => $e)), 'error');
return;
}
// get object models // get object models
$enabled_solution_packs = module_invoke_all('islandora_required_objects'); $enabled_solution_packs = module_invoke_all('islandora_required_objects');
$islandora_required_objects = $module_name . '_islandora_required_objects'; $islandora_required_objects = $module_name . '_islandora_required_objects';

18
includes/utilities.inc

@ -98,14 +98,17 @@ function islandora_is_valid_dsid($dsid) {
*/ */
function islandora_describe_repository($url = NULL) { function islandora_describe_repository($url = NULL) {
$url = isset($url) ? $url : variable_get('islandora_base_url', 'http://localhost:8080/fedora'); $url = isset($url) ? $url : variable_get('islandora_base_url', 'http://localhost:8080/fedora');
$connection = new IslandoraTuque(NULL, $url); $connection = islandora_get_tuque_connection();
try { if ($connection) {
$info = $connection->api->a->describeRepository(); try {
return $info; $info = $connection->api->a->describeRepository();
} return $info;
catch (RepositoryException $e) { }
return FALSE; catch (RepositoryException $e) {
return FALSE;
}
} }
return FALSE;
} }
/** /**
@ -375,7 +378,6 @@ function islandora_get_datastreams_requirements_from_content_model(FedoraObject
* An ingestable NewFedoraObject. * An ingestable NewFedoraObject.
*/ */
function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastreams = array(), $content_models = array(), $relationships = array()) { function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastreams = array(), $content_models = array(), $relationships = array()) {
module_load_include('inc', 'islandora', 'includes/IslandoraTuque');
global $user; global $user;
$tuque = islandora_get_tuque_connection(); $tuque = islandora_get_tuque_connection();
$object = isset($namespace) ? $tuque->repository->constructObject($namespace) : new NewFedoraObject(NULL, $tuque->repository); $object = isset($namespace) ? $tuque->repository->constructObject($namespace) : new NewFedoraObject(NULL, $tuque->repository);

41
islandora.module

@ -454,6 +454,31 @@ function islandora_default_islandora_view_object($object) {
return array('Default output' => $output); return array('Default output' => $output);
} }
/**
* Just a wrapper around fetchings the IslandoraTuque object, with some very
* basic error logging.
*
* @return IslandoraTuque
* A IslandoraTuque instance
*/
function islandora_get_tuque_connection($user = NULL, $url = NULL) {
module_load_include('inc', 'islandora', 'includes/IslandoraTuque');
$tuque = &drupal_static(__FUNCTION__);
if (!$tuque) {
if (IslandoraTuque::exists()) {
try {
$tuque = new IslandoraTuque($user, $url);
} catch (Exception $e) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error');
}
}
else {
return NULL;
}
}
return $tuque;
}
/** /**
* A helper function to get a connection and return an object for objects * A helper function to get a connection and return an object for objects
* specified in the menu path as '%islandora_object'. * specified in the menu path as '%islandora_object'.
@ -471,7 +496,6 @@ function islandora_default_islandora_view_object($object) {
* drupal_access_denied(). * drupal_access_denied().
*/ */
function islandora_object_load($object_id) { function islandora_object_load($object_id) {
module_load_include('inc', 'islandora', 'includes/IslandoraTuque');
$tuque = islandora_get_tuque_connection(); $tuque = islandora_get_tuque_connection();
if ($tuque) { if ($tuque) {
try { try {
@ -603,12 +627,21 @@ function islandora_islandora_undeletable_datastreams(array $models) {
* *
* @return FedoraObject * @return FedoraObject
* The ingested FedoraObject, after running the pre/post ingest hooks. * The ingested FedoraObject, after running the pre/post ingest hooks.
* Returns FALSE if the ingest failed.
*/ */
function islandora_add_object(NewFedoraObject &$object) { function islandora_add_object(NewFedoraObject &$object) {
islandora_pre_add_object($object); islandora_pre_add_object($object);
$object->repository->ingestObject($object); try {
islandora_post_add_object($object); $object->repository->ingestObject($object);
return $object; islandora_post_add_object($object);
return $object;
} catch (Exception $e) {
watchdog('islandora', 'Failed to ingest object: @pid</br>code: @code<br/>message: @msg', array(
'@pid' => $object->id,
'@code' => $e->getCode(),
'@msg' => $e->getMessage()), WATCHDOG_ERROR);
}
return FALSE;
} }
/** /**

Loading…
Cancel
Save