From 56b1d21f499885fb09f2ee36d1610cf702252dac Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 13 Feb 2012 15:02:19 -0400 Subject: [PATCH 01/29] Fixed coding issues --- fedora_repository.module | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 00201ec9..83532ead 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,7 +246,7 @@ 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 ' . + 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))); file_delete($file); return; @@ -505,7 +505,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; } From a4a846e90a7ac2e74006690beee663785167f867 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 13 Feb 2012 15:10:32 -0400 Subject: [PATCH 02/29] Fixed t tags --- fedora_repository.module | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 83532ead..0e8e25fc 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -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; } From 9babc676d8d3e814607e508c26e13c91468fe674 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 13 Feb 2012 15:11:54 -0400 Subject: [PATCH 03/29] Fixed t tags --- fedora_repository.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 0e8e25fc..aaad2c4c 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -247,8 +247,8 @@ 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 . ') ' . + t('The uploaded file\'s mimetype') . + ' (' . $dformat . ') ' . t('is not associated with this Content Model. The allowed types are') . ' ' . implode(' ', $allowedMimeTypes)); file_delete($file); From fb41e231b7ff86b513a6a1cf2ec149d534bd272e Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 13 Feb 2012 15:17:08 -0400 Subject: [PATCH 04/29] Fixed formBuilder --- plugins/FormBuilder.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) { From 039e77b41289eabf86b38336ab05dcb8b6b37d50 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 13 Feb 2012 15:31:26 -0400 Subject: [PATCH 05/29] Fixed Refworks --- plugins/Refworks.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) { From 5d771e78b65b46f396e612f9463a473ff0c8e4cd Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 13 Feb 2012 15:35:17 -0400 Subject: [PATCH 06/29] Fixed ShowStreamsInFieldSets --- plugins/ShowStreamsInFieldSets.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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', From 129cb21079e62473791f94c54fb18b3f4ed18206 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 13 Feb 2012 15:42:15 -0400 Subject: [PATCH 07/29] Fixed more i18n errors --- ObjectHelper.inc | 2 +- SecurityClass.inc | 6 +++--- formClass.inc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 313d2159..8f58a3ab 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -963,7 +963,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/formClass.inc b/formClass.inc index be5ef9d2..1c8d2f84 100644 --- a/formClass.inc +++ b/formClass.inc @@ -498,7 +498,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( From cd234314305b934cab92f5b8a1ca0e57a550d762 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 13 Feb 2012 15:46:09 -0400 Subject: [PATCH 08/29] Fixed more i18n errors --- CollectionClass.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 6c5fd8f5..96eca6f0 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -343,7 +343,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; } } @@ -463,7 +463,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); From dbacca19be6e06da6ba80b4b9d75434acbaa1b84 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 13 Feb 2012 16:34:33 -0400 Subject: [PATCH 09/29] Fixed more i18n errors --- fedora_repository.solutionpacks.inc | 4 ++-- plugins/PersonalCollectionClass.inc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index fb09528d..756f8bf0 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -181,7 +181,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" => $name))); } } @@ -196,7 +196,7 @@ 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@name", array("@cm" => $content_model, "@name"=>$name))); } } 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; } From 67007c80dedd0b62e20158f0f43956cb00cc788f Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Tue, 14 Feb 2012 10:34:13 -0400 Subject: [PATCH 10/29] Created a move to trash option asdf removed breadcrumbs for a test setback to default playing with the menu playing with the menu playing with the menu playing with the menu playing with the menu cleanup Removed ALL limits on collections remove testing line --- CollectionClass.inc | 3 --- api/fedora_item.inc | 28 ++++++++++++++++++++++++++++ fedora_repository.module | 1 + formClass.inc | 2 ++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index c5029333..71710d78 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -67,9 +67,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 = 10000; - } if (!isset($offset)) { $offset = 0; } diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 2a70010a..3018d614 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -635,6 +635,28 @@ 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 + ); + + // Send message to mark the object deleted + return self::soap_call('modifyObject', $params, $quiet); + } /** * Removes this object form the repository. @@ -643,12 +665,18 @@ class Fedora_Item { * @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); } diff --git a/fedora_repository.module b/fedora_repository.module index aaad2c4c..f3412b54 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1011,6 +1011,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(); diff --git a/formClass.inc b/formClass.inc index 1c8d2f84..b3972087 100644 --- a/formClass.inc +++ b/formClass.inc @@ -581,6 +581,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 { From abb065f7e3512131ddc08330bb3b421d4c8eb7b4 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Wed, 15 Feb 2012 16:37:16 -0400 Subject: [PATCH 11/29] Fixed collection renaming --- formClass.inc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/formClass.inc b/formClass.inc index b3972087..86a5128f 100644 --- a/formClass.inc +++ b/formClass.inc @@ -379,7 +379,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 +406,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) { From e9291a96c37ca248188bd698087c779eb333673c Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Thu, 16 Feb 2012 12:07:45 -0400 Subject: [PATCH 12/29] Added a new api --- newapi/Cache.php | 76 ++++++++++ newapi/Configuration.php | 58 ++++++++ newapi/IslandoraModule.php | 37 +++++ newapi/Repository.php | 264 ++++++++++++++++++++++++++++++++++ newapi/Search.php | 37 +++++ newapi/models/DataObject.php | 42 ++++++ newapi/models/ObjectModel.php | 119 +++++++++++++++ newapi/models/SPO.php | 75 ++++++++++ 8 files changed, 708 insertions(+) create mode 100644 newapi/Cache.php create mode 100644 newapi/Configuration.php create mode 100644 newapi/IslandoraModule.php create mode 100644 newapi/Repository.php create mode 100644 newapi/Search.php create mode 100644 newapi/models/DataObject.php create mode 100644 newapi/models/ObjectModel.php create mode 100644 newapi/models/SPO.php diff --git a/newapi/Cache.php b/newapi/Cache.php new file mode 100644 index 00000000..906fe804 --- /dev/null +++ b/newapi/Cache.php @@ -0,0 +1,76 @@ +objectList[$object->getId()])) + { + $this->objectList[$object->getId()] = array(); + } + + $this->objectList[$object->getId()]['checksum'] = sha1(serialize($object)); + $this->objectList[$object->getId()]['object'] = $object; + } + + /** + * Check to see if the object has been updated + * @param ObjectModel $object + */ + public function hasChanged(ObjectModel &$object) + { + // Is the object even cached + if ( !isset($this->objectList[$object->getId()])) + { + return false; + } + + // Does it have the same checksum + if ($this->objectList[$object->getId()]['checksum'] == sha1(serialize($object)) ) + { + return true; + } + + // If they were the same then it would have already exited + return false; + } + + /** + * Get object from the cache. Returns null if not found. + * @param type $id + */ + public function getObject($id) + { + // Is the object cached + if ( isset($this->objectList[$id]['object'] ) ) { + + // Return the object from the cache + return $this->objectList[$id]['object']; + } + + // Object wasn't found so return null + return null; + } + + /** + * Remove the object from the cache + * @param type $id + */ + public function deleteObject($id) + { + // Unset it from the array + unset( $this->objectList[$id]); + } +} + +?> diff --git a/newapi/Configuration.php b/newapi/Configuration.php new file mode 100644 index 00000000..5f939715 --- /dev/null +++ b/newapi/Configuration.php @@ -0,0 +1,58 @@ +$baseUrl = $base_url; + $this->$port = $port; + } + + /** + * Get the base url + * @return type + */ + public function getBaseURL() + { + return $this->$baseUrl; + } + + /** + * Set the base url + * @param type $url + */ + public function setBaseURL($url) + { + $this->$baseUrl = $url; + } + + /** + * Get the port + * @return type + */ + public function getPort() + { + return $this->$port; + } + + /** + * Set the port + * @param type $port + */ + public function setPort($port) + { + $this->$port = $port; + } +} + +?> diff --git a/newapi/IslandoraModule.php b/newapi/IslandoraModule.php new file mode 100644 index 00000000..8183415a --- /dev/null +++ b/newapi/IslandoraModule.php @@ -0,0 +1,37 @@ +repository = new Repository(new Configuration("127.0.0.1", 8080), new Search, new Cache()); + } + + /** + * Get the repository singleton + * @return type + */ + public static function instance() + { + if ( self::instance == null ) + { + $className = __CLASS__; + self::$instance = new $className; + // get_called_class only works in 5.3 + } + + // Return the link to the repository + return self::$instance->repository; + } +} + +?> diff --git a/newapi/Repository.php b/newapi/Repository.php new file mode 100644 index 00000000..cfc34e6c --- /dev/null +++ b/newapi/Repository.php @@ -0,0 +1,264 @@ +setConfig($config); + $this->setSearch($search); + $this->setCache($cache); + } + + /** + * Get the configuration implementation + * @return type + */ + public function getConfig() + { + return $this->config; + } + + /** + * Get the search implementation + * @return type + */ + public function getSearch() + { + return $this->search; + } + + /** + * Get the cache implementation + * @return type + */ + public function getCache() + { + return $this->cache; + } + + /** + * Set the configuration implementation + * @param Configuration $config + */ + public function setConfig(Configuration &$config) + { + if ( $config == null ) + { + throw new Exception("Config implementation can't be null"); + } + $this->config = $config; + } + + /** + * Set the search implementation + * @param Search $search + */ + public function setSearch(Search &$search) + { + if ( $search == null ) + { + throw new Exception("Search implementation can't be null"); + } + $this->search = $search; + } + + /** + * Set the cache implementation + * @param Cache $cache + */ + public function setCache(Cache &$cache) + { + if ( $cache == null ) + { + throw new Exception("Cache implementation can't be null"); + } + $this->cache = $cache; + } + + /** + * Get the object from the repo + * @param type $id + */ + public function loadObject($id, $cache=true) + { + // Check to see if its already cached + if ( $this->getCache()->getObject( $id ) && $cache = true) + { + // Return the cached object + return $this->getCache()->getObject( $id ); + } + + // Create the request + $results = $this->makeRequest( '/objects/' .$id ); + + // Return the object model + return unserialize($results); + } + + /** + * Save an object to the repository + * @param ObjectModel $model + * @param type $force + */ + public function saveObject(ObjectModel $model, $force=false) + { + // Has the object been created at all + if ( $model->getId() == null ) { + + // Get the next free persistent id + $id = $this->makeRequest( '/objects/nextPID' ); + + // Set the id on the model + $model->setId($id); + + } + + // If it hasn't changed then done't save unless it's forced + if ( ! $force && ! $this->getCache()->hasChanged($model) ) + { + return; + } + + // Add the object to the cache so everybody has the new copy + $this->getCache()->addObject($model); + + // Post the serialized model to the object endpoint + $this->makeRequest('/objects', $this->serialize($model)); + } + + /** + * Find an object using a search term + * @param type $term + * @return type + */ + public function findObjectByTerm($term) + { + // Create results + $results = $this->makeRequest('/objects?terms=' . $term); + + // Do something with results + return $results; + } + + /** + * Find an object with a query + * @param type $query + * @return type + */ + public function findObjectWithQuery($query) + { + // Create results + $results = $this->makeRequest('/objects?query=' . $term); + + // Do something with results + return $results; + } + + /** + * Search the repository using either a SPO or an array of SPOs + * @param type $query + */ + public function SearchSPO($SPO) + { + // Search + $results = $this->getSearch()->SearchSPO($SPO); + + // Do something with the results + return $results; + } + + /** + * Unserialize the object from foxml + * @param type $xml + * @return \ObjectModel + */ + protected function unserialize($xml) + { + // Create the object model + $model = new ObjectModel(); + + // Do something with the xml + $xml = $xml; + + // Return the model; + return $model; + } + + /** + * Serialize the object to foxml + * @param ObjectModel $model + * @return string + */ + protected function serialize(ObjectModel $model) + { + // Do something with the model + serialize($model); + + // return a string + return ""; + } + + /** + * Make a request + * @param type $request + * @return type + */ + private function makeRequest($request, array $postData = null, $responseCode=200, $format="xml") + { + // Check to see if we already have parameters + $pos = strpos($request, "?"); + if ($pos === false) { + $request.="?format=".$format; + } else { + $request.="&format=".$format; + } + + // Initialize Curl + $curl = curl_init(); + + // Set all the options + curl_setopt($curl, CURLOPT_URL, $this->getConfig()->getBaseURL() . $request); + curl_setopt($curl, CURLOPT_PORT , $this->getConfig()->getPort() ); + curl_setopt($curl, CURLOPT_VERBOSE, 1); + // If we have post data then append that + if ( $postData ) { + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } + + // Execute the curl call + $results = curl_exec($curl); + + // Check for an error + if( ! curl_errno($curl) ) { + + // Get information regarding the curl connection + $info = curl_getinfo($curl); + + // Check the response code + if ( $info['http_code'] != $responseCode ) + { + var_dump($results); + var_dump($info); + throw new Exception("Curl request failed"); + } else { + return $results; + } + } + + // Close connection + curl_close($curl); + + } // Close makeRequest + +} + + +?> diff --git a/newapi/Search.php b/newapi/Search.php new file mode 100644 index 00000000..406a68e5 --- /dev/null +++ b/newapi/Search.php @@ -0,0 +1,37 @@ +getSubject() . " " . $spo->getPredicate() . " " . $spo->getObject() . ", "; + } + // Strip off the extra comma + $queryString = substr($queryString, '', -2); + } + else { + $queryString .= $SPO->getSubject() . " " . $SPO->getPredicate() . " " . $SPO->getObject(); + } + + // Do a search + $results = ""; + + // Return results; + return $results; + } +} + +?> diff --git a/newapi/models/DataObject.php b/newapi/models/DataObject.php new file mode 100644 index 00000000..55af4062 --- /dev/null +++ b/newapi/models/DataObject.php @@ -0,0 +1,42 @@ +id; + } + + /** + * Set the idea if not already set + * @param type $id + * @throws Exception + */ + public function setId($id) + { + if ( $pid != null ) + { + throw new Exception("PID can't be changed"); + } + $this->id = $pid; + } + + /** + * Add the data from a file ( example ) + */ + public function addDataFromFile() + { + + } +} + +?> diff --git a/newapi/models/ObjectModel.php b/newapi/models/ObjectModel.php new file mode 100644 index 00000000..3ceb6da1 --- /dev/null +++ b/newapi/models/ObjectModel.php @@ -0,0 +1,119 @@ +id; + } + + /** + * Set the idea if not already set + * @param type $id + * @throws Exception + */ + public function setId($id) + { + if ( $id != null ) + { + throw new Exception("ID can't be changed"); + } + $this->id = $id; + } + + /** + * Get the object label + * @return type + */ + public function getLabel() + { + return $this->label; + } + + /** + * Set the label + * @param type $label + */ + public function setLabel($label) + { + $this->label = $label; + } + + /** + * Get the object status + * @return type + */ + public function getStatus() + { + return $this->status; + } + + /** + * Set the status + * @param type $status + */ + public function setStatus($status) + { + $this->label = $status; + } + + /** + * Get a data using the id + * @param type $id + * @return null + */ + public function getData($id) + { + foreach($this->getAllDataObjects() as $data) + { + if ($data->getId() == $id) + { + return $data; + } + } + return null; + } + + /** + * Get all the data object + * @return type + */ + public function getAllDataObjects() + { + return $this->dataObjects; + } + + /** + * Add a data object + * @param type $data + */ + public function addData(DataObject &$data) + { + $this->dataObjects[$data->getId()] = $data; + } + + /** + * Delete a data object + * @param type $data + */ + public function deleteData(DataObject &$data) + { + unset( $this->datas[$data->getId()] ); + } +} + +?> diff --git a/newapi/models/SPO.php b/newapi/models/SPO.php new file mode 100644 index 00000000..6ccce543 --- /dev/null +++ b/newapi/models/SPO.php @@ -0,0 +1,75 @@ +subject = $subject; + $this->predicate = $predicate; + $this->object = $object; + } + + /** + * Get the subject + * @return type + */ + public function getSubject() + { + return $this->subject; + } + + /** + * Get the predicate + * @return type + */ + public function getPredicate() + { + return $this->predicate; + } + + /** + * Get the object + * @return type + */ + public function getObject() + { + return $this->object; + } + + /** + * Set the subject + * @param type $value + */ + public function setSubject($value) + { + $this->subject = $value; + } + + /** + * Set the predicate + * @param type $value + */ + public function setPredicate($value) + { + $this->predicate = $value; + } + + /** + * Set the object + * @param type $value + */ + public function setObject($value) + { + $this->object = $value; + } +} + +?> From b60921adf42d6834b1a7b07249c683f8b975cb9b Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 27 Feb 2012 15:06:17 -0400 Subject: [PATCH 13/29] Switched queries from dc:title to fedora label --- CollectionClass.inc | 2 +- ContentModel.inc | 12 ++++++------ ObjectHelper.inc | 8 ++++---- api/fedora_collection.inc | 2 +- api/fedora_utils.inc | 4 ++-- fedora_repository.module | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 71710d78..f561295c 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -81,7 +81,7 @@ class CollectionClass { $query_string = $objectHelper->getStream($pid, 'QUERY', 0); 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 ) diff --git a/ContentModel.inc b/ContentModel.inc index cbacd422..444f485c 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'); diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 8f58a3ab..1a8db575 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -729,7 +729,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 +829,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 +858,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 ( '; @@ -929,7 +929,7 @@ class ObjectHelper { } else { $query_string = 'select $parentObject $title $content from <#ri> - where ( $title + where ( $title and $parentObject $content and ( $parentObject or $parentObject 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_utils.inc b/api/fedora_utils.inc index c2665fc7..eb56bdcc 100644 --- a/api/fedora_utils.inc +++ b/api/fedora_utils.inc @@ -239,7 +239,7 @@ function get_collections_as_option_array() { $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'; @@ -288,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 f3412b54..1646ce4f 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1596,7 +1596,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 ) From 34fa8851274f939970994807df35e251ad66cecf Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 27 Feb 2012 15:14:38 -0400 Subject: [PATCH 14/29] removed the api stuff that shouldn't have been pushed --- newapi/Cache.php | 76 ---------- newapi/Configuration.php | 58 -------- newapi/IslandoraModule.php | 37 ----- newapi/Repository.php | 264 ---------------------------------- newapi/Search.php | 37 ----- newapi/models/DataObject.php | 42 ------ newapi/models/ObjectModel.php | 119 --------------- newapi/models/SPO.php | 75 ---------- 8 files changed, 708 deletions(-) delete mode 100644 newapi/Cache.php delete mode 100644 newapi/Configuration.php delete mode 100644 newapi/IslandoraModule.php delete mode 100644 newapi/Repository.php delete mode 100644 newapi/Search.php delete mode 100644 newapi/models/DataObject.php delete mode 100644 newapi/models/ObjectModel.php delete mode 100644 newapi/models/SPO.php diff --git a/newapi/Cache.php b/newapi/Cache.php deleted file mode 100644 index 906fe804..00000000 --- a/newapi/Cache.php +++ /dev/null @@ -1,76 +0,0 @@ -objectList[$object->getId()])) - { - $this->objectList[$object->getId()] = array(); - } - - $this->objectList[$object->getId()]['checksum'] = sha1(serialize($object)); - $this->objectList[$object->getId()]['object'] = $object; - } - - /** - * Check to see if the object has been updated - * @param ObjectModel $object - */ - public function hasChanged(ObjectModel &$object) - { - // Is the object even cached - if ( !isset($this->objectList[$object->getId()])) - { - return false; - } - - // Does it have the same checksum - if ($this->objectList[$object->getId()]['checksum'] == sha1(serialize($object)) ) - { - return true; - } - - // If they were the same then it would have already exited - return false; - } - - /** - * Get object from the cache. Returns null if not found. - * @param type $id - */ - public function getObject($id) - { - // Is the object cached - if ( isset($this->objectList[$id]['object'] ) ) { - - // Return the object from the cache - return $this->objectList[$id]['object']; - } - - // Object wasn't found so return null - return null; - } - - /** - * Remove the object from the cache - * @param type $id - */ - public function deleteObject($id) - { - // Unset it from the array - unset( $this->objectList[$id]); - } -} - -?> diff --git a/newapi/Configuration.php b/newapi/Configuration.php deleted file mode 100644 index 5f939715..00000000 --- a/newapi/Configuration.php +++ /dev/null @@ -1,58 +0,0 @@ -$baseUrl = $base_url; - $this->$port = $port; - } - - /** - * Get the base url - * @return type - */ - public function getBaseURL() - { - return $this->$baseUrl; - } - - /** - * Set the base url - * @param type $url - */ - public function setBaseURL($url) - { - $this->$baseUrl = $url; - } - - /** - * Get the port - * @return type - */ - public function getPort() - { - return $this->$port; - } - - /** - * Set the port - * @param type $port - */ - public function setPort($port) - { - $this->$port = $port; - } -} - -?> diff --git a/newapi/IslandoraModule.php b/newapi/IslandoraModule.php deleted file mode 100644 index 8183415a..00000000 --- a/newapi/IslandoraModule.php +++ /dev/null @@ -1,37 +0,0 @@ -repository = new Repository(new Configuration("127.0.0.1", 8080), new Search, new Cache()); - } - - /** - * Get the repository singleton - * @return type - */ - public static function instance() - { - if ( self::instance == null ) - { - $className = __CLASS__; - self::$instance = new $className; - // get_called_class only works in 5.3 - } - - // Return the link to the repository - return self::$instance->repository; - } -} - -?> diff --git a/newapi/Repository.php b/newapi/Repository.php deleted file mode 100644 index cfc34e6c..00000000 --- a/newapi/Repository.php +++ /dev/null @@ -1,264 +0,0 @@ -setConfig($config); - $this->setSearch($search); - $this->setCache($cache); - } - - /** - * Get the configuration implementation - * @return type - */ - public function getConfig() - { - return $this->config; - } - - /** - * Get the search implementation - * @return type - */ - public function getSearch() - { - return $this->search; - } - - /** - * Get the cache implementation - * @return type - */ - public function getCache() - { - return $this->cache; - } - - /** - * Set the configuration implementation - * @param Configuration $config - */ - public function setConfig(Configuration &$config) - { - if ( $config == null ) - { - throw new Exception("Config implementation can't be null"); - } - $this->config = $config; - } - - /** - * Set the search implementation - * @param Search $search - */ - public function setSearch(Search &$search) - { - if ( $search == null ) - { - throw new Exception("Search implementation can't be null"); - } - $this->search = $search; - } - - /** - * Set the cache implementation - * @param Cache $cache - */ - public function setCache(Cache &$cache) - { - if ( $cache == null ) - { - throw new Exception("Cache implementation can't be null"); - } - $this->cache = $cache; - } - - /** - * Get the object from the repo - * @param type $id - */ - public function loadObject($id, $cache=true) - { - // Check to see if its already cached - if ( $this->getCache()->getObject( $id ) && $cache = true) - { - // Return the cached object - return $this->getCache()->getObject( $id ); - } - - // Create the request - $results = $this->makeRequest( '/objects/' .$id ); - - // Return the object model - return unserialize($results); - } - - /** - * Save an object to the repository - * @param ObjectModel $model - * @param type $force - */ - public function saveObject(ObjectModel $model, $force=false) - { - // Has the object been created at all - if ( $model->getId() == null ) { - - // Get the next free persistent id - $id = $this->makeRequest( '/objects/nextPID' ); - - // Set the id on the model - $model->setId($id); - - } - - // If it hasn't changed then done't save unless it's forced - if ( ! $force && ! $this->getCache()->hasChanged($model) ) - { - return; - } - - // Add the object to the cache so everybody has the new copy - $this->getCache()->addObject($model); - - // Post the serialized model to the object endpoint - $this->makeRequest('/objects', $this->serialize($model)); - } - - /** - * Find an object using a search term - * @param type $term - * @return type - */ - public function findObjectByTerm($term) - { - // Create results - $results = $this->makeRequest('/objects?terms=' . $term); - - // Do something with results - return $results; - } - - /** - * Find an object with a query - * @param type $query - * @return type - */ - public function findObjectWithQuery($query) - { - // Create results - $results = $this->makeRequest('/objects?query=' . $term); - - // Do something with results - return $results; - } - - /** - * Search the repository using either a SPO or an array of SPOs - * @param type $query - */ - public function SearchSPO($SPO) - { - // Search - $results = $this->getSearch()->SearchSPO($SPO); - - // Do something with the results - return $results; - } - - /** - * Unserialize the object from foxml - * @param type $xml - * @return \ObjectModel - */ - protected function unserialize($xml) - { - // Create the object model - $model = new ObjectModel(); - - // Do something with the xml - $xml = $xml; - - // Return the model; - return $model; - } - - /** - * Serialize the object to foxml - * @param ObjectModel $model - * @return string - */ - protected function serialize(ObjectModel $model) - { - // Do something with the model - serialize($model); - - // return a string - return ""; - } - - /** - * Make a request - * @param type $request - * @return type - */ - private function makeRequest($request, array $postData = null, $responseCode=200, $format="xml") - { - // Check to see if we already have parameters - $pos = strpos($request, "?"); - if ($pos === false) { - $request.="?format=".$format; - } else { - $request.="&format=".$format; - } - - // Initialize Curl - $curl = curl_init(); - - // Set all the options - curl_setopt($curl, CURLOPT_URL, $this->getConfig()->getBaseURL() . $request); - curl_setopt($curl, CURLOPT_PORT , $this->getConfig()->getPort() ); - curl_setopt($curl, CURLOPT_VERBOSE, 1); - // If we have post data then append that - if ( $postData ) { - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } - - // Execute the curl call - $results = curl_exec($curl); - - // Check for an error - if( ! curl_errno($curl) ) { - - // Get information regarding the curl connection - $info = curl_getinfo($curl); - - // Check the response code - if ( $info['http_code'] != $responseCode ) - { - var_dump($results); - var_dump($info); - throw new Exception("Curl request failed"); - } else { - return $results; - } - } - - // Close connection - curl_close($curl); - - } // Close makeRequest - -} - - -?> diff --git a/newapi/Search.php b/newapi/Search.php deleted file mode 100644 index 406a68e5..00000000 --- a/newapi/Search.php +++ /dev/null @@ -1,37 +0,0 @@ -getSubject() . " " . $spo->getPredicate() . " " . $spo->getObject() . ", "; - } - // Strip off the extra comma - $queryString = substr($queryString, '', -2); - } - else { - $queryString .= $SPO->getSubject() . " " . $SPO->getPredicate() . " " . $SPO->getObject(); - } - - // Do a search - $results = ""; - - // Return results; - return $results; - } -} - -?> diff --git a/newapi/models/DataObject.php b/newapi/models/DataObject.php deleted file mode 100644 index 55af4062..00000000 --- a/newapi/models/DataObject.php +++ /dev/null @@ -1,42 +0,0 @@ -id; - } - - /** - * Set the idea if not already set - * @param type $id - * @throws Exception - */ - public function setId($id) - { - if ( $pid != null ) - { - throw new Exception("PID can't be changed"); - } - $this->id = $pid; - } - - /** - * Add the data from a file ( example ) - */ - public function addDataFromFile() - { - - } -} - -?> diff --git a/newapi/models/ObjectModel.php b/newapi/models/ObjectModel.php deleted file mode 100644 index 3ceb6da1..00000000 --- a/newapi/models/ObjectModel.php +++ /dev/null @@ -1,119 +0,0 @@ -id; - } - - /** - * Set the idea if not already set - * @param type $id - * @throws Exception - */ - public function setId($id) - { - if ( $id != null ) - { - throw new Exception("ID can't be changed"); - } - $this->id = $id; - } - - /** - * Get the object label - * @return type - */ - public function getLabel() - { - return $this->label; - } - - /** - * Set the label - * @param type $label - */ - public function setLabel($label) - { - $this->label = $label; - } - - /** - * Get the object status - * @return type - */ - public function getStatus() - { - return $this->status; - } - - /** - * Set the status - * @param type $status - */ - public function setStatus($status) - { - $this->label = $status; - } - - /** - * Get a data using the id - * @param type $id - * @return null - */ - public function getData($id) - { - foreach($this->getAllDataObjects() as $data) - { - if ($data->getId() == $id) - { - return $data; - } - } - return null; - } - - /** - * Get all the data object - * @return type - */ - public function getAllDataObjects() - { - return $this->dataObjects; - } - - /** - * Add a data object - * @param type $data - */ - public function addData(DataObject &$data) - { - $this->dataObjects[$data->getId()] = $data; - } - - /** - * Delete a data object - * @param type $data - */ - public function deleteData(DataObject &$data) - { - unset( $this->datas[$data->getId()] ); - } -} - -?> diff --git a/newapi/models/SPO.php b/newapi/models/SPO.php deleted file mode 100644 index 6ccce543..00000000 --- a/newapi/models/SPO.php +++ /dev/null @@ -1,75 +0,0 @@ -subject = $subject; - $this->predicate = $predicate; - $this->object = $object; - } - - /** - * Get the subject - * @return type - */ - public function getSubject() - { - return $this->subject; - } - - /** - * Get the predicate - * @return type - */ - public function getPredicate() - { - return $this->predicate; - } - - /** - * Get the object - * @return type - */ - public function getObject() - { - return $this->object; - } - - /** - * Set the subject - * @param type $value - */ - public function setSubject($value) - { - $this->subject = $value; - } - - /** - * Set the predicate - * @param type $value - */ - public function setPredicate($value) - { - $this->predicate = $value; - } - - /** - * Set the object - * @param type $value - */ - public function setObject($value) - { - $this->object = $value; - } -} - -?> From 0ba035d4da00f681247d91f0b018d9c307471a5d Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 28 Feb 2012 12:15:17 +0000 Subject: [PATCH 15/29] Cleaned up the function soap_call(). It was using watchdog incorrectly, causing the function to attempt to serialize non-serializable data. --- api/fedora_item.inc | 183 ++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 100 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 7524ebbb..3367df43 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -1,7 +1,7 @@ objectProfile)); @@ -81,7 +97,7 @@ class Fedora_Item { * @param type $datastream_mimetype * @param type $controlGroup * @param type $logMessage - * @return type + * @return type */ function add_datastream_from_file($datastream_file, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = NULL) { module_load_include('inc', 'fedora_repository', 'MimeClass'); @@ -116,7 +132,7 @@ class Fedora_Item { * @param type $datastream_mimetype * @param type $controlGroup * @param type $logMessage - * @return type + * @return type */ function add_datastream_from_url($datastream_url, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = NULL) { if (empty($datastream_label)) { @@ -151,7 +167,7 @@ class Fedora_Item { * @param type $datastream_mimetype * @param type $controlGroup * @param type $logMessage - * @return type + * @return type */ function add_datastream_from_string($str, $datastream_id, $datastream_label = NULL, $datastream_mimetype = 'text/xml', $controlGroup = 'M', $logMessage = NULL) { $dir = file_directory_temp(); @@ -164,9 +180,8 @@ class Fedora_Item { return $returnvalue; } - /** - * Wrapper to add new or modify existing datastream + * Wrapper to add new or modify existing datastream * @global url $base_url * @param url $external_url * @param string $dsid @@ -175,7 +190,7 @@ class Fedora_Item { * @param string $controlGroup * @param boolean $force * @param string $logMessage - * @param boolean $quiet + * @param boolean $quiet */ function add_or_modify_by_reference($external_url, $dsid, $label, $mime_type, $controlGroup = 'M', $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) { global $base_url; @@ -193,7 +208,7 @@ class Fedora_Item { * does not support rels-int yet. * @param type $relationship * @param type $object - * @param type $namespaceURI + * @param type $namespaceURI */ function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI) { $ds_list = $this->get_datastreams_list_as_array(); @@ -297,7 +312,7 @@ class Fedora_Item { /** * Export as foxml - * @return type + * @return type */ function export_as_foxml() { $params = array( @@ -378,7 +393,7 @@ class Fedora_Item { * Get datastream dissemination * @param type $dsid * @param type $as_of_date_time - * @return string + * @return string */ function get_datastream_dissemination($dsid, $as_of_date_time = "") { $params = array( @@ -401,7 +416,7 @@ class Fedora_Item { * Get datastream * @param type $dsid * @param type $as_of_date_time - * @return type + * @return type */ function get_datastream($dsid, $as_of_date_time = "") { $params = array( @@ -417,7 +432,7 @@ class Fedora_Item { /** * Get datastream history * @param type $dsid - * @return type + * @return type */ function get_datastream_history($dsid) { $params = array( @@ -439,7 +454,7 @@ class Fedora_Item { * @param type $method_name * @param type $parameters * @param type $as_of_date_time - * @return string + * @return string */ function get_dissemination($service_definition_pid, $method_name, $parameters = array(), $as_of_date_time = NULL) { $params = array( @@ -658,18 +673,16 @@ class Fedora_Item { return FALSE; } - + /** * Set the object to a deleted state */ - function move_to_trash($log_message = 'Flagged deleted using Islandora API.') - { + function move_to_trash($log_message = 'Flagged deleted using Islandora API.') { // Loop through the datastreams and mark them deleted - foreach($this->get_datastreams_list_as_array() as $dsid) - { + foreach ($this->get_datastreams_list_as_array() as $dsid) { $this->set_datastream_state($dsid, 'D'); } - + // Create a message to mark the object deleted $params = array( 'pid' => $this->pid, @@ -685,13 +698,13 @@ class Fedora_Item { * Removes this object form the repository. * @param type $log_message * @param type $force - * @return type + * @return type */ function purge($log_message = 'Purged using Islandora API.', $force = FALSE) { - + // Flag the object to be deleted first $this->move_to_trash($log_message); - + // Create the delete message $params = array( 'pid' => $this->pid, @@ -710,7 +723,7 @@ class Fedora_Item { * @param type $end_date * @param type $log_message * @param type $force - * @return type + * @return type */ function purge_datastream($dsID, $start_date = NULL, $end_date = NULL, $log_message = 'Purged datastream using Islandora API', $force = FALSE) { $params = array( @@ -727,7 +740,7 @@ class Fedora_Item { /** * URL * @global type $base_url - * @return type + * @return type */ function url() { global $base_url; @@ -737,7 +750,7 @@ class Fedora_Item { /** * Get Next PID in Namespace * @param type $pid_namespace - * @return type + * @return type */ static function get_next_PID_in_namespace($pid_namespace = '') { @@ -765,7 +778,7 @@ class Fedora_Item { /** * ingest from FOXML * @param type $foxml - * @return Fedora_Item + * @return Fedora_Item */ static function ingest_from_FOXML($foxml) { $params = array('objectXML' => $foxml->saveXML(), 'format' => "info:fedora/fedora-system:FOXML-1.1", 'logMessage' => "Fedora Object Ingested"); @@ -776,7 +789,7 @@ class Fedora_Item { /** * ingest from FOXML file * @param type $foxml_file - * @return type + * @return type */ static function ingest_from_FOXML_file($foxml_file) { $foxml = new DOMDocument(); @@ -786,7 +799,7 @@ class Fedora_Item { /** * ingest from FOXML files in directory - * @param type $path + * @param type $path */ static function ingest_from_FOXML_files_in_directory($path) { // Open the directory @@ -814,7 +827,7 @@ class Fedora_Item { * @param type $ownerId * @param type $logMessage * @param type $quiet - * @return type + * @return type */ function modify_object($label = '', $state = NULL, $ownerId = NULL, $logMessage = 'Modified by Islandora API', $quiet=TRUE) { @@ -838,7 +851,7 @@ class Fedora_Item { * @param type $force * @param type $logMessage * @param type $quiet - * @return type + * @return type */ function modify_datastream_by_reference($external_url, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) { $params = array( @@ -866,7 +879,7 @@ class Fedora_Item { * @param type $force * @param type $logMessage * @param type $quiet - * @return type + * @return type */ function modify_datastream_by_value($content, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) { $params = array( @@ -899,74 +912,44 @@ class Fedora_Item { } /** - * Soap call - * @param type $function_name - * @param type $params_array - * @param type $quiet - * @return type + * Make a soap call to the fedora API. + * + * @param string $function + * The name of the soap function to call. + * @param array $parameters + * Paramters to pass onto the soap call + * @param boolean $quiet + * If TRUE suppress drupal messages. + * + * @return mixed + * The return value from the soap function if successful, NULL otherwise. */ - static function soap_call($function_name, $params_array, $quiet = FALSE) { + static function soap_call($function, $parameters, $quiet = FALSE) { if (!self::$connection_helper) { module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); self::$connection_helper = new ConnectionHelper(); } - switch ($function_name) { - case 'ingest': - case 'addDataStream': - case 'addRelationship': - case 'export': - case 'getDatastream': - case 'getDatastreamHistory': - case 'getNextPID': - case 'getRelationships': - case 'modifyDatastreamByValue': - case 'modifyDatastreamByReference': - case 'purgeDatastream': - case 'purgeObject': - case 'modifyObject': - case 'setDatastreamState': - $soap_client = self::$connection_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl')); - try { - if (!empty($soap_client)) { - $result = $soap_client->__soapCall($function_name, array('parameters' => $params_array)); - } - else { - watchdog(t("FEDORA_REPOSITORY"), "Error trying to get SOAP client connection."); - return NULL; - } - } catch (exception $e) { - if (!$quiet) { - - if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage())) { - drupal_set_message(t('Error: Insufficient permissions to call SOAP function !fn.', array('!fn' => $function_name)), 'error'); - } - else { - drupal_set_message(t("Error trying to call SOAP function $function_name. Check watchdog logs for more information."), 'error'); - } - - watchdog(t("FEDORA_REPOSITORY"), "Error Trying to call SOAP function @fn: @e", array('@fn' => $function_name, '@e' => $e), NULL, WATCHDOG_ERROR); - } - return NULL; - } - break; - - default: - try { - $soap_client = self::$connection_helper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl')); - if (!empty($soap_client)) { - $result = $soap_client->__soapCall($function_name, array('parameters' => $params_array)); - } - else { - watchdog(t("FEDORA_REPOSITORY"), "Error trying to get SOAP client connection."); - return NULL; - } - } catch (exception $e) { - - if (!$quiet) { - watchdog(t("FEDORA_REPOSITORY"), "Error trying to call SOAP function @fn: @e", array('@fn' => $function_name, '@e' => $e), NULL, WATCHDOG_ERROR); - } - return NULL; + $url = (array_search($function, self::$SoapManagedFunctions) !== FALSE) ? + variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl') : + variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'); + try { + $soap_client = self::$connection_helper->getSoapClient($url); + if (empty($soap_client)) { + if (!$quiet) { + drupal_set_message(t('Error trying to get SOAP client connection.')); } + watchdog('fedora_repository', 'Error trying to get SOAP client connection.'); + return NULL; + } + $result = $soap_client->__soapCall($function, array('parameters' => $parameters)); + } catch (Exception $e) { + if (!$quiet) { + preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage()) ? + drupal_set_message(t('Insufficient permissions to call SOAP function "%func".', array('%func' => $function)), 'error') : + drupal_set_message(t('Error trying to call SOAP function "%func". Check watchdog logs for more information.', array('%func' => $function)), 'error'); + } + watchdog('fedora_repository', 'Error Trying to call SOAP function "%func". Exception Occured: @e', array('%func' => $function, '@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); + return NULL; } return $result; } @@ -979,7 +962,7 @@ class Fedora_Item { * @param string $state The initial state, A - Active, I - Inactive, D - Deleted * @param type $label * @param type $owner - * @return DOMDocument + * @return DOMDocument */ static function create_object_FOXML($pid = '', $state = 'A', $label = 'Untitled', $owner = '') { $foxml = new DOMDocument("1.0", "UTF-8"); @@ -1034,16 +1017,16 @@ class Fedora_Item { * @param type $state * @param type $label * @param type $owner - * @return type + * @return type */ static function ingest_new_item($pid = '', $state = 'A', $label = '', $owner = '') { return self::ingest_from_FOXML(self::create_object_FOXML($pid, $state, $label, $owner)); } /** - * fedora item exists + * fedora item exists * @param type $pid - * @return type + * @return type */ static function fedora_item_exists($pid) { $item = new Fedora_Item($pid); From 7715ec1f1d03c8c4231e73f6beecbee7d83dcd46 Mon Sep 17 00:00:00 2001 From: rwincewicz Date: Thu, 1 Mar 2012 17:13:38 -0400 Subject: [PATCH 16/29] Removed object labels from the URLs created in sparql_to_html.xsl to prevent unnecessarily long paths and stop diacritics from breaking the default collection view --- xsl/sparql_to_html.xsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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/ From 6bd33358edcd1dd5b50df44e52e61762e896498f Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Fri, 2 Mar 2012 17:38:49 +0000 Subject: [PATCH 17/29] Using fedora item instead of object helper in some cause to prevent exceptions such as object not found in lower level storage. --- CollectionClass.inc | 24 ++++++++++++++---------- api/fedora_item.inc | 10 ++++++---- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index f561295c..08f669e0 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -45,11 +45,12 @@ class CollectionClass { * @return type */ function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) { - module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - $objectHelper = new ObjectHelper(); if (!isset($itqlquery)) { - // $query_string = $objectHelper->getStream($pid, 'QUERY', 0); - $itqlquery = $objectHelper->getStream($pid, 'QUERY', 0); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $item = new Fedora_Item($pid); + if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { + $itqlquery = $item->get_datastream_dissemination('QUERY'); + } } return $this->getRelatedItems($pid, $itqlquery, $limit, $offset); } @@ -78,7 +79,11 @@ class CollectionClass { $objectHelper = new ObjectHelper(); $query_string = $itqlquery; if (!isset($query_string)) { - $query_string = $objectHelper->getStream($pid, 'QUERY', 0); + $query_string = NULL; + $item = new Fedora_Item($pid); + if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { + $query_string = $item->get_datastream_dissemination('QUERY'); + } if ($query_string == NULL) { $query_string = 'select $object $title $content from <#ri> where ($object $title @@ -445,7 +450,7 @@ class CollectionClass { 'pidNamespace' => $pidNameSpace ); $object = $soapClient->__soapCall('getNextPID', array( - $params + $params )); } catch (exception $e) { drupal_set_message(t('Error getting Next PID: @e', array('@e' => check_plain($e->getMessage()))), 'error'); @@ -498,11 +503,10 @@ class CollectionClass { module_load_include('inc', 'fedora_repository', 'CollectionManagement'); module_load_include('inc', 'fedora_repository', 'BatchIngest'); global $base_url; - $tabset = array(); global $user; - $objectHelper = new ObjectHelper(); - $item = new Fedora_Item($this->pid); + $tabset = array(); $query = NULL; + $item = new Fedora_Item($this->pid); if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { $query = $item->get_datastream_dissemination('QUERY'); } @@ -517,7 +521,7 @@ class CollectionClass { $show_batch_tab = FALSE; $policy = CollectionPolicy::loadFromCollection($this->pid, TRUE); - if(!empty($policy)){ + if (!empty($policy)) { $content_models = $policy->getContentModels(); } if (count($content_models) == 1 && $content_models[0]->pid == "islandora:collectionCModel") { diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 3367df43..afc110bd 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -934,21 +934,23 @@ class Fedora_Item { variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'); try { $soap_client = self::$connection_helper->getSoapClient($url); - if (empty($soap_client)) { + if (isset($soap_client)) { + $result = $soap_client->__soapCall($function, array('parameters' => $parameters)); + } + else { if (!$quiet) { - drupal_set_message(t('Error trying to get SOAP client connection.')); + drupal_set_message(t('Error trying to get SOAP client connection')); } watchdog('fedora_repository', 'Error trying to get SOAP client connection.'); return NULL; } - $result = $soap_client->__soapCall($function, array('parameters' => $parameters)); } catch (Exception $e) { if (!$quiet) { preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage()) ? drupal_set_message(t('Insufficient permissions to call SOAP function "%func".', array('%func' => $function)), 'error') : drupal_set_message(t('Error trying to call SOAP function "%func". Check watchdog logs for more information.', array('%func' => $function)), 'error'); } - watchdog('fedora_repository', 'Error Trying to call SOAP function "%func". Exception Occured: @e', array('%func' => $function, '@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); + watchdog('fedora_repository', 'Error Trying to call SOAP function "%func". Exception: @e in @f(@l)\n@t', array('%func' => $function, '@e' => $e->getMessage(), '@f' => $e->getFile(), '@l' => $e->getLine(), '@t' => $e->getTraceAsString()), NULL, WATCHDOG_ERROR); return NULL; } return $result; From 2f979ab447565b881ef058866ac053940ecf50c2 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Fri, 2 Mar 2012 17:45:20 +0000 Subject: [PATCH 18/29] Found incorrect use of watchdog. --- ObjectHelper.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 1a8db575..e8555635 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -383,8 +383,8 @@ class ObjectHelper { $xsl->load($path . '/xsl/convertQDC.xsl'); $input = new DomDocument(); $input->loadXML(trim($xmlstr)); - } catch (exception $e) { - watchdog(t("Fedora_Repository"), "Problem loading XSL file: @e", array('@e' => $e), NULL, WATCHDOG_ERROR); + } catch (Exception $e) { + watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); } $xsl = $proc->importStylesheet($xsl); $newdom = $proc->transformToDoc($input); From 741a1727242c9d9941ce64e80bc75711b187fafb Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 5 Mar 2012 11:13:44 -0400 Subject: [PATCH 19/29] Added solution pack install boilerplate --- fedora_repository.solutionpacks.inc | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index 756f8bf0..c45f475a 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -200,3 +200,54 @@ function solution_pack_add_form_association($content_model, $form_name) { } } +/** + * Solution pack install helper + * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" + * @param type $mods_form_file The MODS form file name relative to the module (solutionpack/xml/mods_article.xml) + * @param type $content_model The Content Model (islandora:docs_sp_cm) + */ +function solution_pack_installer($mods_form_name, $mods_form_file, $content_model) +{ + module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); + + if (!XMLFormDatabase::Exists($mods_form_name)) { + //$module_path = drupal_get_path('module', ISLANDORA_SP_MODULE_NAME); + $definition = new DOMDocument(); + $definition->load($mods_form_file); + XMLFormDatabase::Create($mods_form_name, $definition); + } + + // Associates the form with the content model + $result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name)); + + if (!$result) { + $object = new stdClass(); + $object->content_model = $content_model; + $object->form_name = $mods_form_name; + $object->dsid = 'MODS'; + $object->title_field = "['titleInfo']['title']"; + $object->transform = 'mods_to_dc.xsl'; + $result = drupal_write_record('islandora_content_model_forms', $object); + } +} + +/** + * Solution Pack Uninstall Helper + * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" + * @param type $mods_form_file The MODS form file name relative to the module (solutionpack/xml/mods_article.xml) + * @param type $content_model The Content Model (islandora:docs_sp_cm) + */ +function solution_pack_uninstaller($mods_form_name, $mods_form_name, $content_model) +{ + module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); + + if (XMLFormDatabase::Exists($mods_form_name)) { + XMLFormDatabase::Delete($mods_form_name); + } + + $result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name)); + + if (!$result) { + db_query('DELETE FROM {islandora_content_model_forms} WHERE content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name); + } +} From 800407ec54029acb876031f6549b8e45d1e1c08c Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 5 Mar 2012 11:47:59 -0400 Subject: [PATCH 20/29] Renamed the files to something more appropriate --- fedora_repository.solutionpacks.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index c45f475a..64dc78bb 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -201,12 +201,12 @@ function solution_pack_add_form_association($content_model, $form_name) { } /** - * Solution pack install helper + * Solution pack register form * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" * @param type $mods_form_file The MODS form file name relative to the module (solutionpack/xml/mods_article.xml) * @param type $content_model The Content Model (islandora:docs_sp_cm) */ -function solution_pack_installer($mods_form_name, $mods_form_file, $content_model) +function solution_pack_register_form($mods_form_name, $mods_form_file, $content_model) { module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); @@ -232,12 +232,12 @@ function solution_pack_installer($mods_form_name, $mods_form_file, $content_mode } /** - * Solution Pack Uninstall Helper + * Solution pack unregister form * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" * @param type $mods_form_file The MODS form file name relative to the module (solutionpack/xml/mods_article.xml) * @param type $content_model The Content Model (islandora:docs_sp_cm) */ -function solution_pack_uninstaller($mods_form_name, $mods_form_name, $content_model) +function solution_pack_unregister_form($mods_form_name, $mods_form_name, $content_model) { module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); From 9948737d7c585ff4297477a688023b92b32e342e Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 5 Mar 2012 12:20:28 -0400 Subject: [PATCH 21/29] Added a force reinstall option --- fedora_repository.solutionpacks.inc | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index 64dc78bb..b7edc8ab 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -205,16 +205,28 @@ function solution_pack_add_form_association($content_model, $form_name) { * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" * @param type $mods_form_file The MODS form file name relative to the module (solutionpack/xml/mods_article.xml) * @param type $content_model The Content Model (islandora:docs_sp_cm) + * @param boolean $force Force a reinstall */ -function solution_pack_register_form($mods_form_name, $mods_form_file, $content_model) +function solution_pack_register_form($mods_form_name, $mods_form_file, $content_model, $force=false) { + // Load the form builder database module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); + + // Load the form + $definition = new DOMDocument(); + $definition->load($mods_form_file); - if (!XMLFormDatabase::Exists($mods_form_name)) { - //$module_path = drupal_get_path('module', ISLANDORA_SP_MODULE_NAME); - $definition = new DOMDocument(); - $definition->load($mods_form_file); + // If it doesn't exist + if (!XMLFormDatabase::Exists($mods_form_name) ) { + + // Create the form XMLFormDatabase::Create($mods_form_name, $definition); + + // Force Update of an existing form + } elseif ( $force == true ) { + + // Update the form + XMLFormDatabase::Update($mods_form_name, $definition); } // Associates the form with the content model @@ -234,10 +246,9 @@ function solution_pack_register_form($mods_form_name, $mods_form_file, $content_ /** * Solution pack unregister form * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" - * @param type $mods_form_file The MODS form file name relative to the module (solutionpack/xml/mods_article.xml) * @param type $content_model The Content Model (islandora:docs_sp_cm) */ -function solution_pack_unregister_form($mods_form_name, $mods_form_name, $content_model) +function solution_pack_unregister_form($mods_form_name, $content_model) { module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); From 783e2da0c86117ab8456b4daff31efabd2047c01 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 5 Mar 2012 12:30:33 -0400 Subject: [PATCH 22/29] Cleaned up, added a force and fixed a bug in the delete --- fedora_repository.solutionpacks.inc | 37 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index b7edc8ab..bdd36132 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -211,34 +211,43 @@ function solution_pack_register_form($mods_form_name, $mods_form_file, $content_ { // Load the form builder database module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); - - // Load the form - $definition = new DOMDocument(); - $definition->load($mods_form_file); - + // If it doesn't exist if (!XMLFormDatabase::Exists($mods_form_name) ) { + + // Load the form + $definition = new DOMDocument(); + $definition->load($mods_form_file); // Create the form XMLFormDatabase::Create($mods_form_name, $definition); // Force Update of an existing form } elseif ( $force == true ) { + + // Load the form + $definition = new DOMDocument(); + $definition->load($mods_form_file); // Update the form XMLFormDatabase::Update($mods_form_name, $definition); } - // Associates the form with the content model - $result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name)); + // Check to see if the form has already been registered + $result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name)); + // Check for results if (!$result) { + + // Create a model for the database $object = new stdClass(); $object->content_model = $content_model; $object->form_name = $mods_form_name; $object->dsid = 'MODS'; $object->title_field = "['titleInfo']['title']"; $object->transform = 'mods_to_dc.xsl'; + + // Write the association $result = drupal_write_record('islandora_content_model_forms', $object); } } @@ -250,15 +259,23 @@ function solution_pack_register_form($mods_form_name, $mods_form_file, $content_ */ function solution_pack_unregister_form($mods_form_name, $content_model) { + // Load the form builders xmlformdatabase module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); + // Check to see if the form exists if (XMLFormDatabase::Exists($mods_form_name)) { + + // Delete the form XMLFormDatabase::Delete($mods_form_name); } - + + // Check to see if the form has already been registered $result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name)); - - if (!$result) { + + // Is there anything to delete + if ($result) { + + // Delete the association db_query('DELETE FROM {islandora_content_model_forms} WHERE content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name); } } From 0a13bf248fb509b7a0c2fa23719f0ed9fd819834 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 5 Mar 2012 13:13:50 -0400 Subject: [PATCH 23/29] We now use the database to store instead of xmlformdatabase and a force has been added --- fedora_repository.solutionpacks.inc | 132 ++++++++++++++++------------ 1 file changed, 76 insertions(+), 56 deletions(-) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index bdd36132..34a4b33d 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -181,7 +181,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(t("Added @name", array("@name" => $name))); + drupal_set_message(t("Added @name", array("@name" => $form_name))); } } @@ -196,7 +196,7 @@ 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(t("Added association between @cm@name", array("@cm" => $content_model, "@name"=>$name))); + drupal_set_message(t("Added association between @cm@name", array("@cm" => $content_model, "@name"=>$form_name))); } } @@ -204,78 +204,98 @@ function solution_pack_add_form_association($content_model, $form_name) { * Solution pack register form * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" * @param type $mods_form_file The MODS form file name relative to the module (solutionpack/xml/mods_article.xml) - * @param type $content_model The Content Model (islandora:docs_sp_cm) - * @param boolean $force Force a reinstall + * @return int 0 = Ok and 1 = Unable to load file */ -function solution_pack_register_form($mods_form_name, $mods_form_file, $content_model, $force=false) +function solution_pack_register_form($mods_form_name, $mods_form_file, $force=false) { - // Load the form builder database - module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); - - // If it doesn't exist - if (!XMLFormDatabase::Exists($mods_form_name) ) { + // Lookup the form + $results = db_result(db_query('Select name from {xml_forms} where name = "%s"', $mods_form_name)); + + // Check to see if there is anything to do + if ( $results && $force==false) { - // Load the form - $definition = new DOMDocument(); - $definition->load($mods_form_file); - - // Create the form - XMLFormDatabase::Create($mods_form_name, $definition); - - // Force Update of an existing form - } elseif ( $force == true ) { - - // Load the form - $definition = new DOMDocument(); - $definition->load($mods_form_file); + // Nothing to do so early out + return 0; + } + + // Get the contents of the file + $mods_form_data = file_get_contents($mods_form_file); + + // Didn't load the file + if ( ! $mods_form_data ) { - // Update the form - XMLFormDatabase::Update($mods_form_name, $definition); + // Return an error + return 1; } - - // Check to see if the form has already been registered - $result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name)); - // Check for results - if (!$result) { + // Create the data model + $object = new stdClass(); + $object->name = $mods_form_name; + $object->form = $mods_form_data; + + // Are we adding the form + if ( ! $results ) { - // Create a model for the database - $object = new stdClass(); - $object->content_model = $content_model; - $object->form_name = $mods_form_name; - $object->dsid = 'MODS'; - $object->title_field = "['titleInfo']['title']"; - $object->transform = 'mods_to_dc.xsl'; + // Add the model to the database + $result = drupal_write_record('xml_forms', $object); - // Write the association - $result = drupal_write_record('islandora_content_model_forms', $object); + } else { + + // Update the model in the database + $result = drupal_write_record('xml_forms', $object, array("name" => $mods_form_name)); } + + // Log the action + drupal_set_message(t("Added @name", array("@name" => $mods_form_name))); } /** - * Solution pack unregister form + * Solution pack register form * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" * @param type $content_model The Content Model (islandora:docs_sp_cm) */ -function solution_pack_unregister_form($mods_form_name, $content_model) -{ - // Load the form builders xmlformdatabase - module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); - - // Check to see if the form exists - if (XMLFormDatabase::Exists($mods_form_name)) { +function solution_pack_register_form_association($mods_form_name, $content_model, $force=false) { + + // Query the database for previous associations + $results = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', + $content_model, $mods_form_name)); + + // Check to see if there is anything to do + if ( $results && $force==false) { - // Delete the form - XMLFormDatabase::Delete($mods_form_name); + // Nothing to do so early out + return; } - // Check to see if the form has already been registered - $result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name)); + // Create a model for the database + $object = new stdClass(); + $object->content_model = $content_model; + $object->form_name = $mods_form_name; + $object->dsid = 'MODS'; + $object->title_field = "['titleInfo']['title']"; + $object->transform = 'mods_to_dc.xsl'; - // Is there anything to delete - if ($result) { + // Are we adding the form association + if ( ! $results ) { - // Delete the association - db_query('DELETE FROM {islandora_content_model_forms} WHERE content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name); - } + // Add the association + $result = drupal_write_record('islandora_content_model_forms', $object); + } else { + + // Update the association + $result = drupal_write_record('islandora_content_model_forms', $object, array("content_model" => $content_model)); + } + + // Log the action + drupal_set_message(t("Added association between @cm@name", array("@cm" => $content_model, "@name"=>$mods_form_name))); +} + +/** + * Solution pack unregister form + * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" + * @param type $content_model The Content Model (islandora:docs_sp_cm) + */ +function solution_pack_unregister_form($mods_form_name, $content_model) +{ + } From f153548f0740eb7c3176d7feef345e03bca97997 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 5 Mar 2012 13:27:41 -0400 Subject: [PATCH 24/29] Added delete calls --- fedora_repository.solutionpacks.inc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index 34a4b33d..59e2f6da 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -290,12 +290,21 @@ function solution_pack_register_form_association($mods_form_name, $content_model drupal_set_message(t("Added association between @cm@name", array("@cm" => $content_model, "@name"=>$mods_form_name))); } +/** + * Solution pack unregister form + * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" + */ +function solution_pack_unregister_form($mods_form_name) +{ + +} + /** * Solution pack unregister form * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" * @param type $content_model The Content Model (islandora:docs_sp_cm) */ -function solution_pack_unregister_form($mods_form_name, $content_model) +function solution_pack_unregister_form_association($mods_form_name, $content_model) { } From 63ac3d44d30327e6af1660766a5385d5d2c6eb8d Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Mon, 5 Mar 2012 16:36:19 -0400 Subject: [PATCH 25/29] Added a new sp architecture based around alans ideas --- fedora_repository.newsp.inc | 11 +++++++++++ fedora_repository.solutionpacks.inc | 2 ++ formClass.inc | 11 ++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 fedora_repository.newsp.inc diff --git a/fedora_repository.newsp.inc b/fedora_repository.newsp.inc new file mode 100644 index 00000000..98e6d3e0 --- /dev/null +++ b/fedora_repository.newsp.inc @@ -0,0 +1,11 @@ + diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index 59e2f6da..f8f4bdd5 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -308,3 +308,5 @@ function solution_pack_unregister_form_association($mods_form_name, $content_mod { } + + diff --git a/formClass.inc b/formClass.inc index 86a5128f..4ac1c246 100644 --- a/formClass.inc +++ b/formClass.inc @@ -48,7 +48,16 @@ class formClass { 'file' => 'fedora_repository.solutionpacks.inc', 'type' => MENU_LOCAL_TASK, ); - + + $items['admin/settings/fedora_repository/newsp'] = array( + 'title' => t('New Solution Packs'), + 'description' => t('Install content models and collections required by installed solution packs.'), + 'page callback' => 'fedora_repository_newsp_page', + 'access arguments' => array('add fedora datastreams'), + 'file' => 'fedora_repository.newsp.inc', + 'type' => MENU_LOCAL_TASK, + ); + $items['islandoracm.xsd'] = array( 'title' => t('Islandora Content Model XML Schema Definition'), 'page callback' => 'fedora_repository_display_schema', From bac9026c93fdaa5de361c7bb2b50b01eb0037a40 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Tue, 6 Mar 2012 10:30:11 -0400 Subject: [PATCH 26/29] cleanup my solution pack code --- fedora_repository.newsp.inc | 11 ----------- formClass.inc | 10 ---------- 2 files changed, 21 deletions(-) delete mode 100644 fedora_repository.newsp.inc diff --git a/fedora_repository.newsp.inc b/fedora_repository.newsp.inc deleted file mode 100644 index 98e6d3e0..00000000 --- a/fedora_repository.newsp.inc +++ /dev/null @@ -1,11 +0,0 @@ - diff --git a/formClass.inc b/formClass.inc index 4ac1c246..09bfce8b 100644 --- a/formClass.inc +++ b/formClass.inc @@ -48,16 +48,6 @@ class formClass { 'file' => 'fedora_repository.solutionpacks.inc', 'type' => MENU_LOCAL_TASK, ); - - $items['admin/settings/fedora_repository/newsp'] = array( - 'title' => t('New Solution Packs'), - 'description' => t('Install content models and collections required by installed solution packs.'), - 'page callback' => 'fedora_repository_newsp_page', - 'access arguments' => array('add fedora datastreams'), - 'file' => 'fedora_repository.newsp.inc', - 'type' => MENU_LOCAL_TASK, - ); - $items['islandoracm.xsd'] = array( 'title' => t('Islandora Content Model XML Schema Definition'), 'page callback' => 'fedora_repository_display_schema', From 286354196927f0b88d6f4734dec24bacf5470226 Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Tue, 6 Mar 2012 16:11:44 -0400 Subject: [PATCH 27/29] removed register functions --- fedora_repository.solutionpacks.inc | 110 ---------------------------- 1 file changed, 110 deletions(-) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index f8f4bdd5..1ee956f1 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -200,113 +200,3 @@ function solution_pack_add_form_association($content_model, $form_name) { } } -/** - * Solution pack register form - * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" - * @param type $mods_form_file The MODS form file name relative to the module (solutionpack/xml/mods_article.xml) - * @return int 0 = Ok and 1 = Unable to load file - */ -function solution_pack_register_form($mods_form_name, $mods_form_file, $force=false) -{ - // Lookup the form - $results = db_result(db_query('Select name from {xml_forms} where name = "%s"', $mods_form_name)); - - // Check to see if there is anything to do - if ( $results && $force==false) { - - // Nothing to do so early out - return 0; - } - - // Get the contents of the file - $mods_form_data = file_get_contents($mods_form_file); - - // Didn't load the file - if ( ! $mods_form_data ) { - - // Return an error - return 1; - } - - // Create the data model - $object = new stdClass(); - $object->name = $mods_form_name; - $object->form = $mods_form_data; - - // Are we adding the form - if ( ! $results ) { - - // Add the model to the database - $result = drupal_write_record('xml_forms', $object); - - } else { - - // Update the model in the database - $result = drupal_write_record('xml_forms', $object, array("name" => $mods_form_name)); - } - - // Log the action - drupal_set_message(t("Added @name", array("@name" => $mods_form_name))); -} - -/** - * Solution pack register form - * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" - * @param type $content_model The Content Model (islandora:docs_sp_cm) - */ -function solution_pack_register_form_association($mods_form_name, $content_model, $force=false) { - - // Query the database for previous associations - $results = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', - $content_model, $mods_form_name)); - - // Check to see if there is anything to do - if ( $results && $force==false) { - - // Nothing to do so early out - return; - } - - // Create a model for the database - $object = new stdClass(); - $object->content_model = $content_model; - $object->form_name = $mods_form_name; - $object->dsid = 'MODS'; - $object->title_field = "['titleInfo']['title']"; - $object->transform = 'mods_to_dc.xsl'; - - // Are we adding the form association - if ( ! $results ) { - - // Add the association - $result = drupal_write_record('islandora_content_model_forms', $object); - } else { - - // Update the association - $result = drupal_write_record('islandora_content_model_forms', $object, array("content_model" => $content_model)); - } - - // Log the action - drupal_set_message(t("Added association between @cm@name", array("@cm" => $content_model, "@name"=>$mods_form_name))); -} - -/** - * Solution pack unregister form - * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" - */ -function solution_pack_unregister_form($mods_form_name) -{ - -} - -/** - * Solution pack unregister form - * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" - * @param type $content_model The Content Model (islandora:docs_sp_cm) - */ -function solution_pack_unregister_form_association($mods_form_name, $content_model) -{ - -} - - From fec776de32f7c0aea82500fc30f5a41adf6c89ee Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Wed, 7 Mar 2012 14:02:34 -0400 Subject: [PATCH 28/29] Added a force reinstall and fixed a move to trash bug --- api/fedora_item.inc | 6 ++++-- fedora_repository.module | 7 +++++++ fedora_repository.solutionpacks.inc | 18 ++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 7524ebbb..e7043b14 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -669,12 +669,14 @@ class Fedora_Item { { $this->set_datastream_state($dsid, 'D'); } - + // Create a message to mark the object deleted $params = array( 'pid' => $this->pid, 'state' => 'D', - 'logMessage' => $logMessage + 'logMessage' => $logMessage, + 'label' => $this->objectProfile->objLabel, + 'ownerId' => null, ); // Send message to mark the object deleted diff --git a/fedora_repository.module b/fedora_repository.module index 1646ce4f..eeee9851 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -2150,13 +2150,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()) { @@ -2172,6 +2175,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( @@ -2185,10 +2189,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 1ee956f1..12a4e08c 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'])) { @@ -149,6 +150,12 @@ function fedora_repository_solution_pack_form(&$form_state, $solution_pack_modul '#type' => 'submit', '#name' => $solution_pack_module, ); + $form['forcesubmit'] = array( + '#value' => t('Force Reinstall'), + //'#disabled' => !$needs_install && !$needs_update, + '#type' => 'submit', + '#name' => $solution_pack_module, + ); $form['#submit'] = array( 'fedora_repository_solution_pack_form_submit', @@ -159,7 +166,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', @@ -171,6 +182,9 @@ function fedora_repository_solution_pack_form_submit($form, &$form_state) { // Add this object to the batch job queue. $batch['operations'][] = array('fedora_repository_batch_reingest_object', array($object)); } + foreach($batch['operations'] as $key => $value) { + //var_dump($value); + } batch_set($batch); } From c5bcc3d082476386bbfa108ee8b3f55876a3bb8a Mon Sep 17 00:00:00 2001 From: Ben Woodhead Date: Wed, 7 Mar 2012 14:06:44 -0400 Subject: [PATCH 29/29] Removed some debug info --- fedora_repository.solutionpacks.inc | 3 --- 1 file changed, 3 deletions(-) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index 12a4e08c..1fa64a9c 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -182,9 +182,6 @@ function fedora_repository_solution_pack_form_submit($form, &$form_state) { // Add this object to the batch job queue. $batch['operations'][] = array('fedora_repository_batch_reingest_object', array($object)); } - foreach($batch['operations'] as $key => $value) { - //var_dump($value); - } batch_set($batch); }