diff --git a/CollectionClass.inc b/CollectionClass.inc index 6c5fd8f5..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); } @@ -67,9 +68,6 @@ class CollectionClass { function getRelatedItems($pid, $itqlquery = NULL, $limit = NULL, $offset = NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - if (!isset($limit)) { - $limit = 1000; - } if (!isset($offset)) { $offset = 0; } @@ -81,10 +79,14 @@ 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 + where ($object $title and $object $content and ($object or $object ) @@ -343,7 +345,7 @@ class CollectionClass { $thisClass = new $phpClass (); $returnValue = $thisClass->$phpMethod($parametersArray, $dsid, $file, $file_ext); if (!$returnValue) { - drupal_set_message('Error! Failed running content model method !m !rv', array('!m' => $phpMethod, '!rv' => $returnValue)); + drupal_set_message(t('Error! Failed running content model method !m !rv', array('!m' => $phpMethod, '!rv' => $returnValue))); return FALSE; } } @@ -448,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'); @@ -463,7 +465,7 @@ class CollectionClass { module_load_include('inc', 'fedora_repository', 'plugins/PersonalCollectionClass'); $personalCollectionClass = new PersonalCollectionClass(); if (!$personalCollectionClass->createCollection($user, $pid, $soapClient)) { - drupal_set_message("Did not create a personal collection object for !u", array('!u' => $user->name)); + drupal_set_message(t("Did not create a personal collection object for !u", array('!u' => $user->name))); return FALSE; //creation failed don't save the collection pid in drupal db } user_save($user, $personal_collection_pid); @@ -501,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'); } @@ -520,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/ContentModel.inc b/ContentModel.inc index cbacd422..be362c70 100644 --- a/ContentModel.inc +++ b/ContentModel.inc @@ -429,12 +429,12 @@ class ContentModel extends XMLDatastream { */ public function getServices() { $query = 'select $object $title from <#ri> - where ($object $title - and $object $deploymentOf - and $object - and $object pid . '> - and $object ) - order by $title'; + where ($object $title + and $object $deploymentOf + and $object + and $object pid . '> + and $object ) + order by $title'; module_load_include('inc', 'fedora_repository', 'CollectionClass'); @@ -1374,6 +1374,7 @@ class ContentModel extends XMLDatastream { else { $status = $class->$methodName($param_array, $method->getAttribute('dsid'), $file, $method->getAttribute('modified_files_ext')); if ($status !== TRUE) { + self::$errors[] = 'Execute Ingest Rules: method \'' . $className . '->' . $methodName . '\' failed.'; $ret = FALSE; } } diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 313d2159..31a0ccd2 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -122,8 +122,7 @@ class ObjectHelper { $dsID = variable_get('fedora_default_display_dsid', 'TN'); $mimeType = 'image/jpeg'; } - - $url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/get/' . $pid . '/' . $dsID; + $url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/objects/' . $pid . '/datastreams/' . $dsID . '/content'; if ($version) { $url .= '/' . $version; //drupal_urlencode($version); } @@ -383,8 +382,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); @@ -729,7 +728,7 @@ class ObjectHelper { */ function get_parent_objects($pid) { $query_string = 'select $object $title from <#ri> - where ($object $title + where ($object $title and $object and $object ) order by $title'; @@ -829,7 +828,7 @@ class ObjectHelper { // Get title and descriptions for $pid $query_string = 'select $title $desc from <#ri> - where $o $title + where $o $title and $o $desc and $o '; @@ -858,7 +857,7 @@ class ObjectHelper { $query_string = 'select $o $title from <#ri> ' . // $query_string = 'select $o $title $desc from <#ri> '. 'where $s $o ' . - 'and $o $title ' . + 'and $o $title ' . // 'and $o $desc '. 'and ( '; @@ -924,12 +923,13 @@ class ObjectHelper { // Before executing the query, we hve a base case of accessing the top-level collection global $base_url; if ($pid == variable_get('fedora_repository_pid', 'islandora:root')) { - $breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); + //$breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); + $breadcrumbs[] = l(variable_get('fedora_repository_title', 'Digital repository'), 'fedora/repository'); $breadcrumbs[] = l(t('Home'), $base_url); } else { $query_string = 'select $parentObject $title $content from <#ri> - where ( $title + where ( $title and $parentObject $content and ( $parentObject or $parentObject @@ -954,7 +954,8 @@ class ObjectHelper { $breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid); if ($parent == variable_get('fedora_repository_pid', 'islandora:root')) { - $breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); + //$breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); + $breadcrumbs[] = l(variable_get('fedora_repository_title', 'Digital repository'), 'fedora/repository'); $breadcrumbs[] = l(t('Home'), $base_url); } elseif ($level > 0) { @@ -963,7 +964,7 @@ class ObjectHelper { } else { - $breadcrumbs[] = l("Path Calculation Error", 'fedora/repository/' . $pid); + $breadcrumbs[] = l(t("Path Calculation Error"), 'fedora/repository/' . $pid); } } } diff --git a/SecurityClass.inc b/SecurityClass.inc index 55a6ebb4..970b108b 100644 --- a/SecurityClass.inc +++ b/SecurityClass.inc @@ -71,9 +71,9 @@ class SecurityClass { try { $xml = new SimpleXMLElement($policyStream); } catch (Exception $e) { - watchdog(t("Fedora_Repository"), t("No roles found in security policy, could not parse policy stream."), NULL, WATCHDOG_ERROR); + watchdog(t("Fedora_Repository"), "No roles found in security policy, could not parse policy stream.", NULL, WATCHDOG_ERROR); //we may not want to send this to the screen. - drupal_set_message(t('No roles found in security policy, could not parse policy stream: !message', array('!message' => $e->getMessage())), 'error'); + drupal_set_message(t('No roles found in security policy, could not parse policy stream: !message', array('!message' => check_plain($e->getMessage()))), 'error'); return NULL; } $xml->registerXPathNamespace('default', 'urn:oasis:names:tc:xacml:1.0:policy'); @@ -110,7 +110,7 @@ class SecurityClass { try { $doc->load(drupal_get_path('module', 'Fedora_Repository') . '/policies/noObjectEditPolicy.xml'); } catch (exception $e) { - watchdog(t("Fedora_Repository"), t("Problem loading policy file."), NULL, WATCHDOG_ERROR); + watchdog(t("Fedora_Repository"), "Problem loading policy file.", NULL, WATCHDOG_ERROR); } $conditions = $doc->getElementsByTagName('Condition'); foreach ($conditions as $condition) { diff --git a/api/fedora_collection.inc b/api/fedora_collection.inc index a82bf39b..200fb324 100644 --- a/api/fedora_collection.inc +++ b/api/fedora_collection.inc @@ -77,7 +77,7 @@ function get_related_items_as_xml($collection_pid, $relationship = array('isMemb } $query_string = 'select $object $title $content from <#ri> - where ($object $title + where ($object $title and $object $content and ('; diff --git a/api/fedora_item.inc b/api/fedora_item.inc index a79749a7..e6477915 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -1,11 +1,12 @@ soap_call('getObjectProfile', array('pid' => $this->pid, 'asOfDateTime' => "")); - + $raw_objprofile = $this->soap_call('getObjectProfile', array('pid' => $this->pid, 'asOfDateTime' => ""), TRUE); + if (!empty($raw_objprofile)) { $this->objectProfile = $raw_objprofile->objectProfile; $this->datastreams = $this->get_datastreams_list_as_array(); @@ -57,8 +74,17 @@ class Fedora_Item { } /** - * Exists - * @return type + * Forget this Object, do manually when memory constraints apply. + * + * Removes this object from the static list of $instantiated_pids + */ + function forget() { + unset(Fedora_Item::$instantiated_pids[$this->pid]); + } + + /** + * Exists + * @return type */ function exists() { return (!empty($this->objectProfile)); @@ -72,7 +98,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'); @@ -107,13 +133,21 @@ 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) { + global $base_url; + if (empty($datastream_label)) { $datastream_label = $datastream_id; } + // Fedora has some problems getting files from HTTPS connections sometimes, so if we are getting a file + // from the local drupal, we try to pass a HTTP url instead of a HTTPS one. + if(stripos($datastream_url, 'https://') !== FALSE && stripos($datastream_url, $base_url) !== FALSE) { + $datastream_url = str_ireplace('https://', 'http://', $datastream_url); + } + $params = array( 'pid' => $this->pid, 'dsID' => $datastream_id, @@ -142,7 +176,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(); @@ -155,12 +189,35 @@ class Fedora_Item { return $returnvalue; } + /** + * Wrapper to add new or modify existing datastream + * @global url $base_url + * @param url $external_url + * @param string $dsid + * @param string $label + * @param string $mime_type + * @param string $controlGroup + * @param boolean $force + * @param string $logMessage + * @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; + if (array_key_exists($dsid, $this->datastreams)) { + $this->modify_datastream_by_reference($external_url, $dsid, $label, $mime_type, $force, $logMessage, $quiet); + } + else { + $file_location = str_replace("$base_url/", '', $external_url); + $this->add_datastream_from_file($file_location, $dsid, $label, $mime_type, $controlGroup = 'M', $logMessage = NULL); + } + } + /** * Add a relationship string to this object's RELS-EXT. * 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(); @@ -237,6 +294,10 @@ class Fedora_Item { $relationship = "hasModel"; $namespaceURI = FEDORA_MODEL_URI; break; + case "isPageNumber": + $relationship = "isPageNumber"; + $namespaceURI = ISLANDORA_PAGE_URI; + break; } if (substr($object, 0, 12) != 'info:fedora/') { @@ -264,7 +325,7 @@ class Fedora_Item { /** * Export as foxml - * @return type + * @return type */ function export_as_foxml() { $params = array( @@ -345,15 +406,18 @@ class Fedora_Item { * Get datastream dissemination * @param type $dsid * @param type $as_of_date_time - * @return string + * @param type $quiet + * @return null */ - function get_datastream_dissemination($dsid, $as_of_date_time = "") { + function get_datastream_dissemination($dsid, $as_of_date_time = "", $quiet=TRUE) { $params = array( 'pid' => $this->pid, 'dsID' => $dsid, 'asOfDateTime' => $as_of_date_time, ); - $object = self::soap_call('getDataStreamDissemination', $params); + + // Make soap call with quite + $object = self::soap_call('getDataStreamDissemination', $params, $quiet); if (!empty($object)) { $content = $object->dissemination->stream; $content = trim($content); @@ -368,7 +432,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( @@ -384,7 +448,7 @@ class Fedora_Item { /** * Get datastream history * @param type $dsid - * @return type + * @return type */ function get_datastream_history($dsid) { $params = array( @@ -406,7 +470,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( @@ -574,8 +638,36 @@ class Fedora_Item { return $relationships; } + function get_rdf_relationships() { + + $relationships = array(); + try { + $relsext = $this->get_datastream_dissemination('RELS-EXT'); + } catch (exception $e) { + drupal_set_message(t("Error retrieving RELS-EXT of object $pid"), 'error'); + return $relationships; + } + + // Parse the RELS-EXT into an associative array. + $relsextxml = new DOMDocument(); + $relsextxml->loadXML($relsext); + $relsextxml->normalizeDocument(); + $allTags = array(); + $allTags[] = $relsextxml->getElementsByTagNameNS(RELS_EXT_URI, '*'); + $allTags[] = $relsextxml->getElementsByTagNameNS(FEDORA_MODEL_URI, '*'); + $allTags[] = $relsextxml->getElementsByTagNameNS(ISLANDORA_PAGE_URI, '*'); + foreach ($allTags as $tags) { + foreach ($tags as $child) { + $value = preg_replace('/info:fedora\//','',$child->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource')); + + $relationships[$child->tagName][] = $value; + } + } + + return $relationships; + } - function get_models() { + function get_models() { $relationships = array(); try { $relsext = $this->get_datastream_dissemination('RELS-EXT'); @@ -627,19 +719,47 @@ class Fedora_Item { return FALSE; } + /** + * Set the object to a deleted state + */ + 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) { + $this->set_datastream_state($dsid, 'D'); + } + + // Create a message to mark the object deleted + $params = array( + 'pid' => $this->pid, + 'state' => 'D', + 'logMessage' => $logMessage, + 'label' => $this->objectProfile->objLabel, + 'ownerId' => null, + ); + + // Send message to mark the object deleted + return self::soap_call('modifyObject', $params, $quiet); + } + /** * 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, 'logMessage' => $log_message, 'force' => $force ); + // Delete the object return $this->soap_call('purgeObject', $params); } @@ -650,7 +770,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( @@ -667,7 +787,7 @@ class Fedora_Item { /** * URL * @global type $base_url - * @return type + * @return type */ function url() { global $base_url; @@ -677,7 +797,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 = '') { @@ -705,7 +825,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"); @@ -716,7 +836,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(); @@ -726,7 +846,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 @@ -754,7 +874,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) { @@ -778,7 +898,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( @@ -806,7 +926,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( @@ -839,74 +959,46 @@ 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 (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')); } + watchdog('fedora_repository', 'Error trying to get SOAP client connection.'); + return NULL; + } + } 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: @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; } @@ -919,7 +1011,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"); @@ -974,16 +1066,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); diff --git a/api/fedora_utils.inc b/api/fedora_utils.inc index 89545191..eb56bdcc 100644 --- a/api/fedora_utils.inc +++ b/api/fedora_utils.inc @@ -236,8 +236,10 @@ function fix_dsid($dsid) { function get_collections_as_option_array() { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); $restricted = variable_get('fedora_namespace_restriction_enforced', TRUE); + $allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:'); + $namespaces = explode(':', $allowed_string); $query = 'select $object $title from <#ri> - where ($object $title + where ($object $title and $object and $object ) order by $title'; @@ -247,13 +249,22 @@ function get_collections_as_option_array() { $list = explode("\n", $content); array_shift($list); $list = preg_replace('/info:fedora\//', '', $list); + foreach ($namespaces as $namespace) { + $trimmed_names[] = trim($namespace); + } $options = array(); foreach ($list as $item) { //removes blanks if ($item) { $parts = explode(',', $item); - $options[$parts[0]] = $parts[1]; + $namespace = explode(':', $parts[0]); + $namespace = trim($namespace[0]); + $bool = in_array($namespace, $trimmed_names); + if (!$restricted || in_array($namespace, $trimmed_names)) { + $options[$parts[0]] = $parts[1]; + } } } + unset($options['islandora:ContentModelCollection']); return $options; } @@ -277,7 +288,7 @@ function get_content_models_as_option_array() { } } $query = 'select $object $title from <#ri> - where ($object $title + where ($object $title and ($object or $object ) and $object ) diff --git a/fedora_repository.module b/fedora_repository.module index 00201ec9..42eb4c49 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -143,7 +143,7 @@ function fedora_repository_ingest_object($collection_pid=NULL, $collection_label function fedora_repository_ingest_form_submit(array $form, array &$form_state) { //only validate the form if the submit button was pressed (other buttons may be used for AHAH if ($form_state['ahah_submission']) { - $form_state['submitted'] = false; + $form_state['submitted'] = FALSE; return; } if ($form_state['storage']['xml']) { @@ -202,7 +202,7 @@ function fedora_repository_ingest_form_submit(array $form, array &$form_state) { function fedora_repository_ingest_form_validate($form, &$form_state) { //only validate the form if the submit button was pressed (other buttons may be used for AHAH if ($form_state['ahah_submission']) { - $form_state['submitted'] = false; + $form_state['submitted'] = FALSE; return; } if ($form_state['clicked_button']['#id'] == 'edit-submit' && $form_state['ahah_submission'] != 1) { @@ -246,8 +246,11 @@ function fedora_repository_ingest_form_validate($form, &$form_state) { if (!empty($file)) { if (!in_array($dformat, $allowedMimeTypes)) { - form_set_error('ingest-file-location', t('The uploaded file\'s mimetype (' . $dformat . ') is not associated with this Content Model. The allowed types are ' . - implode(' ', $allowedMimeTypes))); + form_set_error('ingest-file-location', + t('The uploaded file\'s mimetype') . + ' (' . $dformat . ') ' . + t('is not associated with this Content Model. The allowed types are') . + ' ' . implode(' ', $allowedMimeTypes)); file_delete($file); return; } @@ -505,7 +508,7 @@ function fedora_repository_purge_object_form_validate($form, &$form_state) { foreach ($contentModels as $contentModel) { if ($contentModel->pid == 'islandora:collectionCModel') { $member_pids = get_related_items_as_array($pid, 'isMemberOfCollection'); - if (is_array($member_pids) && ! empty($member_pids)){ + if (is_array($member_pids) && ! empty($member_pids)) { form_set_error('new_collection_pid', t("Please purge all members of this collection before deleting the collection itself.")); return; } @@ -614,7 +617,7 @@ function fedora_repository_purge_stream_form_submit($form, &$form_state) { * @param type $collectionName * @return type */ -function fedora_repository_replace_stream($pid, $dsId, $dsLabel, $collectionName = NULL) { +function fedora_repository_replace_stream($pid, $dsId, $dsLabel = '', $collectionName = NULL) { if ($pid == NULL || $dsId == NULL) { drupal_set_message(t('You must specify an pid and dsId to replace.'), 'error'); return ''; @@ -704,8 +707,20 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $dformat = $mimetype->getType($file->filepath); $item = new Fedora_Item($pid); + $info = $item->get_datastream_info($dsid); - $item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat); + if($info->datastream->controlGroup == 'M') { + $item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat); + } elseif ($info->datastream->controlGroup == 'X') { + if($dformat == 'text/xml') { + $item->modify_datastream_by_value(file_get_contents($file->filepath), $dsid, $dsLabel, $dformat); + } + else { + drupal_set_message('File must be of mimetype text/xml in order to replace inline XML datastream.', 'error'); + } + } else { + drupal_set_message('Cannot replace Redirect or Managed Datastream.', 'error'); + } $form_state['redirect'] = 'fedora/repository/' . $pid; } @@ -879,6 +894,7 @@ function fedora_repository_access($op, $node, $account) { * @param $dsID String */ function makeObject($pid, $dsID) { + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); if (!valid_pid($pid)) { drupal_set_message(t("Invalid PID!"), 'error'); @@ -1008,6 +1024,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU ); } } + // Add a 'manage object' tab for all objects, where detailed list of content is shown. $obj = new FedoraObjectDetailedContent($pid); $object_details = $obj->showFieldSets(); @@ -1592,7 +1609,7 @@ function fedora_repository_demo_objects_form_submit($form, &$form_state) { $dc->set_element('dc:title', array('Installed Content Model')); $dc->save(); $cmodel_collection->add_datastream_from_string('select $object $title from <#ri> - where ($object $title + where ($object $title and ($object or $object ) and $object ) @@ -2146,13 +2163,16 @@ function fedora_repository_display_schema($file) { * @return type */ function fedora_repository_batch_reingest_object($object, &$context) { + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); + if (!empty($object) && is_array($object)) { $pid = $object['pid']; if (!valid_pid($pid)) { return NULL; } + // Does the object exist? If so, purge it. $item = new Fedora_Item($pid); if ($item->exists()) { @@ -2168,6 +2188,7 @@ function fedora_repository_batch_reingest_object($object, &$context) { $context['message'][] = "$new_item->pid installed."; } } + if (!empty($object['dsid']) && !empty($object['datastream_file'])) { $datastreams = array( array( @@ -2181,10 +2202,13 @@ function fedora_repository_batch_reingest_object($object, &$context) { } if (!empty($datastreams) && is_array($datastreams)) { + $label = !empty($object['label']) ? $object['label'] : ''; + if (empty($object['foxml_file']) && !isset($new_item)) { $new_item = Fedora_Item::ingest_new_item($object['pid'], 'A', $label); } + if (!empty($object['cmodel'])) { $new_item->add_relationship('hasModel', $object['cmodel'], FEDORA_MODEL_URI); } diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index fb09528d..efc7cd9d 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -46,19 +46,21 @@ function fedora_repository_solution_packs_page() { * @param array $solution_pack */ function fedora_repository_solution_pack_form(&$form_state, $solution_pack_module, $solution_pack_name, $objects = array()) { + // Check each object to see if it is in the repository. module_load_include('inc', 'fedora_repository', 'api/fedora_item'); global $base_path; $needs_update = FALSE; $needs_install = FALSE; $form = array(); + $form['solution_pack_module'] = array( '#type' => 'hidden', '#value' => $solution_pack_module, ); if (!$form_state['submitted']) { - $form['soluction_pack_name'] = array( + $form['solution_pack_name'] = array( '#type' => 'markup', '#value' => t($solution_pack_name), '#prefix' => '

', @@ -75,7 +77,6 @@ function fedora_repository_solution_pack_form(&$form_state, $solution_pack_modul $table_header = array('PID', 'Status'); $table_rows = array(); - foreach ($objects as $object) { $datastreams = NULL; if (isset($object['pid'])) { @@ -139,13 +140,16 @@ function fedora_repository_solution_pack_form(&$form_state, $solution_pack_modul ); if (!$needs_install && !$needs_update) { $form['install_status']['#value'] = theme_image('misc/watchdog-ok.png') . t('All required objects are installed and up-to-date.'); + $submit_button_text = t("Force Reinstallation of Fedora Objects"); + } else { $form['install_status']['#value'] = theme_image('misc/watchdog-warning.png') . t('Some objects must be re-ingested. See Objects list for details.'); + $submit_button_text = t("Install Fedora Objects"); + } $form['submit'] = array( - '#value' => t('Install'), - '#disabled' => !$needs_install && !$needs_update, + '#value' => $submit_button_text, '#type' => 'submit', '#name' => $solution_pack_module, ); @@ -159,7 +163,11 @@ function fedora_repository_solution_pack_form(&$form_state, $solution_pack_modul function fedora_repository_solution_pack_form_submit($form, &$form_state) { $what = $form_state; $module_name = $form_state['values']['solution_pack_module']; + + // This should be replaced with module_invoke $solution_pack_info = call_user_func($module_name . '_required_fedora_objects'); + //$solution_pack_info = module_invoke($module_name, 'required_fedora_objects'); + $batch = array( 'title' => t('Installing / updating solution pack objects'), 'file' => drupal_get_path('module', 'fedora_repository') . '/fedora_repository.module', @@ -181,7 +189,7 @@ function solution_pack_add_form($form_name, $form_xml) { $object->name = $form_name; $object->form = $form_xml; $result = drupal_write_record('xml_forms', $object); - drupal_set_message("Added $name"); + drupal_set_message(t("Added @name", array("@name" => $form_name))); } } @@ -196,7 +204,6 @@ function solution_pack_add_form_association($content_model, $form_name) { $object->title_field = "['titleInfo']['title']"; $object->transform = 'mods_to_dc.xsl'; $result = drupal_write_record('islandora_content_model_forms', $object); - drupal_set_message("Added association between $content_model$name"); + drupal_set_message(t("Added association between @cm and @name", array("@cm" => $content_model, "@name"=>$form_name))); } } - diff --git a/formClass.inc b/formClass.inc index be5ef9d2..293a83ec 100644 --- a/formClass.inc +++ b/formClass.inc @@ -25,8 +25,8 @@ class formClass { $items = array(); $items['admin/settings/fedora_repository'] = array( - 'title' => t('Islandora Configure'), - 'description' => t('Enter the Islandora Collection information here'), + 'title' => t('Islandora Configuration'), + 'description' => t("Configure Islandora's interaction with Fedora"), 'page callback' => 'drupal_get_form', 'page arguments' => array('fedora_repository_admin'), 'access arguments' => array('administer site configuration'), @@ -48,7 +48,6 @@ class formClass { 'file' => 'fedora_repository.solutionpacks.inc', 'type' => MENU_LOCAL_TASK, ); - $items['islandoracm.xsd'] = array( 'title' => t('Islandora Content Model XML Schema Definition'), 'page callback' => 'fedora_repository_display_schema', @@ -379,7 +378,13 @@ class formClass { // DC elements $previousElement = NULL; // Used in case we have to nest elements for qualified dublin core. + + $label = null; foreach ($form_values as $key => $value) { + //echo ($key); + if ($key == 'dc:title-0') { + $label = $value; + } $index = strrpos($key, '-'); $key = substr($key, 0, $index); $test = substr($key, 0, 2); @@ -400,6 +405,13 @@ class formClass { } } + // Save the title + if ( $label != null ) + { + $object = new Fedora_Item($form_values['pid']); + $object->modify_object($label); + } + $dom->appendChild($oai); if (!$client) { @@ -498,7 +510,7 @@ class formClass { '#title' => t('Content models available'), '#options' => $potential_models, '#default_value' => $selected_model, - '#description' => t('Content models define datastream composition, relationships between this and other content models, and the mandatory behaviors associated with each digital object.
Additional information may be found here. '), + '#description' => t('Content models define datastream composition, relationships between this and other content models, and the mandatory behaviors associated with each digital object.
Additional information may be found here.'), ), ), 'collection_pid' => array( @@ -581,6 +593,8 @@ class formClass { if (!$this->canShowIngestForm($collection_pid)) { return FALSE; } + + drupal_set_title($collection_label); if (module_exists('islandora_content_model_forms')) { module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm'); try { diff --git a/plugins/FormBuilder.inc b/plugins/FormBuilder.inc index cd9dc4a9..715ca6af 100644 --- a/plugins/FormBuilder.inc +++ b/plugins/FormBuilder.inc @@ -95,7 +95,7 @@ class FormBuilder { try { $xml = new SimpleXMLElement($policyStreamDoc); } catch (Exception $e) { - watchdog(t("Fedora_Repository"), t("Problem getting security policy."), NULL, WATCHDOG_ERROR); + watchdog(t("Fedora_Repository"), "Problem getting security policy.", NULL, WATCHDOG_ERROR); drupal_set_message(t('Problem getting security policy: @e', array('@e' => check_plain($e->getMessage()))), 'error'); return FALSE; } @@ -173,7 +173,7 @@ class FormBuilder { $object = Fedora_Item::ingest_from_FOXML($dom); if (!empty($object->pid)) { // drupal_set_message("Item ". l($object->pid, 'fedora/repository/'. $object->pid) . " created successfully.", "status"); - drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($object->pid, 'fedora/repository/' . $object->pid))), "status"); + drupal_set_message(t("Item !pid created successfully.", array('!pid' => l(check_plain($object->pid), 'fedora/repository/' . check_plain($object->pid)))), "status"); } if (!empty($_SESSION['fedora_ingest_files'])) { foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) { diff --git a/plugins/PersonalCollectionClass.inc b/plugins/PersonalCollectionClass.inc index 29c76cfa..9ed6af07 100644 --- a/plugins/PersonalCollectionClass.inc +++ b/plugins/PersonalCollectionClass.inc @@ -75,7 +75,7 @@ class PersonalCollectionClass { try { $xml = new SimpleXMLElement($collectionTemplate); } catch (Exception $e) { - watchdog(t("Fedora_Repository"), t("Problem creating personal collection policy, could not parse collection policy stream."), NULL, WATCHDOG_ERROR); + watchdog(t("Fedora_Repository"), "Problem creating personal collection policy, could not parse collection policy stream.", NULL, WATCHDOG_ERROR); drupal_set_message(t('Problem creating personal collection policy, could not parse collection policy stream: @e', array('@e' => check_plain($e->getMessage()))), 'error'); return FALSE; } diff --git a/plugins/Refworks.inc b/plugins/Refworks.inc index 5e39b3c2..2c86caa7 100644 --- a/plugins/Refworks.inc +++ b/plugins/Refworks.inc @@ -83,7 +83,7 @@ class Refworks { //$dom = dom_import_simplexml($xml);//test to see if it behaves better //$xml = new SimpleXMLElement(trim(file_get_contents($file))); } catch (Exception $e) { - drupal_set_message(t('Error processing Refworks file:') . " " . $e->getMessage()); + drupal_set_message(t('Error processing Refworks file: @message', array('@message' => $e->getMessage()))); return FALSE; } $this->referenceList = array(); @@ -296,7 +296,7 @@ class Refworks { $object = $client->__soapCall('ingest', array( $params )); - watchdog(t("FEDORA_REPOSITORY"), t("Successfully added repository item !pid - !it", array('!pid' => $pid, '!it' => $item_title)), NULL, WATCHDOG_INFO); + watchdog(t("FEDORA_REPOSITORY"), "Successfully added repository item " . $pid . " - ". $item_title, NULL, WATCHDOG_INFO); $deleteFiles = $form_values['delete_file']; //remove files from drupal file system if ($deleteFiles > 0) { diff --git a/plugins/ShowStreamsInFieldSets.inc b/plugins/ShowStreamsInFieldSets.inc index a6e7eaad..9e20ca5a 100644 --- a/plugins/ShowStreamsInFieldSets.inc +++ b/plugins/ShowStreamsInFieldSets.inc @@ -109,7 +109,7 @@ class ShowStreamsInFieldSets { } $dc_html = $objectHelper->getFormattedDC($item); - $dl_link = l('

View Document
', 'fedora/repository/' . $this->pid . '/OBJ', array('html' => TRUE)); + $dl_link = l('

' . t('View Document') .'
', 'fedora/repository/' . $this->pid . '/OBJ', array('html' => TRUE)); $tabset['first_tab']['tabs']['view'] = array( '#type' => 'tabpage', diff --git a/xsl/sparql_to_html.xsl b/xsl/sparql_to_html.xsl index a4a4f934..99045659 100644 --- a/xsl/sparql_to_html.xsl +++ b/xsl/sparql_to_html.xsl @@ -173,7 +173,7 @@ - /fedora/repository//-/ + /fedora/repository/