Browse Source

Filled out purge/delete datastream callback

pull/108/merge
rwincewicz 13 years ago
parent
commit
17a2a1a734
  1. 62
      islandora.module

62
islandora.module

@ -156,7 +156,7 @@ function islandora_menu() {
$items['islandora/object/%/datastream/%/edit'] = array( $items['islandora/object/%/datastream/%/edit'] = array(
'title' => 'Edit datastream', 'title' => 'Edit datastream',
'page callback' => 'islandora_edit_stream', 'page callback' => 'islandora_edit_datastream',
'page arguments' => array(2, 4), 'page arguments' => array(2, 4),
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_METADATA_EDIT), 'access arguments' => array(FEDORA_METADATA_EDIT),
@ -164,7 +164,7 @@ function islandora_menu() {
$items['islandora/object/%/datastream/%/delete'] = array( $items['islandora/object/%/datastream/%/delete'] = array(
'title' => 'Purge data stream', 'title' => 'Purge data stream',
'page callback' => 'islandora_purge_stream', 'page callback' => 'islandora_purge_datastream',
'page arguments' => array(2, 4), 'page arguments' => array(2, 4),
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_PURGE), 'access arguments' => array(FEDORA_PURGE),
@ -240,7 +240,7 @@ function islandora_purge_object($object_id) {
} }
$content_models = $fedora_object->models; $content_models = $fedora_object->models;
$arr = module_invoke_all('islandora_pre_purge_object', $fedora_object); //notify modules of pending deletion $arr = module_invoke_all('islandora_pre_purge_object', $fedora_object); //notify modules of pending deletion
if ($arr['delete']) { if (isset($arr['delete']) && $arr['delete']) {
try { try {
$fedora_object->delete(); $fedora_object->delete();
} catch (Exception $e) { } catch (Exception $e) {
@ -294,7 +294,6 @@ function islandora_edit_object($object_id) {
return $output; return $output;
} }
/** /**
* builds a default page for the edit tab * builds a default page for the edit tab
* @param object $fedora_object * @param object $fedora_object
@ -306,24 +305,68 @@ function islandora_islandora_edit_object($fedora_object){
} }
/** /**
* Gives the option of purging or deleting a datastream.
*
* The default behaviour is to purge the datastream but this can be overridden using the
* 'islandora_pre_purge_datastream' hook. The returned array can include a 'block' => TRUE
* pair which will prevent the datastream from being deleted if it particularly needed for
* a certain function. Returning 'delete' => TRUE will cause the datastream to be put into
* a deleted state.
* *
* @param string $object_id
* ID of the object
* @param string $datastream_id * @param string $datastream_id
* @return type * ID of the datastream
*
*/ */
function islandora_purge_datastream($object_id, $datastream_id) { function islandora_purge_datastream($object_id, $datastream_id) {
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
if (!isset($datastream_id)) { if (!isset($datastream_id)) {
drupal_set_message(t('Cannot remove datastream, datastream id not set')); drupal_set_message(t('Cannot remove datastream, datastream id not set'));
return; return;
} }
$object = new Object($object_id); try {
if (!isset($object)) { $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;
}
if (!isset($fedora_object)) {
drupal_set_message(t('Could not remove object, object not found')); drupal_set_message(t('Could not remove object, object not found'));
return; return;
} }
module_invoke_all('islandora_purge_datastream', $datastream); //notify modules of pending deletion so we can update rels etc $arr = module_invoke_all('islandora_pre_purge_datastream', $fedora_object, $datastream_id); //notify modules of pending deletion so we can update rels etc
$object->deleteDatastream(); if (isset($arr['block']) && $arr['block']) {
drupal_set_message(t('Purging of the %d datastream was blocked', array('%d' => $datastream_id)), 'warning');
return;
}
if (isset($arr['delete']) && $arr['delete']) {
try {
$datastream = new FedoraDatastream($datastream_id, $fedora_object, $restConnection->repository);
$datastream->state = 'D';
} catch (Exception $e) {
drupal_set_message(t('Error deleting %s datastream from Islandora object %o', array('%s' => $datastream_id, '%o' => $object_id)), 'error');
return;
}
}
else {
try {
$fedora_object->purgeDatastream($datastream_id);
} catch (Exception $e) {
drupal_set_message(t('Error purging %s datastream from Islandora object %o', array('%s' => $datastream_id, '%o' => $object_id)), 'error');
return;
}
}
module_invoke_all('islandora_post_purge_datastream', $fedora_object, $datastream_id); //notify modules post deletion
} }
/** /**
* The view entry point. modules should implement hook_islandora_view_object for the Fedora Content models that * The view entry point. modules should implement hook_islandora_view_object for the Fedora Content models that
* there modules want to provide a view for. * there modules want to provide a view for.
@ -473,5 +516,4 @@ function islandora_preprocess_islandora_default(&$variables) {
function islandora_preprocess_islandora_default_edit(&$variables) { function islandora_preprocess_islandora_default_edit(&$variables) {
//$islandora_object = $variables['islandora_object']; //$islandora_object = $variables['islandora_object'];
} }
Loading…
Cancel
Save