From 748b57938b9298c3ad28ce0fa191a9f321ecd463 Mon Sep 17 00:00:00 2001 From: rwincewicz Date: Wed, 23 May 2012 13:19:42 -0300 Subject: [PATCH] Filled out the purge/delete object callback --- includes/ingest-menu.inc | 122 ++++++++++++++++++++++++++++++++++----- islandora.module | 53 +++++++++++++++-- 2 files changed, 154 insertions(+), 21 deletions(-) diff --git a/includes/ingest-menu.inc b/includes/ingest-menu.inc index b2e795a2..172da2b7 100644 --- a/includes/ingest-menu.inc +++ b/includes/ingest-menu.inc @@ -12,22 +12,22 @@ */ function islandora_ingest_callback($collection_pid) { $ingest_registry = module_invoke_all('islandora_ingest_registry', $collection_pid); - + $registry_count = count($ingest_registry); - - if ($registry_count == 0) { - // No ingest implementations. - drupal_set_message(t('There are no ingest methods specified for this collection.')); - drupal_goto('islandora/object/' . $collection_pid); - } - elseif ($registry_count == 1) { - // One registry implementation, go there - drupal_goto($ingest_registry[0]['url']); - } - else { - // Multiple ingest routes registered - return islandora_ingest_registry_render($ingest_registry); - } + islandora_ingest_object(); +// if ($registry_count == 0) { +// // No ingest implementations. +// drupal_set_message(t('There are no ingest methods specified for this collection.')); +// drupal_goto('islandora/object/' . $collection_pid); +// } +// elseif ($registry_count == 1) { +// // One registry implementation, go there +// drupal_goto($ingest_registry[0]['url']); +// } +// else { +// // Multiple ingest routes registered +// return islandora_ingest_registry_render($ingest_registry); +// } } //@TODO: theme @@ -40,4 +40,96 @@ function islandora_ingest_registry_render($ingest_registry) { $output['#markup'] .= l($ingest_route['name'], $ingest_route['url']) . '
'; } return $output; +} + +function islandora_ingest_object($object = NULL) { + module_load_include('inc', 'islandora', 'RestConnection'); + include_once 'sites/all/libraries/tuque/FoxmlDocument.php'; + $user = new stdClass(); + $user->name = 'fedoraAdmin'; + $user->password = 'fedoraAdmin'; + try { + $restConnection = new RestConnection($user); + $object = $restConnection->repository->constructObject('test'); + $new_pid = $object->id; + $object->label = 'foo'; + $object->state = 'a'; + $object->owner = 'woot'; + + $test = $object->constructDatastream('TEST', 'M', $object, $restConnection->repository); + $test->label = 'Test'; + $test->setContentFromFile('http://d7test/sites/default/files/coder_upgrade/theme_cache.txt'); + $test->checksumType = 'MD5'; + $test->format = 'http://www.openarchives.org/OAI/2.0/oai_dc/'; + $object->ingestDatastream($test); + + $test2 = $object->constructDatastream('TEST2', 'R', $object, $restConnection->repository); + $test2->label = 'Test2'; + $test2->url = 'http://d7test/sites/default/files/coder_upgrade/theme_cache.txt'; + $object->ingestDatastream($test2); + + $test3 = $object->constructDatastream('TEST3', 'E', $object, $restConnection->repository); + $test3->label = 'Test3'; + $test3->url = 'http://d7test/sites/default/files/coder_upgrade/theme_cache.txt'; + $object->ingestDatastream($test3); + + $mods = $object->constructDatastream('MODS', 'X', $object, $restConnection->repository); + + $mods_string = ' + + Selective chemical probe + inhibitor of Stat3, identified through structure-based virtual screening, + induces antitumor activity + + + K + Siddiquee + + author + + + '; + $mods->label = 'MODS record'; + $mods->setContentFromString($mods_string); + $object->ingestDatastream($mods); + + $mads = $object->constructDatastream('MADS', 'M', $object, $restConnection->repository); + + $mads_string = ' + + Selective chemical probe + inhibitor of Stat3, identified through structure-based virtual screening, + induces antitumor activity + + + K + Siddiquee + + author + + + '; + $mads->label = 'MADS record'; + $mads->setContentFromString($mads_string); + $object->ingestDatastream($mads); +// $object->relationship = 'isConnectedTo'; + $object->collectionPid = 'islandora:root'; + $object->contentModelPid = 'islandora:collectionCModel'; + +// $datastream = $object->constructDatastream('test'); + + $object->relationships->add(ISLANDORA_RELS_EXT_URI, 'hasAwesomeness', 'jonathan:green'); +// $object->relationships->add(FEDORA_MODEL_URI, 'hasModel', 'islandora:model'); +// $object->relationships->add(ISLANDORA_RELS_EXT_URI, 'isPage', '22', TRUE); +// $object->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'theawesomecollection:awesome'); +// $object->relationships->add(FEDORA_MODEL_URI, 'hasModel', 'islandora:woot'); +// $object->ingestDatastream($datastream); + +// var_dump($object); + + $return = $restConnection->repository->ingestObject($object); + } catch (Exception $e) { + drupal_set_message(t('Error getting Islandora object %s', array('%s' => $object->id)), 'error'); + return""; + } } \ No newline at end of file diff --git a/islandora.module b/islandora.module index e0f4aee7..3e1a45d8 100644 --- a/islandora.module +++ b/islandora.module @@ -122,6 +122,7 @@ function islandora_menu() { $items['islandora/object/%/delete'] = array( 'title' => 'Purge object', 'page callback' => 'islandora_purge_object', + 'page arguments' => array(2), 'type' => MENU_CALLBACK, 'access arguments' => array(FEDORA_PURGE), ); @@ -204,22 +205,62 @@ function islandora_node_access($op, $pid = NULL, $as_user = NULL) { } /** - * - * @param type $object_id + * Gives the option of deleting or purging and object. + * + * The default behaviour is to purge the object to reduce maintenance. + * If a solution pack wants to change this behaviour and have the object set to deleted then + * it can respond to the 'islandora_pre_purge_object' hook with an array containing the pair + * 'delete' => TRUE. + * Once the object has been deleted/purged then a second call lets the solution packs know that + * the object has been dealt with. In this call the object id and content models are sent out so + * that the solution packs can act on this news. There is no guarantee that the object still exists + * and so the object object isn't sent. + * + * @param string $object_id + * ID of the object * @return type */ function islandora_purge_object($object_id) { + module_load_include('inc', 'islandora', 'RestConnection'); + global $user; if (!isset($object_id)) { drupal_set_message(t('Cannot remove object, object id not set')); return; } - $object = new Object($object_id); - if (!isset($object)) { + try { + $restConnection = new RestConnection($user); + $fedora_object = new FedoraObject($object_id, $restConnection->repository); + } catch (Exception $e) { + drupal_set_message(t('Error getting Islandora object %s', array('%s' => $object_id)), 'error'); + return ""; + } + if (!isset($fedora_object)) { drupal_set_message(t('Could not remove object, object not found')); return; } - module_invoke_all('islandora_purge_object', $object); //notify modules of pending deletion - $object->delete(); + $content_models = $fedora_object->models; + $arr = module_invoke_all('islandora_pre_purge_object', $fedora_object); //notify modules of pending deletion + if ($arr['delete']) { + try { + $fedora_object->delete(); + } catch (Exception $e) { + drupal_set_message(t('Error deleting Islandora object %s', array('%s' => $object_id)), 'error'); + return ""; + } + } + else { + try { + $restConnection->repository->purgeObject($object_id); + } catch (Exception $e) { + drupal_set_message(t('Error purging Islandora object %s', array('%s' => $object_id)), 'error'); + return ""; + } + } + module_invoke_all('islandora_post_purge_object', $object_id, $content_models); //notify modules post deletion +} + +function islandora_islandora_pre_purge_object($object) { + return array(); } /**