Browse Source

Fix potential white screen problems with instantiating IslandoraTuque.

pull/209/head
Nigel Banks 12 years ago
parent
commit
b610533cbe
  1. 11
      admin/islandora.admin.inc
  2. 26
      includes/IslandoraTuque.inc
  3. 21
      includes/solution_packs.inc
  4. 6
      includes/utilities.inc
  5. 35
      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');
drupal_add_css(drupal_get_path('module', 'islandora') . '/css/islandora.admin.css');
if (!IslandoraTuque::exists()) {
IslandoraTuque::getError();
return;
}
$form = array();
if (isset($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');
}
$connection = new IslandoraTuque(NULL, $url);
$connection = islandora_get_tuque_connection();
if (!$connection) {
return;
}
try {
$info = $connection->api->a->describeRepository();
}

26
includes/IslandoraTuque.inc

@ -78,6 +78,7 @@ class IslandoraTuque {
}
if (self::exists()) {
module_load_include('inc', 'islandora', 'includes/IslandoraTuqueWrapper');
$this->connection = new IslandoraRepositoryConnection($url, $user_string, $pass_string);
$this->connection->reuseConnection = TRUE;
$this->api = new IslandoraFedoraApi($this->connection);
@ -97,28 +98,3 @@ 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) {
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) {
module_load_include('inc', 'islandora', 'includes/utilities');
global $user;
global $base_url;
// new connection
try {
$connection = new IslandoraTuque($user);
}
catch (Exception $e) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error');
$connection = islandora_get_tuque_connection();
if (!$connection) {
return;
}
if (!empty($object_model) && is_array($object_model)) {
$pid = $object_model['pid'];
if (!islandora_is_valid_pid($pid)) {
@ -293,15 +286,7 @@ function islandora_install_solution_pack($module_name = NULL, $op = 'install') {
return;
}
// create new 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;
}
$connection = islandora_get_tuque_connection();
// get object models
$enabled_solution_packs = module_invoke_all('islandora_required_objects');
$islandora_required_objects = $module_name . '_islandora_required_objects';

6
includes/utilities.inc

@ -98,7 +98,8 @@ function islandora_is_valid_dsid($dsid) {
*/
function islandora_describe_repository($url = NULL) {
$url = isset($url) ? $url : variable_get('islandora_base_url', 'http://localhost:8080/fedora');
$connection = new IslandoraTuque(NULL, $url);
$connection = islandora_get_tuque_connection();
if ($connection) {
try {
$info = $connection->api->a->describeRepository();
return $info;
@ -106,6 +107,8 @@ function islandora_describe_repository($url = NULL) {
catch (RepositoryException $e) {
return FALSE;
}
}
return FALSE;
}
/**
@ -375,7 +378,6 @@ function islandora_get_datastreams_requirements_from_content_model(FedoraObject
* An ingestable NewFedoraObject.
*/
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;
$tuque = islandora_get_tuque_connection();
$object = isset($namespace) ? $tuque->repository->constructObject($namespace) : new NewFedoraObject(NULL, $tuque->repository);

35
islandora.module

@ -454,6 +454,31 @@ function islandora_default_islandora_view_object($object) {
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() {
module_load_include('inc', 'islandora', 'includes/IslandoraTuque');
$tuque = &drupal_static(__FUNCTION__);
if (!$tuque) {
if (IslandoraTuque::exists()) {
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;
}
/**
* A helper function to get a connection and return an object for objects
* specified in the menu path as '%islandora_object'.
@ -471,7 +496,6 @@ function islandora_default_islandora_view_object($object) {
* drupal_access_denied().
*/
function islandora_object_load($object_id) {
module_load_include('inc', 'islandora', 'includes/IslandoraTuque');
$tuque = islandora_get_tuque_connection();
if ($tuque) {
try {
@ -603,12 +627,21 @@ function islandora_islandora_undeletable_datastreams(array $models) {
*
* @return FedoraObject
* The ingested FedoraObject, after running the pre/post ingest hooks.
* Returns FALSE if the ingest failed.
*/
function islandora_add_object(NewFedoraObject &$object) {
islandora_pre_add_object($object);
try {
$object->repository->ingestObject($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