Browse Source

Filled out the purge/delete object callback

pull/108/merge
rwincewicz 13 years ago
parent
commit
748b57938b
  1. 120
      includes/ingest-menu.inc
  2. 51
      islandora.module

120
includes/ingest-menu.inc

@ -14,20 +14,20 @@ 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
@ -41,3 +41,95 @@ function islandora_ingest_registry_render($ingest_registry) {
}
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 = '<mods xmlns="http://www.loc.gov/mods/v3" ID="TopTier/Breast/">
<titleInfo>
<title>Selective chemical probe
inhibitor of Stat3, identified through structure-based virtual screening,
induces antitumor activity</title>
</titleInfo>
<name type="personal">
<namePart type="given">K</namePart>
<namePart type="family">Siddiquee</namePart>
<role>
<roleTerm authority="marcrelator" type="text">author</roleTerm>
</role>
</name>
</mods>';
$mods->label = 'MODS record';
$mods->setContentFromString($mods_string);
$object->ingestDatastream($mods);
$mads = $object->constructDatastream('MADS', 'M', $object, $restConnection->repository);
$mads_string = '<mods xmlns="http://www.loc.gov/mods/v3" ID="TopTier/Breast/">
<titleInfo>
<title>Selective chemical probe
inhibitor of Stat3, identified through structure-based virtual screening,
induces antitumor activity</title>
</titleInfo>
<name type="personal">
<namePart type="given">K</namePart>
<namePart type="family">Siddiquee</namePart>
<role>
<roleTerm authority="marcrelator" type="text">author</roleTerm>
</role>
</name>
</mods>';
$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"";
}
}

51
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) {
}
/**
* 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 type $object_id
* @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();
}
/**

Loading…
Cancel
Save