Kylea Jackson 10 years ago
parent
commit
6d780f5feb
  1. 6
      includes/admin.form.inc
  2. 11
      includes/breadcrumb.inc
  3. 40
      includes/delete_datastream.form.inc
  4. 107
      includes/tuque_wrapper.inc
  5. 19
      islandora.api.php
  6. 7
      islandora.install

6
includes/admin.form.inc

@ -74,6 +74,12 @@ function islandora_repository_admin(array $form, array &$form_state) {
'#description' => t('Displays an extra print tab, allowing an object to be printed'), '#description' => t('Displays an extra print tab, allowing an object to be printed'),
'#default_value' => variable_get('islandora_show_print_option', FALSE), '#default_value' => variable_get('islandora_show_print_option', FALSE),
), ),
'islandora_render_drupal_breadcrumbs' => array(
'#type' => 'checkbox',
'#title' => t('Render Drupal breadcrumbs'),
'#description' => t('Larger sites may experience a notable performance improvement when disabled due to how breadcrumbs are constructed.'),
'#default_value' => variable_get('islandora_render_drupal_breadcrumbs', TRUE),
),
), ),
'islandora_namespace' => array( 'islandora_namespace' => array(
'#type' => 'fieldset', '#type' => 'fieldset',

11
includes/breadcrumb.inc

@ -25,10 +25,13 @@
* drupal_set_breadcrumb(). * drupal_set_breadcrumb().
*/ */
function islandora_get_breadcrumbs($object) { function islandora_get_breadcrumbs($object) {
$breadcrumbs = islandora_get_breadcrumbs_recursive($object->id, $object->repository); $breadcrumbs = array();
array_pop($breadcrumbs); if (variable_get('islandora_render_drupal_breadcrumbs', TRUE)) {
$context = 'islandora'; $breadcrumbs = islandora_get_breadcrumbs_recursive($object->id, $object->repository);
drupal_alter('islandora_breadcrumbs', $breadcrumbs, $context, $object); array_pop($breadcrumbs);
$context = 'islandora';
drupal_alter('islandora_breadcrumbs', $breadcrumbs, $context, $object);
}
return $breadcrumbs; return $breadcrumbs;
} }

40
includes/delete_datastream.form.inc

@ -19,15 +19,44 @@
* The drupal form definition. * The drupal form definition.
*/ */
function islandora_delete_datastream_form(array $form, array &$form_state, AbstractDatastream $datastream) { function islandora_delete_datastream_form(array $form, array &$form_state, AbstractDatastream $datastream) {
// XXX: Stashed version of datastream is deprecated... Use object and
// datastream IDs from 'datastream_info' to acquire.
$form_state['datastream'] = $datastream; $form_state['datastream'] = $datastream;
$form_state['datastream_info'] = array(
'object_id' => $datastream->parent->id,
'datastream_id' => $datastream->id,
);
$object = $datastream->parent; $object = $datastream->parent;
$dsid = $datastream->id; $dsid = $datastream->id;
$derivs = implode(', ', islandora_datastream_to_purge($object, $dsid)); $dsids = array_merge(array($dsid), islandora_datastream_to_purge($object, $dsid));
$dsids = array_unique($dsids);
$form['delete_derivatives'] = array( $form['delete_derivatives'] = array(
'#title' => t('Delete Derviatives'), '#title' => t('Delete Derviatives'),
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => 0, '#default_value' => 0,
'#description' => t('Derivatives can be regenerated at a later time. <p><strong>Datastream(s) to be purged: </strong></p>@dsid, @derivs', array('@dsid' => $datastream->id, '@derivs' => $derivs)), '#description' => t('Derivatives can be regenerated at a later time.'),
);
$form['base_info'] = array(
'#type' => 'item',
'#title' => t('Datastream to be purged'),
'#markup' => $dsid,
'#states' => array(
'invisible' => array(
':input[name="delete_derivatives"]' => array('checked' => TRUE),
),
),
);
$form['derivative_info'] = array(
'#type' => 'item',
'#title' => t('Datastream(s) to be purged'),
'#description' => t('Including detectable derivatives.'),
'#markup' => implode(', ', $dsids),
'#states' => array(
'visible' => array(
':input[name="delete_derivatives"]' => array('checked' => TRUE),
),
),
); );
return confirm_form($form, return confirm_form($form,
t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)), t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)),
@ -87,9 +116,10 @@ function islandora_datastream_derivatives_purged(AbstractObject $object, $dsid)
* The Drupal form state. * The Drupal form state.
*/ */
function islandora_delete_datastream_form_submit(array $form, array &$form_state) { function islandora_delete_datastream_form_submit(array $form, array &$form_state) {
$datastream = $form_state['datastream']; $object = islandora_object_load($form_state['datastream_info']['object_id']);
$datastream_id = $datastream->id; $datastream_id = $form_state['datastream_info']['datastream_id'];
$object = $datastream->parent; $datastream = $object[$datastream_id];
$deleted = FALSE; $deleted = FALSE;
if ($form_state['values']['delete_derivatives']) { if ($form_state['values']['delete_derivatives']) {
islandora_datastream_derivatives_purged($object, $datastream_id); islandora_datastream_derivatives_purged($object, $datastream_id);

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.
* *

19
islandora.api.php

@ -245,7 +245,7 @@ function hook_cmodel_pid_islandora_object_ingested(AbstractObject $object) {
* modifications, where as manipulating an object's datstreams are not. * modifications, where as manipulating an object's datstreams are not.
* *
* @param AbstractObject $object * @param AbstractObject $object
* The object that was ingested. * The object that was modified.
* *
* @todo We should also include what changes were made in a additional * @todo We should also include what changes were made in a additional
* parameter. * parameter.
@ -254,7 +254,7 @@ function hook_islandora_object_modified(AbstractObject $object) {
} }
/** /**
* Notify modules that the given object was ingested. * Notify modules that the given object was modified.
* *
* @see hook_islandora_object_modified() * @see hook_islandora_object_modified()
*/ */
@ -361,9 +361,22 @@ function hook_cmodel_pid_islandora_datastream_purged(AbstractObject $object, $ds
* @param AbstractObject $object * @param AbstractObject $object
* The object to check. * The object to check.
* @param string $dsid * @param string $dsid
* todo * A string indicating the datastream for which to get the registry.
*
* @return array
* An array of associative arrays, each mapping:
* - name: A string containg a human-readable name for the entry.
* - url: A string containing the URL to which to the user will be routed.
*/ */
function hook_islandora_edit_datastream_registry($object, $dsid) { function hook_islandora_edit_datastream_registry($object, $dsid) {
$routes = array();
$routes[] = array(
'name' => t('My Awesome Edit Route'),
'url' => "go/edit/here/{$object->id}/{$dsid}",
);
return $routes;
} }
/** /**

7
islandora.install

@ -47,6 +47,13 @@ function islandora_uninstall() {
$variables = array( $variables = array(
'islandora_ds_replace_exclude_enforced', 'islandora_ds_replace_exclude_enforced',
'islandora_defer_derivatives_on_ingest', 'islandora_defer_derivatives_on_ingest',
'islandora_base_url',
'islandora_repository_pid',
'islandora_use_datastream_cache_headers',
'islandora_show_print_option',
'islandora_render_drupal_breadcrumbs',
'islandora_namespace_restriction_enforced',
'islandora_pids_allowed',
); );
array_walk($variables, 'variable_del'); array_walk($variables, 'variable_del');
} }

Loading…
Cancel
Save