From 0ba035d4da00f681247d91f0b018d9c307471a5d Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 28 Feb 2012 12:15:17 +0000 Subject: [PATCH 1/3] Cleaned up the function soap_call(). It was using watchdog incorrectly, causing the function to attempt to serialize non-serializable data. --- api/fedora_item.inc | 183 ++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 100 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 7524ebbb..3367df43 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -1,7 +1,7 @@ objectProfile)); @@ -81,7 +97,7 @@ class Fedora_Item { * @param type $datastream_mimetype * @param type $controlGroup * @param type $logMessage - * @return type + * @return type */ function add_datastream_from_file($datastream_file, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = NULL) { module_load_include('inc', 'fedora_repository', 'MimeClass'); @@ -116,7 +132,7 @@ class Fedora_Item { * @param type $datastream_mimetype * @param type $controlGroup * @param type $logMessage - * @return type + * @return type */ function add_datastream_from_url($datastream_url, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = NULL) { if (empty($datastream_label)) { @@ -151,7 +167,7 @@ class Fedora_Item { * @param type $datastream_mimetype * @param type $controlGroup * @param type $logMessage - * @return type + * @return type */ function add_datastream_from_string($str, $datastream_id, $datastream_label = NULL, $datastream_mimetype = 'text/xml', $controlGroup = 'M', $logMessage = NULL) { $dir = file_directory_temp(); @@ -164,9 +180,8 @@ class Fedora_Item { return $returnvalue; } - /** - * Wrapper to add new or modify existing datastream + * Wrapper to add new or modify existing datastream * @global url $base_url * @param url $external_url * @param string $dsid @@ -175,7 +190,7 @@ class Fedora_Item { * @param string $controlGroup * @param boolean $force * @param string $logMessage - * @param boolean $quiet + * @param boolean $quiet */ function add_or_modify_by_reference($external_url, $dsid, $label, $mime_type, $controlGroup = 'M', $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) { global $base_url; @@ -193,7 +208,7 @@ class Fedora_Item { * does not support rels-int yet. * @param type $relationship * @param type $object - * @param type $namespaceURI + * @param type $namespaceURI */ function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI) { $ds_list = $this->get_datastreams_list_as_array(); @@ -297,7 +312,7 @@ class Fedora_Item { /** * Export as foxml - * @return type + * @return type */ function export_as_foxml() { $params = array( @@ -378,7 +393,7 @@ class Fedora_Item { * Get datastream dissemination * @param type $dsid * @param type $as_of_date_time - * @return string + * @return string */ function get_datastream_dissemination($dsid, $as_of_date_time = "") { $params = array( @@ -401,7 +416,7 @@ class Fedora_Item { * Get datastream * @param type $dsid * @param type $as_of_date_time - * @return type + * @return type */ function get_datastream($dsid, $as_of_date_time = "") { $params = array( @@ -417,7 +432,7 @@ class Fedora_Item { /** * Get datastream history * @param type $dsid - * @return type + * @return type */ function get_datastream_history($dsid) { $params = array( @@ -439,7 +454,7 @@ class Fedora_Item { * @param type $method_name * @param type $parameters * @param type $as_of_date_time - * @return string + * @return string */ function get_dissemination($service_definition_pid, $method_name, $parameters = array(), $as_of_date_time = NULL) { $params = array( @@ -658,18 +673,16 @@ class Fedora_Item { return FALSE; } - + /** * Set the object to a deleted state */ - function move_to_trash($log_message = 'Flagged deleted using Islandora API.') - { + function move_to_trash($log_message = 'Flagged deleted using Islandora API.') { // Loop through the datastreams and mark them deleted - foreach($this->get_datastreams_list_as_array() as $dsid) - { + foreach ($this->get_datastreams_list_as_array() as $dsid) { $this->set_datastream_state($dsid, 'D'); } - + // Create a message to mark the object deleted $params = array( 'pid' => $this->pid, @@ -685,13 +698,13 @@ class Fedora_Item { * Removes this object form the repository. * @param type $log_message * @param type $force - * @return type + * @return type */ function purge($log_message = 'Purged using Islandora API.', $force = FALSE) { - + // Flag the object to be deleted first $this->move_to_trash($log_message); - + // Create the delete message $params = array( 'pid' => $this->pid, @@ -710,7 +723,7 @@ class Fedora_Item { * @param type $end_date * @param type $log_message * @param type $force - * @return type + * @return type */ function purge_datastream($dsID, $start_date = NULL, $end_date = NULL, $log_message = 'Purged datastream using Islandora API', $force = FALSE) { $params = array( @@ -727,7 +740,7 @@ class Fedora_Item { /** * URL * @global type $base_url - * @return type + * @return type */ function url() { global $base_url; @@ -737,7 +750,7 @@ class Fedora_Item { /** * Get Next PID in Namespace * @param type $pid_namespace - * @return type + * @return type */ static function get_next_PID_in_namespace($pid_namespace = '') { @@ -765,7 +778,7 @@ class Fedora_Item { /** * ingest from FOXML * @param type $foxml - * @return Fedora_Item + * @return Fedora_Item */ static function ingest_from_FOXML($foxml) { $params = array('objectXML' => $foxml->saveXML(), 'format' => "info:fedora/fedora-system:FOXML-1.1", 'logMessage' => "Fedora Object Ingested"); @@ -776,7 +789,7 @@ class Fedora_Item { /** * ingest from FOXML file * @param type $foxml_file - * @return type + * @return type */ static function ingest_from_FOXML_file($foxml_file) { $foxml = new DOMDocument(); @@ -786,7 +799,7 @@ class Fedora_Item { /** * ingest from FOXML files in directory - * @param type $path + * @param type $path */ static function ingest_from_FOXML_files_in_directory($path) { // Open the directory @@ -814,7 +827,7 @@ class Fedora_Item { * @param type $ownerId * @param type $logMessage * @param type $quiet - * @return type + * @return type */ function modify_object($label = '', $state = NULL, $ownerId = NULL, $logMessage = 'Modified by Islandora API', $quiet=TRUE) { @@ -838,7 +851,7 @@ class Fedora_Item { * @param type $force * @param type $logMessage * @param type $quiet - * @return type + * @return type */ function modify_datastream_by_reference($external_url, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) { $params = array( @@ -866,7 +879,7 @@ class Fedora_Item { * @param type $force * @param type $logMessage * @param type $quiet - * @return type + * @return type */ function modify_datastream_by_value($content, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) { $params = array( @@ -899,74 +912,44 @@ class Fedora_Item { } /** - * Soap call - * @param type $function_name - * @param type $params_array - * @param type $quiet - * @return type + * Make a soap call to the fedora API. + * + * @param string $function + * The name of the soap function to call. + * @param array $parameters + * Paramters to pass onto the soap call + * @param boolean $quiet + * If TRUE suppress drupal messages. + * + * @return mixed + * The return value from the soap function if successful, NULL otherwise. */ - static function soap_call($function_name, $params_array, $quiet = FALSE) { + static function soap_call($function, $parameters, $quiet = FALSE) { if (!self::$connection_helper) { module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); self::$connection_helper = new ConnectionHelper(); } - switch ($function_name) { - case 'ingest': - case 'addDataStream': - case 'addRelationship': - case 'export': - case 'getDatastream': - case 'getDatastreamHistory': - case 'getNextPID': - case 'getRelationships': - case 'modifyDatastreamByValue': - case 'modifyDatastreamByReference': - case 'purgeDatastream': - case 'purgeObject': - case 'modifyObject': - case 'setDatastreamState': - $soap_client = self::$connection_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl')); - try { - if (!empty($soap_client)) { - $result = $soap_client->__soapCall($function_name, array('parameters' => $params_array)); - } - else { - watchdog(t("FEDORA_REPOSITORY"), "Error trying to get SOAP client connection."); - return NULL; - } - } catch (exception $e) { - if (!$quiet) { - - if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage())) { - drupal_set_message(t('Error: Insufficient permissions to call SOAP function !fn.', array('!fn' => $function_name)), 'error'); - } - else { - drupal_set_message(t("Error trying to call SOAP function $function_name. Check watchdog logs for more information."), 'error'); - } - - watchdog(t("FEDORA_REPOSITORY"), "Error Trying to call SOAP function @fn: @e", array('@fn' => $function_name, '@e' => $e), NULL, WATCHDOG_ERROR); - } - return NULL; - } - break; - - default: - try { - $soap_client = self::$connection_helper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl')); - if (!empty($soap_client)) { - $result = $soap_client->__soapCall($function_name, array('parameters' => $params_array)); - } - else { - watchdog(t("FEDORA_REPOSITORY"), "Error trying to get SOAP client connection."); - return NULL; - } - } catch (exception $e) { - - if (!$quiet) { - watchdog(t("FEDORA_REPOSITORY"), "Error trying to call SOAP function @fn: @e", array('@fn' => $function_name, '@e' => $e), NULL, WATCHDOG_ERROR); - } - return NULL; + $url = (array_search($function, self::$SoapManagedFunctions) !== FALSE) ? + variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl') : + variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'); + try { + $soap_client = self::$connection_helper->getSoapClient($url); + if (empty($soap_client)) { + if (!$quiet) { + drupal_set_message(t('Error trying to get SOAP client connection.')); } + watchdog('fedora_repository', 'Error trying to get SOAP client connection.'); + return NULL; + } + $result = $soap_client->__soapCall($function, array('parameters' => $parameters)); + } catch (Exception $e) { + if (!$quiet) { + preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage()) ? + drupal_set_message(t('Insufficient permissions to call SOAP function "%func".', array('%func' => $function)), 'error') : + drupal_set_message(t('Error trying to call SOAP function "%func". Check watchdog logs for more information.', array('%func' => $function)), 'error'); + } + watchdog('fedora_repository', 'Error Trying to call SOAP function "%func". Exception Occured: @e', array('%func' => $function, '@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); + return NULL; } return $result; } @@ -979,7 +962,7 @@ class Fedora_Item { * @param string $state The initial state, A - Active, I - Inactive, D - Deleted * @param type $label * @param type $owner - * @return DOMDocument + * @return DOMDocument */ static function create_object_FOXML($pid = '', $state = 'A', $label = 'Untitled', $owner = '') { $foxml = new DOMDocument("1.0", "UTF-8"); @@ -1034,16 +1017,16 @@ class Fedora_Item { * @param type $state * @param type $label * @param type $owner - * @return type + * @return type */ static function ingest_new_item($pid = '', $state = 'A', $label = '', $owner = '') { return self::ingest_from_FOXML(self::create_object_FOXML($pid, $state, $label, $owner)); } /** - * fedora item exists + * fedora item exists * @param type $pid - * @return type + * @return type */ static function fedora_item_exists($pid) { $item = new Fedora_Item($pid); From 6bd33358edcd1dd5b50df44e52e61762e896498f Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Fri, 2 Mar 2012 17:38:49 +0000 Subject: [PATCH 2/3] Using fedora item instead of object helper in some cause to prevent exceptions such as object not found in lower level storage. --- CollectionClass.inc | 24 ++++++++++++++---------- api/fedora_item.inc | 10 ++++++---- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index f561295c..08f669e0 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -45,11 +45,12 @@ class CollectionClass { * @return type */ function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) { - module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - $objectHelper = new ObjectHelper(); if (!isset($itqlquery)) { - // $query_string = $objectHelper->getStream($pid, 'QUERY', 0); - $itqlquery = $objectHelper->getStream($pid, 'QUERY', 0); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $item = new Fedora_Item($pid); + if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { + $itqlquery = $item->get_datastream_dissemination('QUERY'); + } } return $this->getRelatedItems($pid, $itqlquery, $limit, $offset); } @@ -78,7 +79,11 @@ class CollectionClass { $objectHelper = new ObjectHelper(); $query_string = $itqlquery; if (!isset($query_string)) { - $query_string = $objectHelper->getStream($pid, 'QUERY', 0); + $query_string = NULL; + $item = new Fedora_Item($pid); + if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { + $query_string = $item->get_datastream_dissemination('QUERY'); + } if ($query_string == NULL) { $query_string = 'select $object $title $content from <#ri> where ($object $title @@ -445,7 +450,7 @@ class CollectionClass { 'pidNamespace' => $pidNameSpace ); $object = $soapClient->__soapCall('getNextPID', array( - $params + $params )); } catch (exception $e) { drupal_set_message(t('Error getting Next PID: @e', array('@e' => check_plain($e->getMessage()))), 'error'); @@ -498,11 +503,10 @@ class CollectionClass { module_load_include('inc', 'fedora_repository', 'CollectionManagement'); module_load_include('inc', 'fedora_repository', 'BatchIngest'); global $base_url; - $tabset = array(); global $user; - $objectHelper = new ObjectHelper(); - $item = new Fedora_Item($this->pid); + $tabset = array(); $query = NULL; + $item = new Fedora_Item($this->pid); if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { $query = $item->get_datastream_dissemination('QUERY'); } @@ -517,7 +521,7 @@ class CollectionClass { $show_batch_tab = FALSE; $policy = CollectionPolicy::loadFromCollection($this->pid, TRUE); - if(!empty($policy)){ + if (!empty($policy)) { $content_models = $policy->getContentModels(); } if (count($content_models) == 1 && $content_models[0]->pid == "islandora:collectionCModel") { diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 3367df43..afc110bd 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -934,21 +934,23 @@ class Fedora_Item { variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'); try { $soap_client = self::$connection_helper->getSoapClient($url); - if (empty($soap_client)) { + if (isset($soap_client)) { + $result = $soap_client->__soapCall($function, array('parameters' => $parameters)); + } + else { if (!$quiet) { - drupal_set_message(t('Error trying to get SOAP client connection.')); + drupal_set_message(t('Error trying to get SOAP client connection')); } watchdog('fedora_repository', 'Error trying to get SOAP client connection.'); return NULL; } - $result = $soap_client->__soapCall($function, array('parameters' => $parameters)); } catch (Exception $e) { if (!$quiet) { preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage()) ? drupal_set_message(t('Insufficient permissions to call SOAP function "%func".', array('%func' => $function)), 'error') : drupal_set_message(t('Error trying to call SOAP function "%func". Check watchdog logs for more information.', array('%func' => $function)), 'error'); } - watchdog('fedora_repository', 'Error Trying to call SOAP function "%func". Exception Occured: @e', array('%func' => $function, '@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); + watchdog('fedora_repository', 'Error Trying to call SOAP function "%func". Exception: @e in @f(@l)\n@t', array('%func' => $function, '@e' => $e->getMessage(), '@f' => $e->getFile(), '@l' => $e->getLine(), '@t' => $e->getTraceAsString()), NULL, WATCHDOG_ERROR); return NULL; } return $result; From 2f979ab447565b881ef058866ac053940ecf50c2 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Fri, 2 Mar 2012 17:45:20 +0000 Subject: [PATCH 3/3] Found incorrect use of watchdog. --- ObjectHelper.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 1a8db575..e8555635 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -383,8 +383,8 @@ class ObjectHelper { $xsl->load($path . '/xsl/convertQDC.xsl'); $input = new DomDocument(); $input->loadXML(trim($xmlstr)); - } catch (exception $e) { - watchdog(t("Fedora_Repository"), "Problem loading XSL file: @e", array('@e' => $e), NULL, WATCHDOG_ERROR); + } catch (Exception $e) { + watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); } $xsl = $proc->importStylesheet($xsl); $newdom = $proc->transformToDoc($input);