From b610533cbe49c68c08a5db95638926839c765f29 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Fri, 30 Nov 2012 04:36:32 +0000 Subject: [PATCH] Fix potential white screen problems with instantiating IslandoraTuque. --- admin/islandora.admin.inc | 11 +++++----- includes/IslandoraTuque.inc | 26 +---------------------- includes/solution_packs.inc | 21 +++---------------- includes/utilities.inc | 18 ++++++++-------- islandora.module | 41 +++++++++++++++++++++++++++++++++---- 5 files changed, 56 insertions(+), 61 deletions(-) diff --git a/admin/islandora.admin.inc b/admin/islandora.admin.inc index 3a71c652..5eacbcff 100644 --- a/admin/islandora.admin.inc +++ b/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(); } diff --git a/includes/IslandoraTuque.inc b/includes/IslandoraTuque.inc index 89086829..0eb949b6 100644 --- a/includes/IslandoraTuque.inc +++ b/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; -} diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index 8c8cb3e0..d6fab446 100644 --- a/includes/solution_packs.inc +++ b/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'; diff --git a/includes/utilities.inc b/includes/utilities.inc index 2e36e7bd..375d4aba 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -98,14 +98,17 @@ 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); - try { - $info = $connection->api->a->describeRepository(); - return $info; - } - catch (RepositoryException $e) { - return FALSE; + $connection = islandora_get_tuque_connection(); + if ($connection) { + try { + $info = $connection->api->a->describeRepository(); + return $info; + } + 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); diff --git a/islandora.module b/islandora.module index f2d49ebb..71dc6a34 100644 --- a/islandora.module +++ b/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); - $object->repository->ingestObject($object); - islandora_post_add_object($object); - return $object; + try { + $object->repository->ingestObject($object); + islandora_post_add_object($object); + return $object; + } catch (Exception $e) { + watchdog('islandora', 'Failed to ingest object: @pid
code: @code
message: @msg', array( + '@pid' => $object->id, + '@code' => $e->getCode(), + '@msg' => $e->getMessage()), WATCHDOG_ERROR); + } + return FALSE; } /**