Browse Source

Merge branch '7.x' of github.com:Islandora/islandora into 7.x

pull/109/merge
Paul Pound 13 years ago
parent
commit
d733fef8c5
  1. 49
      islandora.module

49
islandora.module

@ -124,6 +124,7 @@ function islandora_menu() {
$items['islandora/object/%/delete'] = array( $items['islandora/object/%/delete'] = array(
'title' => 'Purge object', 'title' => 'Purge object',
'page callback' => 'islandora_purge_object', 'page callback' => 'islandora_purge_object',
'page arguments' => array(2),
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_PURGE), 'access arguments' => array(FEDORA_PURGE),
); );
@ -206,22 +207,58 @@ function islandora_node_access($op, $pid = NULL, $as_user = NULL) {
} }
/** /**
* * Gives the option of deleting or purging and object.
* @param type $object_id *
* 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 * @return type
*/ */
function islandora_purge_object($object_id) { function islandora_purge_object($object_id) {
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
if (!isset($object_id)) { if (!isset($object_id)) {
drupal_set_message(t('Cannot remove object, object id not set')); drupal_set_message(t('Cannot remove object, object 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')); drupal_set_message(t('Could not remove object, object not found'));
return; return;
} }
module_invoke_all('islandora_purge_object', $object); //notify modules of pending deletion $content_models = $fedora_object->models;
$object->delete(); $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
} }
/** /**

Loading…
Cancel
Save