Browse Source

Merge pull request #587 from willtp87/7.x.more_409s

7.x.more 409s
pull/589/head
Nick Ruest 10 years ago
parent
commit
511f9e05b6
  1. 107
      includes/tuque_wrapper.inc
  2. 2
      tests/includes/utilities.inc

107
includes/tuque_wrapper.inc

@ -56,7 +56,7 @@ function islandora_alter_datastream(AbstractObject $object, AbstractDatastream $
} }
/** /**
* Constructs a list of hooks from the given paramenters and invokes them. * Constructs a list of hooks from the given parameters and invokes them.
*/ */
function islandora_invoke_object_hooks($hook, array $models) { function islandora_invoke_object_hooks($hook, array $models) {
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
@ -64,7 +64,7 @@ function islandora_invoke_object_hooks($hook, array $models) {
} }
/** /**
* Constructs a list of hooks from the given paramenters and invokes them. * Constructs a list of hooks from the given parameters and invokes them.
*/ */
function islandora_invoke_datastream_hooks($hook, array $models, $dsid) { function islandora_invoke_datastream_hooks($hook, array $models, $dsid) {
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
@ -233,6 +233,54 @@ class IslandoraFedoraObject extends FedoraObject {
throw $e; throw $e;
} }
} }
/**
* Purge a datastream.
*
* Invokes datastream altered/purged hooks and calls the API-M method.
*
* @see FedoraObject::purgeObject()
*/
public function purgeDatastream($id) {
$this->populateDatastreams();
if (!array_key_exists($id, $this->datastreams)) {
return FALSE;
}
$context = array(
'action' => 'purge',
'purge' => TRUE,
'delete' => FALSE,
'block' => FALSE,
);
try {
islandora_alter_datastream($this, $this[$id], $context);
$action = $context['block'] ? 'block' : FALSE;
$action = (!$action && $context['delete']) ? 'delete' : $action;
$action = !$action ? 'purge' : $action;
switch ($action) {
case 'block':
throw new Exception('Purge Datastream was blocked.');
case 'delete':
$this[$id]->state = 'D';
return array();
default:
$to_return = parent::purgeDatastream($id);
islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_PURGED_HOOK, $this->models, $id, $this, $id);
return $to_return;
}
}
catch (Exception $e) {
watchdog('islandora', 'Failed to purge datastream @dsid from @pid</br>code: @code<br/>message: @msg', array(
'@pid' => $this->id,
'@dsid' => $id,
'@code' => $e->getCode(),
'@msg' => $e->getMessage()), WATCHDOG_ERROR);
throw $e;
}
}
} }
class IslandoraRepositoryConnection extends RepositoryConnection {} class IslandoraRepositoryConnection extends RepositoryConnection {}
@ -276,8 +324,10 @@ class IslandoraFedoraApiM extends FedoraApiM {
); );
islandora_alter_datastream($object, $datastream, $context); islandora_alter_datastream($object, $datastream, $context);
$params = $context['params']; $params = $context['params'];
if (isset($params['lastModifiedDate'])) { // Anything may be altered during the alter_datastream hook invocation so
$params['lastModifiedDate'] = (string) $object[$dsid]->createdDate; // we need to update our time to the change we know about.
if (isset($params['lastModifiedDate']) && $params['lastModifiedDate'] < (string) $object->lastModifiedDate) {
$params['lastModifiedDate'] = (string) $object->lastModifiedDate;
} }
if ($context['block']) { if ($context['block']) {
throw new Exception('Modify Datastream was blocked.'); throw new Exception('Modify Datastream was blocked.');
@ -305,55 +355,6 @@ class IslandoraFedoraApiM extends FedoraApiM {
return parent::modifyObject($pid, $params); return parent::modifyObject($pid, $params);
} }
/**
* Purge a datastream from from Fedora.
*
* @see FedoraApiM::purgeDatastream
*/
public function purgeDatastream($pid, $dsid, $params = array()) {
$object = islandora_object_load($pid);
$context = array(
'action' => 'purge',
'purge' => TRUE,
'delete' => FALSE,
'block' => FALSE,
);
islandora_alter_datastream($object, $object[$dsid], $context);
try {
$action = $context['block'] ? 'block' : FALSE;
$action = (!$action && $context['delete']) ? 'delete' : $action;
$action = !$action ? 'purge' : $action;
switch ($action) {
case 'block':
throw new Exception('Purge Datastream was blocked.');
case 'delete':
$object[$dsid]->state = 'D';
return array();
default:
$ret = parent::purgeDatastream($pid, $dsid, $params);
// We need to remove this object from the cache and reload it as
// Tuque may not have an updated copy. That is the datastream could
// still be present within the object even though it's purged out of
// Fedora.
$tuque = islandora_get_tuque_connection();
$tuque->cache->delete($pid);
$non_cached_object = islandora_object_load($pid);
islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_PURGED_HOOK, $non_cached_object->models, $dsid, $non_cached_object, $dsid);
return $ret;
}
}
catch (Exception $e) {
watchdog('islandora', 'Failed to purge datastream @dsid from @pid</br>code: @code<br/>message: @msg', array(
'@pid' => $pid,
'@dsid' => $dsid,
'@code' => $e->getCode(),
'@msg' => $e->getMessage()), WATCHDOG_ERROR);
throw $e;
}
}
/** /**
* Purge an object. * Purge an object.
* *

2
tests/includes/utilities.inc

@ -315,7 +315,7 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass {
* *
* @return bool * @return bool
* TRUE if all objects were removed, or FALSE if any of them still remained * TRUE if all objects were removed, or FALSE if any of them still remained
* after removal. * after removal.
*/ */
public function deleteUserCreatedObjects($username) { public function deleteUserCreatedObjects($username) {
if ($username === $this->configuration['admin_user']) { if ($username === $this->configuration['admin_user']) {

Loading…
Cancel
Save