From 5cb3023204d9c582fe5008aa9730726d3e6629d6 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 6 Mar 2012 12:48:44 -0400 Subject: [PATCH 01/17] Get rid of useless instantiations --- fedora_repository.module | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 1646ce4f..2a0dbde9 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -149,8 +149,7 @@ function fedora_repository_ingest_form_submit(array $form, array &$form_state) { if ($form_state['storage']['xml']) { if (module_exists('islandora_content_model_forms')) { module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm'); - $xml_form = new IngestObjectMetadataForm(); - $xml_form->submit($form, $form_state); + IngestObjectMetadataForm::submit($form, $form_state); } } elseif ($form_state['clicked_button']['#id'] == 'edit-submit') { @@ -812,8 +811,7 @@ function fedora_repository_edit_qdc_form_validate($form, &$form_state) { function fedora_repository_edit_qdc_form_submit($form, &$form_state) { if ($form_state['storage']['xml']) { module_load_include('inc', 'islandora_content_model_forms', 'EditObjectMetadataForm'); - $xml_form = new EditObjectMetadataForm($form_state); - $xml_form->submit($form, $form_state); + EditObjectMetadataForm::submit($form, $form_state); } else { module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); From 417b1ab050d53b194b103c2e1562e0dbfa5a4ccd Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 19 Mar 2012 09:35:53 -0400 Subject: [PATCH 02/17] Handle redirect streams better, and various minor changes. --- CollectionPolicy.inc | 8 ++- ConnectionHelper.inc | 7 ++- ObjectHelper.inc | 37 +++++++++++--- api/fedora_item.inc | 67 +++++++++++++++---------- fedora_repository.module | 60 ++++++++++++++-------- fedora_repository.solutionpacks.inc | 2 +- formClass.inc | 1 + plugins/FedoraObjectDetailedContent.inc | 37 +++++++++++--- 8 files changed, 154 insertions(+), 65 deletions(-) diff --git a/CollectionPolicy.inc b/CollectionPolicy.inc index 9b0af861..71d95a6c 100644 --- a/CollectionPolicy.inc +++ b/CollectionPolicy.inc @@ -44,7 +44,12 @@ class CollectionPolicy extends XMLDatastream { if ($preFetch) { $fedoraItem = new Fedora_Item($pid); - $ds = $fedoraItem->get_datastream_dissemination($dsid); + if (array_key_exists($dsid, $fedoraItem->get_datastreams_list_as_array())) { + $ds = $fedoraItem->get_datastream_dissemination($dsid); + } + else { //No collection policy stream (of the default name, anyway) + return FALSE; + } } else { $ds = NULL; @@ -55,7 +60,6 @@ class CollectionPolicy extends XMLDatastream { $ret = new CollectionPolicy($ds, $pid, $dsid); } } catch (SOAPException $e) { - $ret = FALSE; } return $ret; diff --git a/ConnectionHelper.inc b/ConnectionHelper.inc index 59f811e2..f34581e3 100644 --- a/ConnectionHelper.inc +++ b/ConnectionHelper.inc @@ -65,10 +65,11 @@ class ConnectionHelper { //anonymous user. We will need an entry in the fedora users.xml file //with the appropriate entry for a username of anonymous password of anonymous try { - $client = new SoapClient($this->_fixURL($url, 'anonymous', 'anonymous'), array( + $client = new SoapClient($url, array( 'login' => 'anonymous', 'password' => 'anonymous', 'exceptions' => $exceptions, + 'authentication' => SOAP_AUTHENTICATION_BASIC )); } catch (SoapFault $e) { drupal_set_message(t('@e', array('@e' => check_plain($e->getMessage())))); @@ -77,10 +78,12 @@ class ConnectionHelper { } else { try { - $client = new SoapClient($this->_fixURL($url, $user->name, $user->pass), array( + $client = new SoapClient($url, array( 'login' => $user->name, 'password' => $user->pass, 'exceptions' => TRUE, + 'authentication' => SOAP_AUTHENTICATION_BASIC, + 'cache_wsdl' => WSDL_CACHE_MEMORY )); } catch (SoapFault $e) { drupal_set_message(t('@e', array('@e' => check_plain($e->getMessage())))); diff --git a/ObjectHelper.inc b/ObjectHelper.inc index e8555635..8ec7bf1c 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -139,7 +139,7 @@ class ObjectHelper { curl_setopt($ch, CURLOPT_USERPWD, "$fedoraUser:$fedoraPass"); // There seems to be a bug in Fedora 3.1's REST authentication, removing this line fixes the authorization denied error. // curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); // return into a variable + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // return into a variable curl_setopt($ch, CURLOPT_URL, $url); @@ -151,7 +151,6 @@ class ObjectHelper { fclose($fp); } else { - header("Content-type: $mimeType"); if ($contentSize > 0) { header("Content-length: $contentSize"); @@ -182,12 +181,38 @@ class ObjectHelper { header('Content-Disposition: attachment; filename="' . $suggestedFileName . '"'); } - if ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { - curl_exec($ch); + curl_setopt($ch, CURLOPT_NOBODY, TRUE); + $curl_out = curl_exec($ch); + if ($curl_out !== FALSE) { + $info = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); + //dd($info, 'effective URL'); + if ($url !== $info) { //Handle redirect streams (the final URL is not the same as the Fedora URL) + + //Add the parameters passed to Drupal, leaving out the 'q' + $query = array(); + parse_str($_SERVER['QUERY_STRING'], $query); + if (isset($query['q'])) { + unset($query['q']); + } + + header('HTTP/1.1 307 Moved Temporarily'); + header('Location: ' . $info . '?' . http_build_query($query)); //Fedora seems to discard the query portion. + } + elseif ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { //If not anonymous, soap is force or we're using HTTPS + //Have the webserver mediate the transfer (download and restream) + + curl_setopt($ch, CURLOPT_NOBODY, FALSE); + curl_setopt($ch, CURLOPT_HTTPGET, TRUE); //CURLOPT_NOBODY sets it to 'HEAD' + $toReturn = curl_exec($ch); + echo $toReturn; + } + else { + header('Location: ' . $url); + } } else { - header('Location: ' . $url); - } + //Curl error... + } } curl_close($ch); } diff --git a/api/fedora_item.inc b/api/fedora_item.inc index afc110bd..79440f5e 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -211,27 +211,39 @@ class Fedora_Item { * @param type $namespaceURI */ function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI) { + dd($this, 'The Fedora_Item'); $ds_list = $this->get_datastreams_list_as_array(); - - if (empty($ds_list['RELS-EXT'])) { - $this->add_datastream_from_string(' - + $f_prefix = 'info:fedora/'; + if (!array_key_exists('RELS-EXT', $ds_list)) { + $rdf_string = << + - ', 'RELS-EXT', 'Fedora object-to-object relationship metadata', 'text/xml', 'X'); + +RDF; + dd($rdf_string, 'RELS-EXT RDF being added'); + $this->add_datastream_from_string($rdf_string, 'RELS-EXT', 'Fedora object-to-object relationship metadata', 'application/rdf+xml', 'X'); + dd('Added'); } + dd('Getting RELS-EXT'); $relsext = $this->get_datastream_dissemination('RELS-EXT'); - - if (substr($object, 0, 12) != 'info:fedora/') { - $object = "info:fedora/$object"; + dd('Got RELS-EXT'); + + if (substr($object, 0, strlen($f_prefix)) !== $f_prefix) { + $object = $f_prefix . $object; } - $relsextxml = new DomDocument(); + $relsextxml = new DOMDocument(); $relsextxml->loadXML($relsext); $description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description'); if ($description->length == 0) { + //XXX: This really shouldn't be done; lower case d doesn't fit the schema. Warn users to fix the data and generators, pending deprecation. $description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'description'); + if ($description->length > 0) { + drupal_set_message(t('RDF with lower case "d" in "description" encountered. Should be uppercase! PID: %pid', array('%pid' => $this->pid)), 'warning'); + } } $description = $description->item(0); @@ -241,7 +253,7 @@ class Fedora_Item { $newrel->setAttribute('rdf:resource', $object); $description->appendChild($newrel); - $this->modify_datastream_by_value($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml'); + $this->modify_datastream_by_value($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); //print ($description->dump_node()); /* $params = array( 'pid' => $this->pid, @@ -287,7 +299,7 @@ class Fedora_Item { break; } - if (substr($object, 0, 12) != 'info:fedora/') { + if (!empty($object) && substr($object, 0, 12) != 'info:fedora/') { $object = "info:fedora/$object"; } @@ -297,7 +309,7 @@ class Fedora_Item { $rels = $relsextxml->getElementsByTagNameNS($namespaceURI, $relationship); if (!empty($rels)) { foreach ($rels as $rel) { - if ($rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) { + if (empty($object) || $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) { $rel->parentNode->removeChild($rel); $modified = TRUE; } @@ -307,7 +319,6 @@ class Fedora_Item { $this->modify_datastream_by_value($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml'); } return $modified; - //print ($description->dump_node()); } /** @@ -743,8 +754,9 @@ class Fedora_Item { * @return type */ function url() { - global $base_url; - return $base_url . '/fedora/repository/' . $this->pid . (!empty($this->objectProfile) ? '/-/' . drupal_urlencode($this->objectProfile->objLabel) : ''); + return url('fedora/repository/' . $this->pid . (!empty($this->objectProfile) ? '/-/' . drupal_urlencode($this->objectProfile->objLabel) : ''), array( + 'absolute' => TRUE + )); } /** @@ -780,9 +792,14 @@ class Fedora_Item { * @param type $foxml * @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"); + static function ingest_from_FOXML(DOMDocument $foxml) { + $params = array( + 'objectXML' => $foxml->saveXML(), + 'format' => 'info:fedora/fedora-system:FOXML-1.1', + 'logMessage' => 'Fedora Object Ingested' + ); $object = self::soap_call('ingest', $params); + dd($object, 'Soap return'); return new Fedora_Item($object->objectPID); } @@ -982,25 +999,23 @@ class Fedora_Item { } } - $root_element = $foxml->createElement("foxml:digitalObject"); + $root_element = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:digitalObject"); $root_element->setAttribute("VERSION", "1.1"); $root_element->setAttribute("PID", $pid); - $root_element->setAttribute("xmlns:foxml", "info:fedora/fedora-system:def/foxml#"); - $root_element->setAttribute("xmlns:xsl", "http://www.w3.org/2001/XMLSchema-instance"); - $root_element->setAttribute("xsl:schemaLocation", "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd"); + $root_element->setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation", "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd"); $foxml->appendChild($root_element); // FOXML object properties section - $object_properties = $foxml->createElement("foxml:objectProperties"); - $state_property = $foxml->createElement("foxml:property"); + $object_properties = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:objectProperties"); + $state_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property"); $state_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#state"); $state_property->setAttribute("VALUE", $state); - $label_property = $foxml->createElement("foxml:property"); + $label_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property"); $label_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#label"); $label_property->setAttribute("VALUE", $label); - $owner_property = $foxml->createElement("foxml:property"); + $owner_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property"); $owner_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#ownerId"); $owner_property->setAttribute("VALUE", $owner); @@ -1009,7 +1024,7 @@ class Fedora_Item { $object_properties->appendChild($owner_property); $root_element->appendChild($object_properties); $foxml->appendChild($root_element); - + //dd($foxml->saveXML(), 'XML to ingest'); Worked on 2012/01/16 return $foxml; } diff --git a/fedora_repository.module b/fedora_repository.module index 1646ce4f..f8b3f733 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -146,14 +146,13 @@ function fedora_repository_ingest_form_submit(array $form, array &$form_state) { $form_state['submitted'] = FALSE; return; } - if ($form_state['storage']['xml']) { - if (module_exists('islandora_content_model_forms')) { - module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm'); - $xml_form = new IngestObjectMetadataForm(); - $xml_form->submit($form, $form_state); - } + //ddebug_backtrace(); + if ($form_state['storage']['xml'] && module_exists('islandora_content_model_forms')) { + module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm'); + $xml_form = new IngestObjectMetadataForm(); + $xml_form->submit($form, $form_state); } - elseif ($form_state['clicked_button']['#id'] == 'edit-submit') { + elseif (strpos($form_state['clicked_button']['#id'], 'edit-submit') === 0) { global $base_url; module_load_include('inc', 'fedora_repository', 'CollectionClass'); module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); @@ -188,7 +187,7 @@ function fedora_repository_ingest_form_submit(array $form, array &$form_state) { } if ($redirect) { - $form_state['redirect'] = ($err) ? ' ' : $base_url . "/fedora/repository/{$form_state['values']['collection_pid']}"; + $form_state['redirect'] = ($err) ? ' ' : url("fedora/repository/{$form_state['values']['collection_pid']}"); } } } @@ -205,7 +204,7 @@ function fedora_repository_ingest_form_validate($form, &$form_state) { $form_state['submitted'] = FALSE; return; } - if ($form_state['clicked_button']['#id'] == 'edit-submit' && $form_state['ahah_submission'] != 1) { + if (strpos($form_state['clicked_button']['#id'], 'edit-submit') === 0 && $form_state['ahah_submission'] != 1) { switch ($form_state['storage']['step']) { case 1: $form_state['storage']['step']++; @@ -286,7 +285,8 @@ function fedora_repository_ingest_form(&$form_state, $collection_pid, $collectio $ingestForm = new formClass(); $form_state['storage']['content_model'] = $content_model; $form_state['storage']['collection_pid'] = $collection_pid; - return $ingestForm->createIngestForm($collection_pid, $collection_label, $form_state); + $form = $ingestForm->createIngestForm($collection_pid, $collection_label, $form_state); + return $form; } /** @@ -1706,22 +1706,22 @@ function fedora_repository_required_fedora_objects() { 'pid' => 'islandora:collectionCModel', 'label' => 'Islandora Collection Content Model', 'dsid' => 'ISLANDORACM', - 'datastream_file' => "$module_path/content_models/COLLECTIONCM.xml", + 'datastream_file' => "./$module_path/content_models/COLLECTIONCM.xml", 'dsversion' => 2, - 'cmodel' => 'fedora-system:ContentModel-3.0', + 'cmodel' => 'info:fedora/fedora-system:ContentModel-3.0', ), array( 'pid' => 'islandora:root', 'label' => 'Islandora Top-level Collection', - 'cmodel' => 'islandora:collectionCModel', + 'cmodel' => 'info:fedora/islandora:collectionCModel', 'datastreams' => array( array( 'dsid' => 'COLLECTION_POLICY', - 'datastream_file' => "$module_path/collection_policies/COLLECTION-COLLECTION POLICY.xml", + 'datastream_file' => "./$module_path/collection_policies/COLLECTION-COLLECTION POLICY.xml", ), array( 'dsid' => 'TN', - 'datastream_file' => "$module_path/images/Gnome-emblem-photos.png", + 'datastream_file' => "./$module_path/images/Gnome-emblem-photos.png", 'mimetype' => 'image/png', ), ), @@ -2152,23 +2152,30 @@ function fedora_repository_display_schema($file) { 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'); + dd($object, 'Object array'); if (!empty($object) && is_array($object)) { $pid = $object['pid']; if (!valid_pid($pid)) { return NULL; } // Does the object exist? If so, purge it. + dd("About to test existence of PID: $pid"); $item = new Fedora_Item($pid); if ($item->exists()) { + dd(' Found'); $item->purge(t('Remove during re-install batch job')); + dd(' Purged'); } + $new_item = NULL; //Need to have this a couple places... (After trying from FOXML and later for individual DSs) + $datastreams = array(); //Seems like this might be getting messed up due to scope? + // Ingest the object from the source file. if (!empty($object['foxml_file'])) { $foxml_file = $object['foxml_file']; $new_item = Fedora_Item::ingest_from_FOXML_file($foxml_file); if ($new_item->exists()) { -// Batch operation was successful. +// Batch operation was successful; can still add additional DSs, though $context['message'][] = "$new_item->pid installed."; } } @@ -2184,18 +2191,29 @@ function fedora_repository_batch_reingest_object($object, &$context) { $datastreams = $object['datastreams']; } - 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); - } + $label = !empty($object['label']) ? $object['label'] : ''; + if (!isset($new_item)) { + dd(' Not found, creating'); + $new_item = Fedora_Item::ingest_new_item($pid, 'A', $label); + dd(' Created'); + } + elseif (!empty($label)) { + $new_item->modify_object($label); + } + + if (isset($new_item)) { if (!empty($object['cmodel'])) { + dd(' relating to cmodel'); $new_item->add_relationship('hasModel', $object['cmodel'], FEDORA_MODEL_URI); + dd(' related to cmodel'); } if (!empty($object['parent'])) { + dd(' adding parent'); $new_item->add_relationship('isMemberOfCollection', $object['parent']); + dd(' parent added'); } foreach ($datastreams as $ds) { + dd("trying to add ds: {$ds['dsid']}"); if ($ds['dsid'] == 'DC') { $new_item->modify_datastream_by_value(file_get_contents($ds['datastream_file']), $ds['dsid'], $ds['label'], 'text/xml'); } diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index 756f8bf0..1c813b57 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -109,7 +109,7 @@ function fedora_repository_solution_pack_form(&$form_state, $solution_pack_modul $object_status = 'Missing datastream'; break; } - if (isset($ds['dsversion'])) { + elseif (isset($ds['dsversion'])) { // Check if the datastream is versioned and needs updating. $installed_version = fedora_repository_get_islandora_datastream_version($item, $ds['dsid']); $available_version = fedora_repository_get_islandora_datastream_version(NULL, NULL, $ds['datastream_file']); diff --git a/formClass.inc b/formClass.inc index 86a5128f..27b24948 100644 --- a/formClass.inc +++ b/formClass.inc @@ -602,6 +602,7 @@ class formClass { $form = new IngestObjectMetadataForm(); return $form->create($collection_pid, $collection_label, $form_state); } catch (Exception $e) { + dd('An error occured; reverting to QDC form...'); $form_state['storage']['xml'] = FALSE; // An error occured revert back to the QDC Form. } } diff --git a/plugins/FedoraObjectDetailedContent.inc b/plugins/FedoraObjectDetailedContent.inc index 55a3d31c..9283acb2 100644 --- a/plugins/FedoraObjectDetailedContent.inc +++ b/plugins/FedoraObjectDetailedContent.inc @@ -43,6 +43,7 @@ class FedoraObjectDetailedContent { '#type' => 'tabpage', '#title' => t('Object Details'), '#selected' => $details_selected, + '#weight' => 100, //XXX: Make the weight configurable? ); $tabset['fedora_object_details']['tabset'] = array( '#type' => 'tabset', @@ -51,12 +52,28 @@ class FedoraObjectDetailedContent { $ds_list = $objectHelper->get_formatted_datastream_list($this->pid, NULL, $this->item); - - $tabset['fedora_object_details']['tabset']['view'] = array( - '#type' => 'tabpage', - '#title' => t('View'), - '#content' => $dc_html . $ds_list . $purge_form, - ); + $i = 0; + if (fedora_repository_access(OBJECTHELPER :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) { + $tabset['fedora_object_details']['tabset']['view'] = array( + '#type' => 'tabpage', + '#title' => t('View'), + 'dc' => array( + '#type' => 'markup', + '#value' => $dc_html, //XXX: This could easily be done in Drupal, instead of using an XSL + '#weight' => $i++ + ), + 'list' => array( + '#type' => 'markup', + '#value' => $ds_list, //XXX: The function called here could be cleaned up a fair bit as well... + '#weight' => $i++ + ), + 'purge' => array( + '#type' => 'markup', + '#value' => $purge_form, + '#weight' => $i++ + ) + ); + } if (fedora_repository_access(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $this->pid, $user)) { $editform = drupal_get_form('fedora_repository_edit_qdc_form', $this->pid, 'DC'); @@ -68,7 +85,13 @@ class FedoraObjectDetailedContent { ); } - return $tabset; + $ts = $tabset['fedora_object_details']['tabset']; + if (array_key_exists('view', $ts) || array_key_exists('edit', $ts)) { + return $tabset; + } + else { + return array(); + } } } From 972e97d498fc0d48a635189eeed388e3260c3b15 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 19 Mar 2012 12:39:17 -0300 Subject: [PATCH 03/17] Comment out debug lines. --- api/fedora_item.inc | 12 ++++++------ fedora_repository.module | 23 ++++++++++++----------- formClass.inc | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 741c883c..9863816d 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -212,7 +212,7 @@ class Fedora_Item { * @param type $namespaceURI */ function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI) { - dd($this, 'The Fedora_Item'); + //dd($this, 'The Fedora_Item'); $ds_list = $this->get_datastreams_list_as_array(); $f_prefix = 'info:fedora/'; if (!array_key_exists('RELS-EXT', $ds_list)) { @@ -222,14 +222,14 @@ class Fedora_Item { RDF; - dd($rdf_string, 'RELS-EXT RDF being added'); + //dd($rdf_string, 'RELS-EXT RDF being added'); $this->add_datastream_from_string($rdf_string, 'RELS-EXT', 'Fedora object-to-object relationship metadata', 'application/rdf+xml', 'X'); - dd('Added'); + //dd('Added'); } - dd('Getting RELS-EXT'); + //dd('Getting RELS-EXT'); $relsext = $this->get_datastream_dissemination('RELS-EXT'); - dd('Got RELS-EXT'); + //dd('Got RELS-EXT'); if (substr($object, 0, strlen($f_prefix)) !== $f_prefix) { $object = $f_prefix . $object; @@ -835,7 +835,7 @@ RDF; 'logMessage' => 'Fedora Object Ingested' ); $object = self::soap_call('ingest', $params); - dd($object, 'Soap return'); + //dd($object, 'Soap return'); return new Fedora_Item($object->objectPID); } diff --git a/fedora_repository.module b/fedora_repository.module index 822bfda0..fa4d6e25 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -812,7 +812,8 @@ function fedora_repository_edit_qdc_form_validate($form, &$form_state) { function fedora_repository_edit_qdc_form_submit($form, &$form_state) { if ($form_state['storage']['xml']) { module_load_include('inc', 'islandora_content_model_forms', 'EditObjectMetadataForm'); - EditObjectMetadataForm::submit($form, $form_state); + $xml_form = new EditObjectMetadataForm(); + $xml_form->submit($form, $form_state); } else { module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); @@ -2160,12 +2161,12 @@ function fedora_repository_batch_reingest_object($object, &$context) { } // Does the object exist? If so, purge it. - dd("About to test existence of PID: $pid"); + //dd("About to test existence of PID: $pid"); $item = new Fedora_Item($pid); if ($item->exists()) { - dd(' Found'); + //dd(' Found'); $item->purge(t('Remove during re-install batch job')); - dd(' Purged'); + //dd(' Purged'); } $new_item = NULL; //Need to have this a couple places... (After trying from FOXML and later for individual DSs) @@ -2193,9 +2194,9 @@ function fedora_repository_batch_reingest_object($object, &$context) { $label = !empty($object['label']) ? $object['label'] : ''; if (!isset($new_item)) { - dd(' Not found, creating'); + //dd(' Not found, creating'); $new_item = Fedora_Item::ingest_new_item($pid, 'A', $label); - dd(' Created'); + //dd(' Created'); } elseif (!empty($label)) { $new_item->modify_object($label); @@ -2203,17 +2204,17 @@ function fedora_repository_batch_reingest_object($object, &$context) { if (isset($new_item)) { if (!empty($object['cmodel'])) { - dd(' relating to cmodel'); + //dd(' relating to cmodel'); $new_item->add_relationship('hasModel', $object['cmodel'], FEDORA_MODEL_URI); - dd(' related to cmodel'); + //dd(' related to cmodel'); } if (!empty($object['parent'])) { - dd(' adding parent'); + //dd(' adding parent'); $new_item->add_relationship('isMemberOfCollection', $object['parent']); - dd(' parent added'); + //dd(' parent added'); } foreach ((array)$datastreams as $ds) { - dd("trying to add ds: {$ds['dsid']}"); + //dd("trying to add ds: {$ds['dsid']}"); if ($ds['dsid'] == 'DC') { $new_item->modify_datastream_by_value(file_get_contents($ds['datastream_file']), $ds['dsid'], $ds['label'], 'text/xml'); } diff --git a/formClass.inc b/formClass.inc index 12f56b3f..e57f4dba 100644 --- a/formClass.inc +++ b/formClass.inc @@ -601,7 +601,7 @@ class formClass { $form = new IngestObjectMetadataForm(); return $form->create($collection_pid, $collection_label, $form_state); } catch (Exception $e) { - dd('An error occured; reverting to QDC form...'); + //dd('An error occured; reverting to QDC form...'); $form_state['storage']['xml'] = FALSE; // An error occured revert back to the QDC Form. } } From 1c48ace3900b398b633ce27cb80de7904530f4f2 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 29 Mar 2012 11:24:30 -0300 Subject: [PATCH 04/17] Use hook mechanism and improve version acquisition --- fedora_repository.module | 19 +++++++------------ fedora_repository.solutionpacks.inc | 5 +++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index fa4d6e25..18e3bfb5 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -2178,7 +2178,7 @@ function fedora_repository_batch_reingest_object($object, &$context) { $new_item = Fedora_Item::ingest_from_FOXML_file($foxml_file); if ($new_item->exists()) { // Batch operation was successful; can still add additional DSs, though - $context['message'][] = "{$new_item->pid} installed."; + $context['message'][] = t('%pid installed.', array('%pid' => $new_item->pid)); } } @@ -2238,22 +2238,17 @@ function fedora_repository_batch_reingest_object($object, &$context) { */ function fedora_repository_get_islandora_datastream_version($item = NULL, $dsid = NULL, $datastream_file = NULL) { $return = NULL; - if (isset($item)) { + if (!empty($item) && !empty($dsid)) { $doc = simplexml_load_string($item->get_datastream_dissemination($dsid)); } - elseif (isset($datastream_file)) { + elseif (!empty($datastream_file)) { $doc = simplexml_load_file($datastream_file); } - - if (!empty($doc)) { - $attrs = $doc->attributes(); - foreach ($attrs as $name => $value) { - if ($name == 'version') { - $return = (int) $value; - break; - } - } + + if (!empty($doc) && $version = (int)$doc->attributes()->version) { + $return = $version; } + return $return; } diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index e9cc573e..b6c40412 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -114,6 +114,7 @@ function fedora_repository_solution_pack_form(&$form_state, $solution_pack_modul // Check if the datastream is versioned and needs updating. $installed_version = fedora_repository_get_islandora_datastream_version($item, $ds['dsid']); $available_version = fedora_repository_get_islandora_datastream_version(NULL, NULL, $ds['datastream_file']); + if ($available_version > $installed_version) { $needs_update = TRUE; $object_status = 'Out of date'; @@ -165,8 +166,8 @@ function fedora_repository_solution_pack_form_submit($form, &$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'); + //$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'), From b8e88b628695808307c44728cce59c064cddb555 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 29 Mar 2012 11:27:21 -0300 Subject: [PATCH 05/17] Fix tab selection and slight refactoring. --- CollectionClass.inc | 84 +++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 08f669e0..6fa83b63 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -5,6 +5,11 @@ * * Collection Class Class */ + +if (!defined('PHP_VERSION_ID')) { //XXX: This should go elsewhere + $version = explode('.', PHP_VERSION); + define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2])); +} /** * This CLASS caches the streams so once you call a getstream once it will always return @@ -500,10 +505,11 @@ class CollectionClass { */ function showFieldSets($page_number) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - module_load_include('inc', 'fedora_repository', 'CollectionManagement'); - module_load_include('inc', 'fedora_repository', 'BatchIngest'); + module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); + //module_load_include('inc', 'fedora_repository', 'BatchIngest'); //Legacy code? global $base_url; global $user; + $tabset = array(); $query = NULL; $item = new Fedora_Item($this->pid); @@ -513,10 +519,7 @@ class CollectionClass { $results = $this->getRelatedItems($this->pid, $query); $collection_items = $this->renderCollection($results, $this->pid, NULL, NULL, $page_number); - $collection_item = new Fedora_Item($this->pid); - // Check the form post to see if we are in the middle of an ingest operation. - $show_ingest_tab = (!empty($_POST['form_id']) && $_POST['form_id'] == 'fedora_repository_ingest_form'); - $add_to_collection = $this->getIngestInterface(); + //$collection_item = new Fedora_Item($this->pid); //XXX: This didn't seem to be used... $show_batch_tab = FALSE; $policy = CollectionPolicy::loadFromCollection($this->pid, TRUE); @@ -527,39 +530,42 @@ class CollectionClass { if (count($content_models) == 1 && $content_models[0]->pid == "islandora:collectionCModel") { $show_batch_tab = FALSE; } - if (!$show_ingest_tab) { - $view_selected = TRUE; - } - if (!$collection_items) { - $view_selected = FALSE; - $add_selected = TRUE; - } - $view_selected = !$show_ingest_tab; - + + // Check the form post to see if we are in the middle of an ingest operation. + $add_selected = ((!empty($_POST['form_id']) && $_POST['form_id'] == 'fedora_repository_ingest_form') || !$collection_items); + $view_selected = !$add_selected; $tabset['view_tab'] = array( '#type' => 'tabpage', - '#title' => 'View', + '#title' => t('View'), '#selected' => $view_selected, '#content' => $collection_items, + '#tab_name' => 'view-tab', ); - $tabset['add_tab'] = array( - '#type' => 'tabpage', - '#title' => t('Add'), - '#selected' => $add_selected, - // This will be the content of the tab. - '#content' => $add_to_collection, - ); - - if ($show_batch_tab && user_access('create batch process')) { + + $add_to_collection = $this->getIngestInterface(); + if (!empty($add_to_collection)) { + $tabset['add_tab'] = array( + '#type' => 'tabpage', + '#title' => t('Add'), + '#selected' => $add_selected, + // This will be the content of the tab. + '#content' => $add_to_collection, + '#tab_name' => 'add-tab', + ); + } + + if ($show_batch_tab && user_access('create batch process')) { //XXX: Is this not put in by the batch module? $tabset['batch_ingest_tab'] = array( // #type and #title are the minimum requirements. '#type' => 'tabpage', '#title' => t('Batch Ingest'), // This will be the content of the tab. '#content' => drupal_get_form('batch_creation_form', $this->pid, $content_models), + '#tab_name' => 'batch-ingest-tab', ); } + return $tabset; } @@ -622,7 +628,7 @@ class CollectionClass { $pageNumber = 1; } - if (!isset($collectionName)) { + if (empty($collectionName)) { $collectionName = variable_get('fedora_repository_name', 'Collection'); } $xslContent = $this->getXslContent($pid, $path); @@ -636,11 +642,23 @@ class CollectionClass { if ($results->length > 0) { try { $proc = new XsltProcessor(); - $proc->setParameter('', 'collectionPid', $collection_pid); - $proc->setParameter('', 'collectionTitle', $collectionName); - $proc->setParameter('', 'baseUrl', $base_url); - $proc->setParameter('', 'path', $base_url . '/' . $path); - $proc->setParameter('', 'hitPage', $pageNumber); + $options = array( //Could make this the return of a hook? + 'collectionPid' => $collection_pid, + 'collectionTitle' => $collectionName, + 'baseUrl' => $base_url, + 'path' => "$base_url/$path", + 'hitPage' => $pageNumber, + ); + + if (defined('PHP_VERSION_ID') && PHP_VERSION_ID >= 50100) { + $proc->setParameter('', $options); + } + else { + foreach ($options as $name => $value) { + $proc->setParameter('', $name, $value); + } + } + $proc->registerPHPFunctions(); $xsl = new DomDocument(); $xsl->loadXML($xslContent); @@ -657,13 +675,13 @@ class CollectionClass { throw new Exception("Invalid XML."); } } catch (Exception $e) { - drupal_set_message(t('@e', array('@e' => check_plain($e->getMessage()))), 'error'); + drupal_set_message(check_plain($e->getMessage()), 'error'); return ''; } } } else { - drupal_set_message(t("No Objects in this collection or bad query.")); + drupal_set_message(t("No objects in this collection (or bad query).")); } return $objectList; } From 378e060d2fa71ddcd6edb829d3dc0a71d9d62248 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 11 Apr 2012 15:50:49 -0300 Subject: [PATCH 06/17] Allow breadcrumbs to be overridden by CModels --- fedora_repository.module | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 18e3bfb5..30293e0f 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -762,13 +762,6 @@ function fedora_repository_edit_qdc_form(&$form_state, $pid, $dsId = NULL) { $client = $soapHelper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl')); // Check if there is a custom edit metadata function defined in the content model. - - $breadcrumbs = array(); - $objectHelper = new ObjectHelper(); - $objectHelper->getBreadcrumbs($pid, $breadcrumbs); - drupal_set_breadcrumb(array_reverse($breadcrumbs)); - - $output = ''; if (($cm = ContentModel::loadFromObject($pid)) !== FALSE) { $output = $cm->buildEditMetadataForm($pid, $dsId); @@ -1031,6 +1024,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU /** * fedora repository urlencode string + * FIXME: URL-encoding is not the same as HTML/XML encoding... * @param type $str * @return type */ From 16bd36599307790f20950c20a7337d61a799165c Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 11 Apr 2012 15:55:03 -0300 Subject: [PATCH 07/17] Simplify title acquisition logic and remove commented code --- formClass.inc | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/formClass.inc b/formClass.inc index e57f4dba..8648fe20 100644 --- a/formClass.inc +++ b/formClass.inc @@ -69,19 +69,12 @@ class formClass { 'type' => MENU_CALLBACK, 'access arguments' => array('view fedora collection'), ); - $repository_title = variable_get('fedora_repository_title', 'Digital repository'); - if (trim($repository_title) != '') { - $respository_title = t($repository_title); - } - else { - $repository_title = NULL; - } $items['fedora/repository'] = array( - 'title' => $repository_title, + 'title callback' => 'variable_get', + 'title arguments' => array('fedora_repository_title', 'Digital Repository'), 'page callback' => 'repository_page', 'type' => MENU_NORMAL_ITEM, 'access arguments' => array('view fedora collection'), - // 'access' => TRUE ); $items['fedora/repository/service'] = array( @@ -100,8 +93,6 @@ class formClass { $items['fedora/repository/editmetadata'] = array( 'title' => t('Edit metadata'), 'page callback' => 'fedora_repository_edit_qdc_page', - // 'page arguments' => array(1), - //'type' => MENU_LOCAL_TASK, 'type' => MENU_CALLBACK, 'access arguments' => array('edit fedora meta data') ); @@ -123,7 +114,6 @@ class formClass { $items['fedora/repository/purgeObject'] = array( 'title' => t('Purge object'), 'page callback' => 'fedora_repository_purge_object', - // 'type' => MENU_LOCAL_TASK, 'type' => MENU_CALLBACK, 'access arguments' => array('purge objects and datastreams') ); @@ -131,7 +121,6 @@ class formClass { $items['fedora/repository/addStream'] = array( 'title' => t('Add stream'), 'page callback' => 'add_stream', - // 'type' => MENU_LOCAL_TASK, 'type' => MENU_CALLBACK, 'access arguments' => array('add fedora datastreams') ); From 33b0c3b3ce68d9be4f6e72e2535f37c9bb475697 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 11 Apr 2012 15:58:27 -0300 Subject: [PATCH 08/17] Additional error handling, and add wrapp for modifyDatastream Wrapping allows either content or a file to be pushed, independant of the controlGroup... You don't have to know if you need to push by value or reference! --- api/fedora_item.inc | 96 ++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 32 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 9863816d..65ec4751 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -103,9 +103,14 @@ class Fedora_Item { 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'); if (!is_file($datastream_file)) { - drupal_set_message("$datastream_file not found
", 'warning'); + drupal_set_message(t('The datastream file %datastream_file could not found! (or is not a regular file...)', array('%datastream_file' => $datastream_file)), 'warning'); return; } + elseif (!is_readable($datastream_file)) { + drupal_set_message(t('The datastream file %datastream_file could not be read! (likely due to permissions...)', array('%datastream_file' => $datastream_file)), 'warning'); + return; + } + if (empty($datastream_mimetype)) { // Get mime type from the file extension. $mimetype_helper = new MimeClass(); @@ -434,7 +439,7 @@ RDF; * @param type $as_of_date_time * @return type */ - function get_datastream($dsid, $as_of_date_time = "") { + function get_datastream($dsid, $as_of_date_time = '') { $params = array( 'pid' => $this->pid, 'dsID' => $dsid, @@ -530,7 +535,7 @@ RDF; * @return datastream object * get the mimetype size etc. in one shot. instead of iterating throught the datastream list for what we need */ - function get_datastream_info($dsid, $as_of_date_time = "") { + function get_datastream_info($dsid, $as_of_date_time = '') { $params = array( 'pid' => $this->pid, 'dsID' => $dsid, @@ -563,7 +568,7 @@ RDF; // datastream, instead of returning it as an array, only // the single item will be returned directly. We have to // check for this. - if (count($this->datastreams_list->datastreamDef) >= 2) { + if (count($this->datastreams_list->datastreamDef) > 1) { foreach ($this->datastreams_list->datastreamDef as $ds) { if (!is_object($ds)) { print_r($ds); @@ -644,7 +649,7 @@ RDF; try { $relsext = $this->get_datastream_dissemination('RELS-EXT'); } catch (exception $e) { - drupal_set_message(t("Error retrieving RELS-EXT of object $pid"), 'error'); + drupal_set_message(t('Error retrieving RELS-EXT of object %pid.', array('%pid' => $pid)), 'error'); return $relationships; } @@ -668,30 +673,8 @@ RDF; } function get_models() { - $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(); - $mods = $relsextxml->getElementsByTagNameNS(FEDORA_MODEL_URI, '*'); - foreach ($mods as $child) { - if (empty($relationship) || preg_match("/$relationship/", $child->tagName)) { - $relationships[] = array( - 'subject' => $this->pid, - 'predicate' => $child->tagName, - 'object' => substr($child->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource'), 12), - ); - } - } - - return $relationships; + //This is/was formerly just a copy/paste jobbie, without the parameter being passable... + return $this->get_relationships(); } /** @@ -895,6 +878,53 @@ RDF; return self::soap_call('modifyObject', $params, $quiet); } + /** + * Wrap modify by value and reference, so that the proper one gets called in the correct instance. (value if inline XML, reference otherwise) + * + * First tries to treat the passed in value as a filename, tries using as contents second. + * Coerces the data into what is required, and passes it on to the relevant function. + */ + function modify_datastream($filename_or_content, $dsid, $label, $mime_type, $force = FALSE, $logMessage='Modified by Islandora API') { + //Determine if it's inline xml; if it is, modify by value + if ($this->get_datastream($dsid)->controlGroup === 'X') { + $content = ''; + if (is_file($filename_or_content) && is_readable($filename_or_content)) { + $content = file_get_contents($filename_or_content); + } + else { + $content = $filename_or_content; + } + + $this->modify_datastream_by_value($content, $dsid, $label, $mime_type, $force, $logMessage); + } + //Otherwise, write to web-accessible temp file and modify by reference. + else { + $file = ''; + $created_temp = FALSE; + if (is_file($filename_or_content) && is_readable($filename_or_content)) { + $file = $filename_or_content; + } + else { + //Get Drupal temp file + $file = file_directory_path(); + $file = tempnam($file, 'fedora_modification'); //Be careful... Does this return the full path to the file? + //Push contents to file + file_put_contents($file, $filename_or_content); + $created_temp = TRUE; + } + + $file_url = url($file, array( + 'absolute' => TRUE, + )); + + $this->modify_datastream_by_reference($file_url, $dsid, $label, $mime_type, $force, $logMessage); + + if ($created_temp && is_file($file) && is_writable($file)) { + unlink($file); + } + } + } + /** * Modify datastream by reference * @param type $external_url @@ -982,9 +1012,11 @@ RDF; module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); self::$connection_helper = new ConnectionHelper(); } - $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'); + $url = ( + in_array($function, self::$SoapManagedFunctions)? + 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)) { From 899f1fb5ad2bc46142febe4b14c12d5e57a38e21 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 11 Apr 2012 17:01:52 -0300 Subject: [PATCH 09/17] Documentation and improvement of wrapper. --- api/fedora_item.inc | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 65ec4751..b647e514 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -883,6 +883,13 @@ RDF; * * First tries to treat the passed in value as a filename, tries using as contents second. * Coerces the data into what is required, and passes it on to the relevant function. + * + * @param $filename_or_content Either a filename to add, or an string of content. + * @param $dsid The DSID to update + * @param $label A label to withwhich to update the datastream + * @param $mime_type Mimetype for the data being pushed into the datastream + * @param $force Dunno, refer to underlying functions/SOAP interface. We just pass it like a chump. + * @param $logMessage A message for the audit log. */ function modify_datastream($filename_or_content, $dsid, $label, $mime_type, $force = FALSE, $logMessage='Modified by Islandora API') { //Determine if it's inline xml; if it is, modify by value @@ -902,25 +909,24 @@ RDF; $file = ''; $created_temp = FALSE; if (is_file($filename_or_content) && is_readable($filename_or_content)) { - $file = $filename_or_content; + $file = $filename_or_content; + $original_path = $file; + // Temporarily move file to a web-accessible location. + file_copy($file, file_directory_path()); + $created_temp = ($original_path != $file); } else { - //Get Drupal temp file - $file = file_directory_path(); - $file = tempnam($file, 'fedora_modification'); //Be careful... Does this return the full path to the file? - //Push contents to file - file_put_contents($file, $filename_or_content); + //Push contents to a web-accessible file + $file = file_save_data($filename_or_content, file_directory_path()); $created_temp = TRUE; } - $file_url = url($file, array( - 'absolute' => TRUE, - )); + $file_url = file_create_url($file); $this->modify_datastream_by_reference($file_url, $dsid, $label, $mime_type, $force, $logMessage); if ($created_temp && is_file($file) && is_writable($file)) { - unlink($file); + file_delete($file); } } } From 280243ea65a05eb70dfafd780f1397d2320fa4b3 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 11 Apr 2012 17:10:19 -0300 Subject: [PATCH 10/17] Drupal-parsable docs --- api/fedora_item.inc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index b647e514..1063262d 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -879,17 +879,25 @@ RDF; } /** + * Wrap modify by value and reference + * * Wrap modify by value and reference, so that the proper one gets called in the correct instance. (value if inline XML, reference otherwise) * * First tries to treat the passed in value as a filename, tries using as contents second. * Coerces the data into what is required, and passes it on to the relevant function. * - * @param $filename_or_content Either a filename to add, or an string of content. - * @param $dsid The DSID to update - * @param $label A label to withwhich to update the datastream - * @param $mime_type Mimetype for the data being pushed into the datastream - * @param $force Dunno, refer to underlying functions/SOAP interface. We just pass it like a chump. - * @param $logMessage A message for the audit log. + * @param string $filename_or_content + * Either a filename to add, or an string of content. + * @param string $dsid + * The DSID to update + * @param string $label + * A label to withwhich to update the datastream + * @param string $mime_type + * Mimetype for the data being pushed into the datastream + * @param boolean $force + * Dunno, refer to underlying functions/SOAP interface. We just pass it like a chump. + * @param string $logMessage + * A message for the audit log. */ function modify_datastream($filename_or_content, $dsid, $label, $mime_type, $force = FALSE, $logMessage='Modified by Islandora API') { //Determine if it's inline xml; if it is, modify by value From 63b089cedd96d3ad5571ba2a6bb58ca0a1a056b8 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 12 Apr 2012 09:30:32 -0300 Subject: [PATCH 11/17] Allow for literals in add_relationship, and use wrapped modify_datastream Slight improvements, and RELS-EXT does not have to be inline XML (can be managed) --- api/fedora_item.inc | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 1063262d..318ce114 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -212,11 +212,16 @@ class Fedora_Item { /** * 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 string $relationship + * The predicate/relationship tag to add + * @param string $object + * The object to be related to. + * @param string $namespaceURI + * The predicate namespace. + * @param boolean $literal_value + * Whether or not the object should be added as a URI (FALSE) or a literal (TRUE). */ - function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI) { + function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = FALSE) { //dd($this, 'The Fedora_Item'); $ds_list = $this->get_datastreams_list_as_array(); $f_prefix = 'info:fedora/'; @@ -236,7 +241,7 @@ RDF; $relsext = $this->get_datastream_dissemination('RELS-EXT'); //dd('Got RELS-EXT'); - if (substr($object, 0, strlen($f_prefix)) !== $f_prefix) { + if (!$literal_value && strpos($object, $f_prefix) !== 0) { $object = $f_prefix . $object; } @@ -256,10 +261,16 @@ RDF; // Create the new relationship node. $newrel = $relsextxml->createElementNS($namespaceURI, $relationship); - $newrel->setAttribute('rdf:resource', $object); + if ($literal_value) { + $newrel->appendChild($relsextxml->createTextNode($object)); + } + else { + $newrel->setAttribute('rdf:resource', $object); + } $description->appendChild($newrel); - $this->modify_datastream_by_value($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); + + $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); //print ($description->dump_node()); /* $params = array( 'pid' => $this->pid, From 27be8ded87ad814f133fdb9edb3b7df65d6e088a Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 12 Apr 2012 09:38:38 -0300 Subject: [PATCH 12/17] Add 'quiet' parameter to modify_datastream wrapper. --- api/fedora_item.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 318ce114..2079d060 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -909,8 +909,10 @@ RDF; * Dunno, refer to underlying functions/SOAP interface. We just pass it like a chump. * @param string $logMessage * A message for the audit log. + * @param boolean $quiet + * Error suppression? Refer to soap_call for usage (just passed along here). */ - function modify_datastream($filename_or_content, $dsid, $label, $mime_type, $force = FALSE, $logMessage='Modified by Islandora API') { + function modify_datastream($filename_or_content, $dsid, $label, $mime_type, $force = FALSE, $logMessage='Modified by Islandora API', $quiet=FALSE) { //Determine if it's inline xml; if it is, modify by value if ($this->get_datastream($dsid)->controlGroup === 'X') { $content = ''; From 0983d5c05911b8caf75bde1069d82150be1e7518 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 12 Apr 2012 09:40:40 -0300 Subject: [PATCH 13/17] Undo some minor changes... --- fedora_repository.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 30293e0f..45f99d01 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1702,12 +1702,12 @@ function fedora_repository_required_fedora_objects() { 'dsid' => 'ISLANDORACM', 'datastream_file' => "./$module_path/content_models/COLLECTIONCM.xml", 'dsversion' => 2, - 'cmodel' => 'info:fedora/fedora-system:ContentModel-3.0', + 'cmodel' => 'fedora-system:ContentModel-3.0', ), array( 'pid' => 'islandora:root', 'label' => 'Islandora Top-level Collection', - 'cmodel' => 'info:fedora/islandora:collectionCModel', + 'cmodel' => 'islandora:collectionCModel', 'datastreams' => array( array( 'dsid' => 'COLLECTION_POLICY', From 04a0a763786020b950e6c22943bcc142bad0f289 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 12 Apr 2012 10:11:34 -0300 Subject: [PATCH 14/17] Produce a purge_relationships function which is more similar to add_relationship --- api/fedora_item.inc | 48 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 2079d060..02d45907 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -211,7 +211,9 @@ class Fedora_Item { /** * Add a relationship string to this object's RELS-EXT. + * * does not support rels-int yet. + * * @param string $relationship * The predicate/relationship tag to add * @param string $object @@ -284,8 +286,52 @@ RDF; */ } + /** + * Purge/delete relationships string from this object's RELS-EXT. + * + * does not support rels-int yet. + * + * @param string $relationship + * The predicate/relationship tag to add + * @param string $object + * The object to be related to. (NULL/value for which empty() evaluates to true will remove all relations of the given type, ignoring $literal_value) + * @param string $namespaceURI + * The predicate namespace. + * @param boolean $literal_value + * Whether or not the object should be added as a URI (FALSE) or a literal (TRUE). + */ + function purge_relationships($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = FALSE) { + $relsext = $this->get_datastream_dissemination('RELS-EXT'); + + $relsextxml = new DomDocument(); + $relsextxml->loadXML($relsext); + $modified = FALSE; + $rels = $relsextxml->getElementsByTagNameNS($namespaceURI, $relationship); + if (!empty($rels)) { + foreach ($rels as $rel) { + if ( //If either no object is specified, or the object matches (in either the literal or URI case), remove this node from it's parent, and mark as changed. + empty($object) || + (!$literal_value && $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) || + ($literal_value && $rel->textContent == $object)) { + $rel->parentNode->removeChild($rel); + $modified = TRUE; + } + } + } + + //Save changes. + if ($modified) { + $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml'); + } + + //Return whether or not we've introduced any changes. + return $modified; + } + /** * Removes the given relationship from the item's RELS-EXT and re-saves it. + * @deprecated + * Dropped in favour of purge_relationships, which follows the same paradigm as add_relationship. This function tries to figure out the predicate URI based on the prefix/predicate given, which requires specific naming... * @param string $relationship * @param string $object */ @@ -337,7 +383,7 @@ RDF; } } if ($modified) { - $this->modify_datastream_by_value($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml'); + $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml'); } return $modified; } From 1c568f760d08a70343a82867dfdc50a0ae9b172e Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 12 Apr 2012 10:20:16 -0300 Subject: [PATCH 15/17] Remove unnecessary comments --- api/fedora_item.inc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 02d45907..d107a844 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -234,14 +234,10 @@ class Fedora_Item { RDF; - //dd($rdf_string, 'RELS-EXT RDF being added'); $this->add_datastream_from_string($rdf_string, 'RELS-EXT', 'Fedora object-to-object relationship metadata', 'application/rdf+xml', 'X'); - //dd('Added'); } - //dd('Getting RELS-EXT'); $relsext = $this->get_datastream_dissemination('RELS-EXT'); - //dd('Got RELS-EXT'); if (!$literal_value && strpos($object, $f_prefix) !== 0) { $object = $f_prefix . $object; @@ -292,13 +288,15 @@ RDF; * does not support rels-int yet. * * @param string $relationship - * The predicate/relationship tag to add + * The predicate/relationship tag to delete * @param string $object * The object to be related to. (NULL/value for which empty() evaluates to true will remove all relations of the given type, ignoring $literal_value) * @param string $namespaceURI * The predicate namespace. * @param boolean $literal_value - * Whether or not the object should be added as a URI (FALSE) or a literal (TRUE). + * Whether or not the object should be looked for as a URI (FALSE) or a literal (TRUE). + * @return boolean + * Whether or not this operation has produced any changes in the RELS-EXT */ function purge_relationships($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = FALSE) { $relsext = $this->get_datastream_dissemination('RELS-EXT'); @@ -330,6 +328,7 @@ RDF; /** * Removes the given relationship from the item's RELS-EXT and re-saves it. + * * @deprecated * Dropped in favour of purge_relationships, which follows the same paradigm as add_relationship. This function tries to figure out the predicate URI based on the prefix/predicate given, which requires specific naming... * @param string $relationship @@ -1165,7 +1164,6 @@ RDF; $object_properties->appendChild($owner_property); $root_element->appendChild($object_properties); $foxml->appendChild($root_element); - //dd($foxml->saveXML(), 'XML to ingest'); Worked on 2012/01/16 return $foxml; } From aa7029a2f22312252e88b48b0a81f9f95017dbd4 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 12 Apr 2012 17:02:29 -0300 Subject: [PATCH 16/17] Fix parameters to variable_get. Fool was I to think it was originally trying to get the correct variable (fedora_repository_title; actually should be fedora_repository_name) --- formClass.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/formClass.inc b/formClass.inc index 8648fe20..e6a3523b 100644 --- a/formClass.inc +++ b/formClass.inc @@ -70,8 +70,9 @@ class formClass { 'access arguments' => array('view fedora collection'), ); $items['fedora/repository'] = array( + 'title' => '', 'title callback' => 'variable_get', - 'title arguments' => array('fedora_repository_title', 'Digital Repository'), + 'title arguments' => array('fedora_repository_name', 'Digital Repository'), 'page callback' => 'repository_page', 'type' => MENU_NORMAL_ITEM, 'access arguments' => array('view fedora collection'), From a8b45fb6d73251008a62696363d0e7bcb1b7856d Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 13 Apr 2012 08:59:05 -0300 Subject: [PATCH 17/17] Reindent query. --- ObjectHelper.inc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 81d56d4e..a9358df0 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -955,14 +955,14 @@ class ObjectHelper { } else { $query_string = 'select $parentObject $title $content from <#ri> - where ( $title - and $parentObject $content - and ( $parentObject - or $parentObject - or $parentObject) - and $parentObject ) - minus $content - order by $title desc'; + where ( $title + and $parentObject $content + and ( $parentObject + or $parentObject + or $parentObject) + and $parentObject ) + minus $content + order by $title desc'; $query_string = htmlentities(urlencode($query_string)); $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');