From df562a7c1e246cecf596a140917da95b9b4892d6 Mon Sep 17 00:00:00 2001 From: Kylea Jackson Date: Tue, 3 Mar 2015 10:39:44 -0400 Subject: [PATCH 1/9] Added checkbox for option to delete derivatives from datastream. --- includes/delete_datastream.form.inc | 31 +++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/includes/delete_datastream.form.inc b/includes/delete_datastream.form.inc index b94e0141..834da7e2 100644 --- a/includes/delete_datastream.form.inc +++ b/includes/delete_datastream.form.inc @@ -1,10 +1,8 @@ t('Delete derivatives?'), + '#type' => 'checkbox', + '#default_value' => 0, + ); return confirm_form($form, t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)), "islandora/object/{$datastream->parent->id}", @@ -28,9 +31,25 @@ function islandora_delete_datastream_form(array $form, array &$form_state, Abstr t('Cancel') ); } - /** - * Submit handler for the delete datastream form. + * Purges datastream derivatives if selected. + * + * Implements hook_islandora_datastream_purged(). + */ +function islandora_datastream_derivatives_purged(AbstractObject $object, $dsid) { + $models = array( + 'ir:citationCModel', + 'ir:thesisCModel', + ); + module_load_include('inc', 'islandora', 'includes/utilities'); + $hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array($object)); + $dsid_map = function ($hook_definition) { + return $hook_definition['destination_dsid']; + }; + $dsids = array_map($dsid_map, $hooks); + array_map(array($object, 'purgeDatastream'), $dsids); +} +/** Submit handler for the delete datastream form. * * Purges/Delete's the given AbstractDatastream if possible. * @@ -48,6 +67,10 @@ function islandora_delete_datastream_form_submit(array $form, array &$form_state $datastream_id = $datastream->id; $object = $datastream->parent; $deleted = FALSE; + + if(!empty($form_state['values']['delete_derivatives'])){ + islandora_datastream_derivatives_purged($object, $datastream_id); + } try { $deleted = islandora_delete_datastream($datastream); } From 8974918573749efe7882254cebcefed46e079b89 Mon Sep 17 00:00:00 2001 From: Kylea Jackson Date: Tue, 3 Mar 2015 12:53:35 -0400 Subject: [PATCH 2/9] Cleaning up changes from adding option to delete derivatives. --- includes/delete_datastream.form.inc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/includes/delete_datastream.form.inc b/includes/delete_datastream.form.inc index 834da7e2..b45c6da6 100644 --- a/includes/delete_datastream.form.inc +++ b/includes/delete_datastream.form.inc @@ -19,7 +19,7 @@ function islandora_delete_datastream_form(array $form, array &$form_state, AbstractDatastream $datastream) { $form_state['datastream'] = $datastream; $form['delete_derivatives'] = array( - '#title' => t('Delete derivatives?'), + '#title' => t('Delete Derviatives'), '#type' => 'checkbox', '#default_value' => 0, ); @@ -32,15 +32,10 @@ function islandora_delete_datastream_form(array $form, array &$form_state, Abstr ); } /** - * Purges datastream derivatives if selected. - * - * Implements hook_islandora_datastream_purged(). + * Purge a given DSID's derivative datastreams on an object. + * */ function islandora_datastream_derivatives_purged(AbstractObject $object, $dsid) { - $models = array( - 'ir:citationCModel', - 'ir:thesisCModel', - ); module_load_include('inc', 'islandora', 'includes/utilities'); $hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array($object)); $dsid_map = function ($hook_definition) { @@ -68,7 +63,7 @@ function islandora_delete_datastream_form_submit(array $form, array &$form_state $object = $datastream->parent; $deleted = FALSE; - if(!empty($form_state['values']['delete_derivatives'])){ + if($form_state['values']['delete_derivatives']){ islandora_datastream_derivatives_purged($object, $datastream_id); } try { From 96a2c32a29e2c25d27087e3dcac19a46479e529b Mon Sep 17 00:00:00 2001 From: Kylea Jackson Date: Tue, 3 Mar 2015 15:16:40 -0400 Subject: [PATCH 3/9] Cleaning up last bit of code standard issues --- includes/delete_datastream.form.inc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/includes/delete_datastream.form.inc b/includes/delete_datastream.form.inc index b45c6da6..d4a46b8b 100644 --- a/includes/delete_datastream.form.inc +++ b/includes/delete_datastream.form.inc @@ -1,8 +1,10 @@ t('Delete Derviatives'), + '#title' => t('Delete Derviatives'), '#type' => 'checkbox', '#default_value' => 0, ); @@ -33,7 +35,6 @@ function islandora_delete_datastream_form(array $form, array &$form_state, Abstr } /** * Purge a given DSID's derivative datastreams on an object. - * */ function islandora_datastream_derivatives_purged(AbstractObject $object, $dsid) { module_load_include('inc', 'islandora', 'includes/utilities'); @@ -44,7 +45,8 @@ function islandora_datastream_derivatives_purged(AbstractObject $object, $dsid) $dsids = array_map($dsid_map, $hooks); array_map(array($object, 'purgeDatastream'), $dsids); } -/** Submit handler for the delete datastream form. +/** + * Submit handler for the delete datastream form. * * Purges/Delete's the given AbstractDatastream if possible. * @@ -62,10 +64,9 @@ function islandora_delete_datastream_form_submit(array $form, array &$form_state $datastream_id = $datastream->id; $object = $datastream->parent; $deleted = FALSE; - - if($form_state['values']['delete_derivatives']){ + if ($form_state['values']['delete_derivatives']) { islandora_datastream_derivatives_purged($object, $datastream_id); - } + } try { $deleted = islandora_delete_datastream($datastream); } From ec5e997ad943e22605f45c226c811bf12d7b095e Mon Sep 17 00:00:00 2001 From: Kylea Jackson Date: Fri, 6 Mar 2015 15:04:06 -0400 Subject: [PATCH 4/9] Added filter for derivatives, added description of what derivatives will be purged --- includes/delete_datastream.form.inc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/includes/delete_datastream.form.inc b/includes/delete_datastream.form.inc index d4a46b8b..b7715657 100644 --- a/includes/delete_datastream.form.inc +++ b/includes/delete_datastream.form.inc @@ -20,10 +20,14 @@ */ function islandora_delete_datastream_form(array $form, array &$form_state, AbstractDatastream $datastream) { $form_state['datastream'] = $datastream; + $object = $datastream->parent; + $dsid = $datastream->id; + $derivs = implode(', ', islandora_datastream_to_purge($object, $dsid)); $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)), ); return confirm_form($form, t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)), @@ -33,18 +37,34 @@ function islandora_delete_datastream_form(array $form, array &$form_state, Abstr t('Cancel') ); } + /** - * Purge a given DSID's derivative datastreams on an object. + * Return $dsids based on a given DSID and filter. */ -function islandora_datastream_derivatives_purged(AbstractObject $object, $dsid) { +function islandora_datastream_to_purge(AbstractObject $object, $dsid) { module_load_include('inc', 'islandora', 'includes/utilities'); $hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array($object)); + $hook_filter = function ($hook_def) use ($dsid) { + return isset($hook_def['source_dsid']) && isset($hook_def['destination_dsid']) ? + $hook_def['source_dsid'] == $dsid : + FALSE; + }; + $hooks = array_filter($hooks, $hook_filter); $dsid_map = function ($hook_definition) { return $hook_definition['destination_dsid']; }; $dsids = array_map($dsid_map, $hooks); + return $dsids; +} + +/** + * Purge a given DSID's derivative datastreams on an object. + */ +function islandora_datastream_derivatives_purged(AbstractObject $object, $dsid) { + $dsids = islandora_datastream_to_purge($object, $dsid); array_map(array($object, 'purgeDatastream'), $dsids); } + /** * Submit handler for the delete datastream form. * From 9e734d6726e8c757c762d30f50002bd2ef0e8034 Mon Sep 17 00:00:00 2001 From: Kylea Jackson Date: Mon, 9 Mar 2015 12:57:58 -0300 Subject: [PATCH 5/9] Added recursive derivative check --- includes/delete_datastream.form.inc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/delete_datastream.form.inc b/includes/delete_datastream.form.inc index b7715657..ce1959df 100644 --- a/includes/delete_datastream.form.inc +++ b/includes/delete_datastream.form.inc @@ -53,7 +53,14 @@ function islandora_datastream_to_purge(AbstractObject $object, $dsid) { $dsid_map = function ($hook_definition) { return $hook_definition['destination_dsid']; }; - $dsids = array_map($dsid_map, $hooks); + $dsids = array(); + $derived_dsids = array_map($dsid_map, $hooks); + while ($current = array_pop($derived_dsids)) { + $dsids[] = $current; + $current_derived = islandora_datastream_to_purge($object, $current); + $current_diff = array_diff($current_derived, $derived_dsids, $dsids); + $derived_dsids = array_merge($derived_dsids, $current_diff); + } return $dsids; } From ccd7ab7f0251c14ffc4d4e4295777f41556e7f14 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 9 Mar 2015 17:23:58 -0300 Subject: [PATCH 6/9] 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 7/9] 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 8/9] 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 9/9] 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']) {