From a788cc52a0d9f83deb047e57ac0d79b530612ac0 Mon Sep 17 00:00:00 2001 From: willtp87 Date: Wed, 4 Mar 2015 13:40:01 -0400 Subject: [PATCH 01/12] Allowing more object altering in hooks. --- includes/tuque_wrapper.inc | 6 ++++-- tests/includes/utilities.inc | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index d14a86b3..f5044db0 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -276,8 +276,10 @@ class IslandoraFedoraApiM extends FedoraApiM { ); islandora_alter_datastream($object, $datastream, $context); $params = $context['params']; - if (isset($params['lastModifiedDate'])) { - $params['lastModifiedDate'] = (string) $object[$dsid]->createdDate; + // Anything may be altered during the alter_datastream hook invocation so + // 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']) { throw new Exception('Modify Datastream was blocked.'); diff --git a/tests/includes/utilities.inc b/tests/includes/utilities.inc index 4eef5255..eefae4cc 100644 --- a/tests/includes/utilities.inc +++ b/tests/includes/utilities.inc @@ -315,7 +315,7 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { * * @return bool * TRUE if all objects were removed, or FALSE if any of them still remained - * after removal. + * after removal. */ public function deleteUserCreatedObjects($username) { if ($username === $this->configuration['admin_user']) { From f65607bb0c35bd16c557bc0ed36eade4d0397bc7 Mon Sep 17 00:00:00 2001 From: willtp87 Date: Thu, 5 Mar 2015 12:30:34 -0400 Subject: [PATCH 02/12] Not nuking object continuity. --- includes/tuque_wrapper.inc | 99 +++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index f5044db0..f4667e43 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -233,6 +233,56 @@ class IslandoraFedoraObject extends FedoraObject { 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, + ); + islandora_alter_datastream($this, $this[$id], $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': + $this[$id]->state = 'D'; + return array(); + + default: + $this->repository->api->m->purgeDatastream($this->id, $id); + unset($this->datastreams[$id]); + $this->refresh(); + islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_PURGED_HOOK, $this->models, $id, $this, $id); + return TRUE; + } + } + catch (Exception $e) { + watchdog('islandora', 'Failed to purge datastream @dsid from @pid
code: @code
message: @msg', array( + '@pid' => $this->id, + '@dsid' => $id, + '@code' => $e->getCode(), + '@msg' => $e->getMessage()), WATCHDOG_ERROR); + throw $e; + } + } } class IslandoraRepositoryConnection extends RepositoryConnection {} @@ -307,55 +357,6 @@ class IslandoraFedoraApiM extends FedoraApiM { 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
code: @code
message: @msg', array( - '@pid' => $pid, - '@dsid' => $dsid, - '@code' => $e->getCode(), - '@msg' => $e->getMessage()), WATCHDOG_ERROR); - throw $e; - } - } - /** * Purge an object. * From 8eecf42360a42acc08fff139d688859dc7dcc033 Mon Sep 17 00:00:00 2001 From: willtp87 Date: Thu, 5 Mar 2015 14:05:12 -0400 Subject: [PATCH 03/12] Playing nice with the parents, cause @adam-vessey made me. --- includes/tuque_wrapper.inc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index f4667e43..dbb60731 100644 --- a/includes/tuque_wrapper.inc +++ b/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) { 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) { module_load_include('inc', 'islandora', 'includes/utilities'); @@ -253,8 +253,8 @@ class IslandoraFedoraObject extends FedoraObject { 'delete' => FALSE, 'block' => FALSE, ); - islandora_alter_datastream($this, $this[$id], $context); try { + islandora_alter_datastream($this, $this[$id], $context); $action = $context['block'] ? 'block' : FALSE; $action = (!$action && $context['delete']) ? 'delete' : $action; $action = !$action ? 'purge' : $action; @@ -267,10 +267,7 @@ class IslandoraFedoraObject extends FedoraObject { return array(); default: - $this->repository->api->m->purgeDatastream($this->id, $id); - unset($this->datastreams[$id]); - $this->refresh(); - islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_PURGED_HOOK, $this->models, $id, $this, $id); + parent::purgeDatastream($id); return TRUE; } } @@ -337,6 +334,16 @@ class IslandoraFedoraApiM extends FedoraApiM { return parent::modifyDatastream($pid, $dsid, $params); } + /** + * Purge a datastream from from Fedora. + * + * @see FedoraApiM::purgeDatastream + */ + public function purgeDatastream($pid, $dsid, $params = array()) { + $object = islandora_object_load($pid); + islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_PURGED_HOOK, $object->models, $dsid, $object, $dsid); + } + /** * Update Fedora Object parameters. * From 3e1c51906d69ff203d2ba7a56b93e377b08f84ce Mon Sep 17 00:00:00 2001 From: willtp87 Date: Thu, 5 Mar 2015 14:13:55 -0400 Subject: [PATCH 04/12] Rely on parent for return. --- includes/tuque_wrapper.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index dbb60731..74129627 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -267,8 +267,7 @@ class IslandoraFedoraObject extends FedoraObject { return array(); default: - parent::purgeDatastream($id); - return TRUE; + return parent::purgeDatastream($id); } } catch (Exception $e) { From 0e82e30d0a370c9d10e3fb09255e2e30e806c6d7 Mon Sep 17 00:00:00 2001 From: willtp87 Date: Thu, 5 Mar 2015 14:38:40 -0400 Subject: [PATCH 05/12] miscomunication and mistakes fixin --- includes/tuque_wrapper.inc | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index 74129627..ef2a2991 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -267,7 +267,9 @@ class IslandoraFedoraObject extends FedoraObject { return array(); default: - return parent::purgeDatastream($id); + $to_return = parent::purgeDatastream($id); + islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_PURGED_HOOK, $this->models, $id, $this, $id); + return $to_return; } } catch (Exception $e) { @@ -333,16 +335,6 @@ class IslandoraFedoraApiM extends FedoraApiM { return parent::modifyDatastream($pid, $dsid, $params); } - /** - * Purge a datastream from from Fedora. - * - * @see FedoraApiM::purgeDatastream - */ - public function purgeDatastream($pid, $dsid, $params = array()) { - $object = islandora_object_load($pid); - islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_PURGED_HOOK, $object->models, $dsid, $object, $dsid); - } - /** * Update Fedora Object parameters. * From ccd7ab7f0251c14ffc4d4e4295777f41556e7f14 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 9 Mar 2015 17:23:58 -0300 Subject: [PATCH 06/12] Slight change to avoid potential caching issues. --- includes/delete_datastream.form.inc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/includes/delete_datastream.form.inc b/includes/delete_datastream.form.inc index ce1959df..cc72a90e 100644 --- a/includes/delete_datastream.form.inc +++ b/includes/delete_datastream.form.inc @@ -19,7 +19,13 @@ * The drupal form definition. */ function islandora_delete_datastream_form(array $form, array &$form_state, AbstractDatastream $datastream) { + // XXX: Stashed version of datastream is deprecated... Use object and + // datastream IDs to acquire. $form_state['datastream'] = $datastream; + $form_state['datastream_info'] = array( + 'object_id' => $datastream->parent->id, + 'datastream_id' => $datastream->id, + ); $object = $datastream->parent; $dsid = $datastream->id; $derivs = implode(', ', islandora_datastream_to_purge($object, $dsid)); @@ -87,9 +93,10 @@ function islandora_datastream_derivatives_purged(AbstractObject $object, $dsid) * The Drupal form state. */ function islandora_delete_datastream_form_submit(array $form, array &$form_state) { - $datastream = $form_state['datastream']; - $datastream_id = $datastream->id; - $object = $datastream->parent; + $object = islandora_object_load($form_state['datastream_info']['object_id']); + $datastream_id = $form_state['datastream_info']['datastream_id']; + $datastream = $object[$datastream_id]; + $deleted = FALSE; if ($form_state['values']['delete_derivatives']) { islandora_datastream_derivatives_purged($object, $datastream_id); From 088a4fad38b50ab4c76495bf6c44af6ad0d9dc20 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 9 Mar 2015 17:36:52 -0300 Subject: [PATCH 07/12] Avoid extra comma when there are no derivatives. --- includes/delete_datastream.form.inc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/delete_datastream.form.inc b/includes/delete_datastream.form.inc index cc72a90e..6e57cd3f 100644 --- a/includes/delete_datastream.form.inc +++ b/includes/delete_datastream.form.inc @@ -20,20 +20,24 @@ */ function islandora_delete_datastream_form(array $form, array &$form_state, AbstractDatastream $datastream) { // XXX: Stashed version of datastream is deprecated... Use object and - // datastream IDs to acquire. + // datastream IDs from 'datastream_info' to acquire. $form_state['datastream'] = $datastream; + $form_state['datastream_info'] = array( 'object_id' => $datastream->parent->id, 'datastream_id' => $datastream->id, ); $object = $datastream->parent; $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( '#title' => t('Delete Derviatives'), '#type' => 'checkbox', '#default_value' => 0, - '#description' => t('Derivatives can be regenerated at a later time.

Datastream(s) to be purged:

@dsid, @derivs', array('@dsid' => $datastream->id, '@derivs' => $derivs)), + '#description' => t('Derivatives can be regenerated at a later time.

Datastream(s) to be purged:

@dsids', array( + '@dsids' => implode(', ', $dsids), + )), ); return confirm_form($form, t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)), From 1814d5af3d5201714575bb5421b7c12f81895adb Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 9 Mar 2015 17:47:31 -0300 Subject: [PATCH 08/12] Somewhat more specific info about the datastreams. --- includes/delete_datastream.form.inc | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/includes/delete_datastream.form.inc b/includes/delete_datastream.form.inc index 6e57cd3f..b88ef0da 100644 --- a/includes/delete_datastream.form.inc +++ b/includes/delete_datastream.form.inc @@ -35,9 +35,28 @@ function islandora_delete_datastream_form(array $form, array &$form_state, Abstr '#title' => t('Delete Derviatives'), '#type' => 'checkbox', '#default_value' => 0, - '#description' => t('Derivatives can be regenerated at a later time.

Datastream(s) to be purged:

@dsids', array( - '@dsids' => implode(', ', $dsids), - )), + '#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, t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)), From c8fdfda96205dfee7d461fd97b90baaa1cf41205 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 9 Mar 2015 17:50:06 -0300 Subject: [PATCH 09/12] Get rid of some unrelated trailing space... --- tests/includes/utilities.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/includes/utilities.inc b/tests/includes/utilities.inc index 4eef5255..eefae4cc 100644 --- a/tests/includes/utilities.inc +++ b/tests/includes/utilities.inc @@ -315,7 +315,7 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { * * @return bool * TRUE if all objects were removed, or FALSE if any of them still remained - * after removal. + * after removal. */ public function deleteUserCreatedObjects($username) { if ($username === $this->configuration['admin_user']) { From b7816b33b279c507ca84a30ffda9c92d095a0cec Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 10 Mar 2015 14:52:51 -0300 Subject: [PATCH 10/12] Option to not render breadcrumbs. --- includes/admin.form.inc | 6 ++++++ includes/breadcrumb.inc | 11 +++++++---- islandora.install | 7 +++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/includes/admin.form.inc b/includes/admin.form.inc index 51116f5c..cf0b8f69 100644 --- a/includes/admin.form.inc +++ b/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'), '#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( '#type' => 'fieldset', diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index e3eb2782..38c0970e 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -25,10 +25,13 @@ * drupal_set_breadcrumb(). */ function islandora_get_breadcrumbs($object) { - $breadcrumbs = islandora_get_breadcrumbs_recursive($object->id, $object->repository); - array_pop($breadcrumbs); - $context = 'islandora'; - drupal_alter('islandora_breadcrumbs', $breadcrumbs, $context, $object); + $breadcrumbs = array(); + if (variable_get('islandora_render_drupal_breadcrumbs', TRUE)) { + $breadcrumbs = islandora_get_breadcrumbs_recursive($object->id, $object->repository); + array_pop($breadcrumbs); + $context = 'islandora'; + drupal_alter('islandora_breadcrumbs', $breadcrumbs, $context, $object); + } return $breadcrumbs; } diff --git a/islandora.install b/islandora.install index 12c92009..a2151767 100644 --- a/islandora.install +++ b/islandora.install @@ -47,6 +47,13 @@ function islandora_uninstall() { $variables = array( 'islandora_ds_replace_exclude_enforced', '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'); } From b23431ce38be24ad47e66008d4364293df2382f5 Mon Sep 17 00:00:00 2001 From: willtp87 Date: Thu, 12 Mar 2015 10:48:48 -0300 Subject: [PATCH 11/12] Copy pasta fix --- islandora.api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/islandora.api.php b/islandora.api.php index dad43838..5d241991 100644 --- a/islandora.api.php +++ b/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. * * @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 * 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() */ From 097469ad8ed5d5181d6b616252b64d16d6478be3 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Mar 2015 13:44:43 -0300 Subject: [PATCH 12/12] Expand on documentation of hook_islandora_edit_datastream_registry(). --- islandora.api.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/islandora.api.php b/islandora.api.php index 5d241991..bbb7a6d9 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -361,9 +361,22 @@ function hook_cmodel_pid_islandora_datastream_purged(AbstractObject $object, $ds * @param AbstractObject $object * The object to check. * @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) { + $routes = array(); + + $routes[] = array( + 'name' => t('My Awesome Edit Route'), + 'url' => "go/edit/here/{$object->id}/{$dsid}", + ); + + return $routes; } /**