Browse Source

Filled out purge/delete datastream callback

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

70
islandora.module

@ -156,7 +156,7 @@ function islandora_menu() {
$items['islandora/object/%/datastream/%/edit'] = array(
'title' => 'Edit datastream',
'page callback' => 'islandora_edit_stream',
'page callback' => 'islandora_edit_datastream',
'page arguments' => array(2, 4),
'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_METADATA_EDIT),
@ -164,7 +164,7 @@ function islandora_menu() {
$items['islandora/object/%/datastream/%/delete'] = array(
'title' => 'Purge data stream',
'page callback' => 'islandora_purge_stream',
'page callback' => 'islandora_purge_datastream',
'page arguments' => array(2, 4),
'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_PURGE),
@ -240,7 +240,7 @@ function islandora_purge_object($object_id) {
}
$content_models = $fedora_object->models;
$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 {
$fedora_object->delete();
} catch (Exception $e) {
@ -294,36 +294,79 @@ function islandora_edit_object($object_id) {
return $output;
}
/**
* builds a default page for the edit tab
* @param object $fedora_object
* A tuque Fedora Object
*/
function islandora_islandora_edit_object($fedora_object){
function islandora_islandora_edit_object($fedora_object) {
$output = theme('islandora_default_edit', array('islandora_object' => $fedora_object));
return array ('Default Edit output' => $output);
return array('Default Edit output' => $output);
}
/**
* 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
* ID of the datastream
*
* @paramstring $datastream_id
* @return type
*/
function islandora_purge_datastream($object_id, $datastream_id) {
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
if (!isset($datastream_id)) {
drupal_set_message(t('Cannot remove datastream, datastream 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_datastream', $datastream); //notify modules of pending deletion so we can update rels etc
$object->deleteDatastream();
if (!isset($fedora_object)) {
drupal_set_message(t('Could not remove object, object not found'));
return;
}
$arr = module_invoke_all('islandora_pre_purge_datastream', $fedora_object, $datastream_id); //notify modules of pending deletion so we can update rels etc
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
* there modules want to provide a view for.
@ -471,7 +514,6 @@ 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'];
}
Loading…
Cancel
Save