From 95333c25342c62f631fde52e53b824d810a1b5d7 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 09:10:33 -0300 Subject: [PATCH 01/36] added management of deleted files --- css/islandora.theme.css | 18 +- includes/manage_deleted_objects.inc | 297 ++++++++++++++++++++++++++++ includes/object_properties.form.inc | 82 +++++++- includes/utilities.inc | 8 +- islandora.api.php | 12 ++ islandora.module | 62 +++--- 6 files changed, 421 insertions(+), 58 deletions(-) create mode 100644 includes/manage_deleted_objects.inc diff --git a/css/islandora.theme.css b/css/islandora.theme.css index 29f14e66..4ac4fddc 100644 --- a/css/islandora.theme.css +++ b/css/islandora.theme.css @@ -1,4 +1,4 @@ -/* +/* Document : islandora_basic_collection.theme Created on : May 23, 2012, 11:23:56 AM Description: @@ -11,16 +11,16 @@ dl.islandora-object-tn { float: left; - width: 20.8333%; - padding: 0 10px 0 0; margin: 1.5em 0; + padding: 0 10px 0 0; + width: 20.8333%; } dl.islandora-object-fields { + border-top: 0px solid #ddd; float: right; - width:79.1666%; - border-top:0px solid #ddd; margin: 1.5em 0; + width: 79.1666%; } .islandora-object-fields dt { @@ -28,16 +28,16 @@ dl.islandora-object-fields { } .islandora-object-fields dt.first { - border-top:0; + border-top: 0; } .islandora-object-fields dt, .islandora-object-fields dd { - padding:6px 2% 4px; - border-top:1px solid #ddd; + border-top: 1px solid #ddd; + padding: 6px 2% 4px; } .islandora-object-fields dt.first, .islandora-object-fields dd.first { border-top: 0; -} \ No newline at end of file +} diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc new file mode 100644 index 00000000..b04b38c5 --- /dev/null +++ b/includes/manage_deleted_objects.inc @@ -0,0 +1,297 @@ +models); + foreach ($hooks as $hook) { + $temp = module_invoke_all($hook, $fedora_object); + if (!empty($temp)) { + $pids_to_restore = array_merge_recursive($pids_to_restore, $temp); + } + } + } + } + $batch = array( + 'title' => t('@descriptor selected objects', array('@descriptor' => $descriptor)), + 'file' => drupal_get_path('module', 'islandora') . '/includes/manage_deleted_objects.inc', + 'operations' => array(), + ); + + foreach ($pids_to_restore as $pid) { + $batch['operations'][] = array( + $action, + array($pid), + ); + } + batch_set($batch); +} + +/** + * The first form in the deletion managemnt process. + * + * @param array $form + * The Drupal form definition. + * @param array $form_state + * The Drupal form state. + * + * @return array + * The Drupal form definition. + */ +function islandora_delete_form_select_objects(array $form, array &$form_state) { + $form['previous'] = array( + '#type' => 'submit', + '#value' => t('Previous'), + '#attributes' => array('source' => 'previous'), + ); + $content_models = $form_state['values']['content_models']; + $chosen_contentmodels = array_filter($content_models); + $options = islandora_get_deleted_objects($chosen_contentmodels); + if (empty($options)) { + $form['message'] = array( + '#type' => 'markup', + '#markup' => t("There are no deleted objects with the selected content models in this repository."), + ); + return $form; + } + $form['propogate'] = array( + '#title' => t('Apply changes to related objects?'), + '#default_value' => TRUE, + '#description' => t("Objects associated with selected objects will also be restored. ie page objects associated with a book object."), + '#type' => 'checkbox', + ); + $form['chosen'] = array( + '#type' => 'hidden', + '#value' => $chosen_contentmodels, + ); + $form['objects_to_process'] = array( + '#type' => 'tableselect', + '#header' => array( + 'title' => t('Name'), + 'pid' => t('PID'), + 'content_model' => t('Content Model'), + ), + '#multiple' => TRUE, + '#options' => $options, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Restore selected objects'), + '#attributes' => array('source' => 'restore'), + ); + + if (user_access(FEDORA_PURGE)) { + $form['purge'] = array( + '#type' => 'submit', + '#value' => t('Irrevocably purge selected objects'), + '#attributes' => array('source' => 'purge'), + ); + } + + return $form; +} + +/** + * The first form in the deletion management process. + * + * @param array $form + * The Drupal form definition. + * @param array $form_state + * The Drupal form state. + * + * @return array + * The Drupal form definition. + */ +function islandora_delete_form_contentmodels(array $form, array &$form_state) { + module_load_include('inc', 'islandora', 'includes/utilities'); + $contentmodels_with_deleted_members = islandora_get_contentmodels_with_deleted_members(); + if (empty($contentmodels_with_deleted_members)) { + $form['message'] = array( + '#type' => 'markup', + '#markup' => t("There are no deleted objects in this repository."), + ); + return $form; + } + $form['message'] = array( + '#type' => 'markup', + '#markup' => t("Select content models of deleted objects."), + ); + $table_element = islandora_content_model_select_table_form_element(NULL); + + foreach ($table_element['#options'] as $option) { + if (!in_array($option['pid'], $contentmodels_with_deleted_members)) { + unset($table_element['#options'][$option['pid']]); + } + } + if (isset($form_state['values']['chosen'])) { + $chosen_contentmodels = $form_state['values']['chosen']; + foreach ($table_element['#options'] as $option) { + if (in_array($option['pid'], $chosen_contentmodels)) { + $table_element['#default_value'][$option['pid']] = TRUE; + } + } + } + $form['content_models'] = $table_element; + $form['next'] = array( + '#type' => 'submit', + '#value' => t('Next'), + ); + + return $form; +} + +/** + * Gets PIDS of all deleted objects. + * + * @return array + * array of pids + */ +function islandora_get_deleted_objects($content_models) { + $qualifier = ''; + $last_content_model = key(array_slice($content_models, -1, 1, TRUE)); + foreach ($content_models as $content_model) { + $qualifier .= "\$subject "; + if ($content_model != $last_content_model) { + $qualifier .= ' or '; + } + } + $tuque = new IslandoraTuque(); + $repository = $tuque->repository; + $query = << +where ($qualifier) +and \$subject +and \$subject \$object +and \$subject \$title +STRING; + $objects = $repository->ri->itqlQuery($query, 'unlimited'); + $deleted_objects = array(); + foreach ($objects as $object) { + if ($object['object']['value'] != "fedora-system:FedoraObject-3.0") { + $pid = $object['subject']['value']; + $title = $object['title']['value']; + $content_model = islandora_object_load($object['object']['value']); + $deleted_objects[$pid] = array( + 'title' => $title, 'pid' => $pid, + 'content_model' => $content_model->label, + ); + } + } + return $deleted_objects; +} + +/** + * Gets PIDS of all content models associated with deleted objects. + * + * @return array + * array of content model pids + */ +function islandora_get_contentmodels_with_deleted_members() { + + $tuque = new IslandoraTuque(); + $repository = $tuque->repository; + $query = << +where \$subject +and \$subject \$object + +STRING; + $objects = $repository->ri->itqlQuery($query, 'unlimited'); + $content_models = array(); + foreach ($objects as $object) { + if ($object['object']['value'] != "fedora-system:FedoraObject-3.0") { + $content_models[] = $object['object']['value']; + } + } + return $content_models; +} + +/** + * Restores deleted object. + * + * @param String $pid + * PID of object to be restored + */ +function islandora_restore_object($pid) { + $fedora_object = islandora_object_load($pid); + $fedora_object->state = 'A'; +} + +/** + * Purges deleted object. + * + * @param String $pid + * PID of object to be restored + */ +function islandora_purge_object($pid) { + $fedora_object = islandora_object_load($pid); + $fedora_object->repository->purgeObject($pid); +} diff --git a/includes/object_properties.form.inc b/includes/object_properties.form.inc index 44d016b7..b42ccda8 100644 --- a/includes/object_properties.form.inc +++ b/includes/object_properties.form.inc @@ -21,6 +21,14 @@ function islandora_object_properties_form(array $form, array &$form_state, AbstractObject $object) { drupal_set_title($object->label); $form_state['object'] = $object; + $hooks = islandora_build_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $object->models); + $related_objects_pids = array(); + foreach ($hooks as $hook) { + $temp = module_invoke_all($hook, $object); + if (!empty($temp)) { + $related_objects_pids = array_merge_recursive($related_objects_pids, $temp); + } + } return array( 'pid' => array( '#type' => 'hidden', @@ -54,6 +62,18 @@ function islandora_object_properties_form(array $form, array &$form_state, Abstr '#type' => 'select', '#options' => array('A' => 'Active', 'I' => 'Inactive', 'D' => 'Deleted'), ), + 'propogate' => array( + '#title' => t('Apply changes to related objects?'), + '#default_value' => TRUE, + '#description' => t("Changes to owner and state will applied to associated objects. ie page objects associated with a book object."), + '#type' => 'checkbox', + '#access' => count($related_objects_pids), + ), + 'related_pids' => array( + '#value' => $related_objects_pids, + '#type' => 'hidden', + '#access' => count($related_objects_pids), + ), 'submit' => array( '#type' => 'submit', '#value' => 'Update Properties', @@ -81,32 +101,54 @@ function islandora_object_properties_form_submit(array $form, array &$form_state $owner = $form_state['values']['object_owner']; $state = $form_state['values']['object_state']; $label = $form_state['values']['object_label']; + $propogate = $form_state['values']['propogate']; + $update_owners = FALSE; + $update_states = FALSE; if (isset($owner) && $owner != $object->owner) { try { $object->owner = $owner; + $update_owners = TRUE; drupal_set_message(t('Successfully updated owner %s', array('%s' => $owner))); } catch (Exception $e) { form_set_error('object_owner', t('Error updating owner %s', array('%s' => $e->getMessage()))); } } + + if (isset($label) && $label != $object->label) { + try { + $object->label = $label; + drupal_set_message(t('Successfully updated label %s', array('%s' => check_plain($label)))); + } + catch (Exception $e) { + form_set_error(t('Error updating label %s', array('%s' => $e->getMessage()))); + } + } if (isset($state) && $state != $object->state) { try { $object->state = $state; + $update_states = TRUE; drupal_set_message(t('Successfully updated state %s', array('%s' => $state))); } catch (Exception $e) { form_set_error('object_state', t('Error updating state %s', array('%s' => $e->getMessage()))); } } - if (isset($label) && $label != $object->label) { - try { - $object->label = $label; - drupal_set_message(t('Successfully updated label %s', array('%s' => check_plain($label)))); - } - catch (Exception $e) { - form_set_error(t('Error updating label %s', array('%s' => $e->getMessage()))); + if ($propogate && ($update_states || $update_owners)) { + $related_objects_pids = $form_state['values']['related_pids']; + $batch = array( + 'title' => t('Updating related objects'), + 'file' => drupal_get_path('module', 'islandora') . '/includes/object_properties.form.inc', + 'operations' => array(), + ); + + foreach ($related_objects_pids as $pid) { + $batch['operations'][] = array( + 'islandora_update_object_properties', + array($pid, $update_states, $state, $update_owners, $owner), + ); } + batch_set($batch); } } @@ -121,3 +163,29 @@ function islandora_object_properties_form_submit(array $form, array &$form_state function islandora_object_properties_form_delete(array $form, array &$form_state) { drupal_goto("islandora/object/{$form_state['values']['pid']}/delete"); } + +/** + * Updates object state. + * + * @param String $pid + * PID of object to be updated + * @param Boolean $update_states + * If TRUE, update object state + * @param String $state + * Desired object state + * @param Boolean $update_owners + * If TRUE, update Owner + * @param String $owner + * New Owner + */ +function islandora_update_object_properties($pid, $update_states, $state, $update_owners, $owner) { + $fedora_object = islandora_object_load($pid); + if ($fedora_object) { + if ($update_states) { + $fedora_object->state = $state; + } + if ($update_owners) { + $fedora_object->owner = $owner; + } + } +} diff --git a/includes/utilities.inc b/includes/utilities.inc index c8d1ae5e..3aed5e01 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -889,9 +889,7 @@ function islandora_as_renderable_array(&$markup_array) { if (!is_array($value)) { // Not a renderable array, just a string. Let's convert it to a // renderable '#markup' element. - $value = array( - '#markup' => $value, - ); + $value = array('#markup' => $value); } elseif (!isset($value['#type']) && !isset($value['#markup'])) { // A simple array--possibly the result of a recursive merge? Let's @@ -902,9 +900,7 @@ function islandora_as_renderable_array(&$markup_array) { // If it is an array at this level, we can assume that it is a // renderable array. If it is not an array, convert to a renderable // '#markup' element. - $inner = array( - '#markup' => $inner, - ); + $inner = array('#markup' => $inner); } } unset($inner); diff --git a/islandora.api.php b/islandora.api.php index 4d54a00f..478f41d4 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -541,3 +541,15 @@ function hook_islandora_datastream_access($op, $object, $user) { */ function hook_CMODEL_PID_islandora_datastream_access($op, $object, $user) { } + +/** + * Content model specific function to update related objects. + * + * @param FedoraObject $object + * FedoraObject representing original object. + * + * @return array + * Array of pids representing objects associated with original object. + */ +function islandora_book_islandora_bookCModel_islandora_update_related_objects($object) { +} diff --git a/islandora.module b/islandora.module index 7d2c0acb..a6a5956d 100644 --- a/islandora.module +++ b/islandora.module @@ -34,6 +34,7 @@ define('FEDORA_INGEST', 'ingest fedora objects'); define('FEDORA_PURGE', 'delete fedora objects and datastreams'); define('FEDORA_MANAGE_PROPERTIES', 'manage object properties'); define('ISLANDORA_VIEW_DATASTREAM_HISTORY', 'view old datastream versions'); +define('ISLANDORA_MANAGE_DELETED_OBJECTS', 'manage deleted objects'); // Hooks. define('ISLANDORA_VIEW_HOOK', 'islandora_view_object'); @@ -44,6 +45,7 @@ define('ISLANDORA_PRE_INGEST_HOOK', 'islandora_ingest_pre_ingest'); define('ISLANDORA_POST_INGEST_HOOK', 'islandora_ingest_post_ingest'); define('ISLANDORA_PRE_PURGE_OBJECT_HOOK', 'islandora_pre_purge_object'); define('ISLANDORA_POST_PURGE_OBJECT_HOOK', 'islandora_post_purge_object'); +define('ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK', 'islandora_update_related_objects_properties'); // @todo Add Documentation. define('ISLANDORA_OBJECT_INGESTED_HOOK', 'islandora_object_ingested'); @@ -289,6 +291,15 @@ function islandora_menu() { 'access arguments' => array('administer site configuration'), 'type' => MENU_CALLBACK, ); + $items['restore/islandora'] = array( + 'title' => 'Manage Deleted Objects', + 'file' => 'includes/manage_deleted_objects.inc', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('islandora_deleted_objects_form'), + 'type' => MENU_NORMAL_ITEM, + 'access arguments' => array(ISLANDORA_MANAGE_DELETED_OBJECTS), + ); + return $items; } @@ -427,9 +438,7 @@ function islandora_permission() { function islandora_forms($form_id) { $forms = array(); if (strpos($form_id, 'islandora_solution_pack_form_') !== FALSE) { - $forms[$form_id] = array( - 'callback' => 'islandora_solution_pack_form', - ); + $forms[$form_id] = array('callback' => 'islandora_solution_pack_form'); } return $forms; } @@ -698,11 +707,7 @@ function islandora_manage_overview_object(AbstractObject $object) { */ function islandora_default_islandora_manage_overview_object(AbstractObject $object) { $output = theme('islandora_default_overview', array('islandora_object' => $object)); - return array( - 'Default overview output' => array( - '#markup' => $output, - ), - ); + return array('Default overview output' => array('#markup' => $output)); } /** @@ -755,11 +760,7 @@ function islandora_edit_object(AbstractObject $object) { */ function islandora_default_islandora_edit_object(AbstractObject $object) { $output = theme('islandora_default_edit', array('islandora_object' => $object)); - return array( - 'Default Edit output' => array( - '#markup' => $output, - ), - ); + return array('Default Edit output' => array('#markup' => $output)); } /** @@ -797,13 +798,12 @@ function islandora_view_object(AbstractObject $object) { drupal_add_js(array( 'islandora' => array( 'print_img' => $path . '/images/print-icon.png'), - ), array( - 'type' => 'setting')); + ), array( + 'type' => 'setting')); drupal_add_js(array( 'islandora' => array( - 'print_link' => '/islandora/object/' . $object->id . '/print')), - array('type' => 'setting')); + 'print_link' => '/islandora/object/' . $object->id . '/print')), array('type' => 'setting')); drupal_add_js($path . '/js/add_print.js'); drupal_set_title($object->label); @@ -887,6 +887,7 @@ function islandora_drupal_title(AbstractObject $object) { return $object->label; } + /** * Renders the default view object page for the given object. * @@ -898,11 +899,7 @@ function islandora_drupal_title(AbstractObject $object) { */ function islandora_default_islandora_view_object($object) { $output = theme('islandora_default', array('islandora_object' => $object)); - return array( - 'Default output' => array( - '#markup' => $output, - ), - ); + return array('Default output' => array('#markup' => $output)); } /** @@ -940,11 +937,7 @@ function islandora_default_islandora_printer_object($object, $alter) { 'dc_array' => $variables, 'islandora_content' => $alter)); - return array( - 'Default output' => array( - '#markup' => $output, - ), - ); + return array('Default output' => array('#markup' => $output)); } /** @@ -1163,9 +1156,7 @@ function islandora_islandora_required_objects(IslandoraTuque $connection) { return array( 'islandora' => array( 'title' => 'Islandora', - 'objects' => array( - $root_collection, - ), + 'objects' => array($root_collection), ), ); } @@ -1341,6 +1332,7 @@ function islandora_entity_property_info() { return $info; } + /** * Menu callback downloads the given clip. */ @@ -1471,9 +1463,9 @@ function islandora_datastream_access($op, $datastream, $user = NULL) { // The datastream check returned FALSE, and one in the object or datastream // checks returned TRUE. $cache[$op][$datastream->parent->id][$datastream->id][$user->uid] = ( - !in_array(FALSE, $datastream_results, TRUE) && - (in_array(TRUE, $object_results, TRUE) || in_array(TRUE, $datastream_results, TRUE)) - ); + !in_array(FALSE, $datastream_results, TRUE) && + (in_array(TRUE, $object_results, TRUE) || in_array(TRUE, $datastream_results, TRUE)) + ); } return $cache[$op][$datastream->parent->id][$datastream->id][$user->uid]; @@ -1487,8 +1479,6 @@ function islandora_islandora_basic_collection_get_query_filters() { if ($enforced) { $namespace_array = islandora_get_allowed_namespaces(); $namespace_sparql = implode('|', $namespace_array); - return format_string('regex(str(?object), "info:fedora/(!namespaces):")', array( - '!namespaces' => $namespace_sparql, - )); + return format_string('regex(str(?object), "info:fedora/(!namespaces):")', array('!namespaces' => $namespace_sparql)); } } From 09baba751a6f9ea6926fd4a4f7279d32f4a890a3 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 11:06:55 -0300 Subject: [PATCH 02/36] fixed hook name --- islandora.api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora.api.php b/islandora.api.php index 93f13445..8937b88f 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -652,6 +652,6 @@ function hook_CMODEL_PID_islandora_derivative() { * * @param string $pid */ -function islandora_update_related_objects_properties($pid){ +function hook_islandora_update_related_objects_properties($pid){ } \ No newline at end of file From 54adf10af29bf0c4b3115f259537125ca245a8e8 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 12:15:48 -0300 Subject: [PATCH 03/36] updated constant name --- includes/manage_deleted_objects.inc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index b04b38c5..7de8b890 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -148,14 +148,14 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) { '#attributes' => array('source' => 'restore'), ); - if (user_access(FEDORA_PURGE)) { + if (user_access(ISLANDORA_PURGE)) { $form['purge'] = array( '#type' => 'submit', '#value' => t('Irrevocably purge selected objects'), '#attributes' => array('source' => 'purge'), ); } - + return $form; } @@ -225,13 +225,13 @@ function islandora_get_deleted_objects($content_models) { } $tuque = new IslandoraTuque(); $repository = $tuque->repository; - $query = <<ri->itqlQuery($query, 'unlimited'); $deleted_objects = array(); foreach ($objects as $object) { From 16abeaf6ee9a2c203691100846bfa18504ec4b23 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 12:32:42 -0300 Subject: [PATCH 04/36] reverted constant --- includes/manage_deleted_objects.inc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index 7de8b890..07ec7aab 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -147,15 +147,15 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) { '#value' => t('Restore selected objects'), '#attributes' => array('source' => 'restore'), ); - - if (user_access(ISLANDORA_PURGE)) { + if (user_access(FEDORA_PURGE)) { $form['purge'] = array( '#type' => 'submit', '#value' => t('Irrevocably purge selected objects'), '#attributes' => array('source' => 'purge'), ); } - + + return $form; } @@ -225,13 +225,13 @@ function islandora_get_deleted_objects($content_models) { } $tuque = new IslandoraTuque(); $repository = $tuque->repository; - $query = " + $query = << where ($qualifier) and \$subject and \$subject \$object -and \$subject \$title"; - +and \$subject \$title +STRING; $objects = $repository->ri->itqlQuery($query, 'unlimited'); $deleted_objects = array(); foreach ($objects as $object) { From 5b0aa05672d23ca58caa7fa483d225d1c525352d Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 13:14:35 -0300 Subject: [PATCH 05/36] codesniffer changes --- islandora.api.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/islandora.api.php b/islandora.api.php index 8937b88f..49292190 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -649,9 +649,10 @@ function hook_CMODEL_PID_islandora_derivative() { /** * Retrieves PIDS of related objects for property updating. - * + * * @param string $pid + * PID of object */ -function hook_islandora_update_related_objects_properties($pid){ - -} \ No newline at end of file +function hook_islandora_update_related_objects_properties($pid) { + +} From ce5644c88392f182cda38527b0199a7234b89e17 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 13:28:33 -0300 Subject: [PATCH 06/36] coder changes --- includes/manage_deleted_objects.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index 07ec7aab..ab3e74f4 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -155,7 +155,6 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) { ); } - return $form; } From 6ae3ce2ee5c1784da78cfb4a81c8e19551f56bbe Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 13:56:48 -0300 Subject: [PATCH 07/36] removed unavailable code --- includes/manage_deleted_objects.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index ab3e74f4..c3e86d65 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -20,7 +20,7 @@ function islandora_deleted_objects_form($form, &$form_state) { if (!isset($form_state['stage'])) { $form_state['stage'] = 'get_content_models'; } - $form = array(); + switch ($form_state['stage']) { case 'get_content_models': return islandora_delete_form_contentmodels($form, $form_state); @@ -32,7 +32,6 @@ function islandora_deleted_objects_form($form, &$form_state) { break; } - return $form; } /** From 73e1f877726d16594cbc1ee6e989ff6a514eea5e Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 14:12:25 -0300 Subject: [PATCH 08/36] removed return statements --- includes/manage_deleted_objects.inc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index c3e86d65..fcd000a7 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -20,18 +20,19 @@ function islandora_deleted_objects_form($form, &$form_state) { if (!isset($form_state['stage'])) { $form_state['stage'] = 'get_content_models'; } - + $form = array(); switch ($form_state['stage']) { case 'get_content_models': - return islandora_delete_form_contentmodels($form, $form_state); + $form = islandora_delete_form_contentmodels($form, $form_state); break; case 'get_objects': - return islandora_delete_form_select_objects($form, $form_state); + $form = islandora_delete_form_select_objects($form, $form_state); break; } + return $form; } /** From 96f3f4b6ae96e521b7c831e6d37826c90206c641 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 14:16:11 -0300 Subject: [PATCH 09/36] removed return statements --- includes/manage_deleted_objects.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index fcd000a7..27546f78 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -23,14 +23,14 @@ function islandora_deleted_objects_form($form, &$form_state) { $form = array(); switch ($form_state['stage']) { case 'get_content_models': - $form = islandora_delete_form_contentmodels($form, $form_state); + $form = islandora_delete_form_contentmodels($form, $form_state); - break; + break; case 'get_objects': $form = islandora_delete_form_select_objects($form, $form_state); - break; + break; } return $form; } From 1228a6da6b35e06951fd9276696f0bb7b19c4f52 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 15:49:23 -0300 Subject: [PATCH 10/36] added constants, redefined menu path --- includes/manage_deleted_objects.inc | 27 ++++++++++++--------------- islandora.module | 3 ++- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index 27546f78..b2b5077c 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -214,23 +214,22 @@ function islandora_delete_form_contentmodels(array $form, array &$form_state) { * array of pids */ function islandora_get_deleted_objects($content_models) { + $tuque = islandora_get_tuque_connection(); + $repository = $tuque->repository; $qualifier = ''; $last_content_model = key(array_slice($content_models, -1, 1, TRUE)); foreach ($content_models as $content_model) { - $qualifier .= "\$subject "; + $qualifier .= "\$subject <" . FEDORA_MODEL_URI . "hasModel> "; if ($content_model != $last_content_model) { $qualifier .= ' or '; } } - $tuque = new IslandoraTuque(); - $repository = $tuque->repository; - $query = << -where ($qualifier) -and \$subject -and \$subject \$object -and \$subject \$title -STRING; + + $query = "select \$subject \$title \$object from <#ri>"; + $query .= "where ($qualifier)"; + $query .= "and \$subject <" . FEDORA_MODEL_URI . "state> <" . FEDORA_MODEL_URI . "Deleted>"; + $query .= "and \$subject<" . FEDORA_MODEL_URI . "hasModel> \$object "; + $query .= "and \$subject \$title"; $objects = $repository->ri->itqlQuery($query, 'unlimited'); $deleted_objects = array(); foreach ($objects as $object) { @@ -257,12 +256,10 @@ function islandora_get_contentmodels_with_deleted_members() { $tuque = new IslandoraTuque(); $repository = $tuque->repository; - $query = << -where \$subject -and \$subject \$object + $query = "select \$object from <#ri>"; + $query .= "where \$subject <" . FEDORA_MODEL_URI . "state> <" . FEDORA_MODEL_URI . "Deleted>"; + $query .= "and \$subject<" . FEDORA_MODEL_URI . "hasModel> \$object"; -STRING; $objects = $repository->ri->itqlQuery($query, 'unlimited'); $content_models = array(); foreach ($objects as $object) { diff --git a/islandora.module b/islandora.module index b49db9e9..ffdd32a6 100644 --- a/islandora.module +++ b/islandora.module @@ -305,7 +305,8 @@ function islandora_menu() { 'access arguments' => array('administer site configuration'), 'type' => MENU_CALLBACK, ); - $items['restore/islandora'] = array( + $items['admin/islandora/restore'] = array( + 'description' => 'Restore or permanantly remove objects with Deleted status', 'title' => 'Manage Deleted Objects', 'file' => 'includes/manage_deleted_objects.inc', 'page callback' => 'drupal_get_form', From 45199e802bc686f29c60617e902d5cf6713c34f5 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 17:58:41 -0300 Subject: [PATCH 11/36] converted to sparql - itql was getting messy --- includes/manage_deleted_objects.inc | 45 +++++++++++++++++------------ 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index b2b5077c..75ed2e70 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -216,26 +216,29 @@ function islandora_delete_form_contentmodels(array $form, array &$form_state) { function islandora_get_deleted_objects($content_models) { $tuque = islandora_get_tuque_connection(); $repository = $tuque->repository; - $qualifier = ''; - $last_content_model = key(array_slice($content_models, -1, 1, TRUE)); - foreach ($content_models as $content_model) { - $qualifier .= "\$subject <" . FEDORA_MODEL_URI . "hasModel> "; - if ($content_model != $last_content_model) { - $qualifier .= ' or '; - } + $first_contentmodel = array_shift($content_models); + $prefix = "PREFIX fm: <" . FEDORA_MODEL_URI . "> "; + $select = "SELECT ?subject ?label ?object FROM <#ri> WHERE { "; + $where_clause = "{?subject fm:hasModel ; + fm:state fm:Deleted; + fm:hasModel ?object; + }"; + $suffix = '}'; + $unions = ''; + foreach ($content_models as $contentmodel) { + $unions .= "UNION {?subject fm:hasModel ; + fm:state fm:Deleted; + fm:hasModel ?object; + } "; } - - $query = "select \$subject \$title \$object from <#ri>"; - $query .= "where ($qualifier)"; - $query .= "and \$subject <" . FEDORA_MODEL_URI . "state> <" . FEDORA_MODEL_URI . "Deleted>"; - $query .= "and \$subject<" . FEDORA_MODEL_URI . "hasModel> \$object "; - $query .= "and \$subject \$title"; - $objects = $repository->ri->itqlQuery($query, 'unlimited'); + $optional = "OPTIONAL{?subject fm:label ?label}"; + $query = "$prefix $select $where_clause $unions $optional $suffix"; + $objects = $repository->ri->sparqlQuery($query, -1); $deleted_objects = array(); foreach ($objects as $object) { if ($object['object']['value'] != "fedora-system:FedoraObject-3.0") { $pid = $object['subject']['value']; - $title = $object['title']['value']; + $title = $object['label']['value']; $content_model = islandora_object_load($object['object']['value']); $deleted_objects[$pid] = array( 'title' => $title, 'pid' => $pid, @@ -256,11 +259,15 @@ function islandora_get_contentmodels_with_deleted_members() { $tuque = new IslandoraTuque(); $repository = $tuque->repository; - $query = "select \$object from <#ri>"; - $query .= "where \$subject <" . FEDORA_MODEL_URI . "state> <" . FEDORA_MODEL_URI . "Deleted>"; - $query .= "and \$subject<" . FEDORA_MODEL_URI . "hasModel> \$object"; + $query = "PREFIX fm: + SELECT DISTINCT ?object FROM <#ri> + WHERE { + {?subject fm:state fm:Deleted; + fm:hasModel ?object; + } + }"; - $objects = $repository->ri->itqlQuery($query, 'unlimited'); + $objects = $repository->ri->sparqlQuery($query, -1); $content_models = array(); foreach ($objects as $object) { if ($object['object']['value'] != "fedora-system:FedoraObject-3.0") { From 94fe28de4b21743d1dcc14ed65e055329ec20aea Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Wed, 21 Aug 2013 10:34:15 -0300 Subject: [PATCH 12/36] changed function names to avoid future name collision --- includes/manage_deleted_objects.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index 75ed2e70..206ae354 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -60,11 +60,11 @@ function islandora_deleted_objects_form_submit($form, &$form_state) { $objects_to_process = array_filter($form_state['values']['objects_to_process']); if ($form_state['clicked_button']['#attributes']['source'] == 'restore') { $descriptor = "Restoring"; - $action = 'islandora_restore_object'; + $action = 'islandora_restore_object_by_pid'; } if ($form_state['clicked_button']['#attributes']['source'] == 'purge') { $descriptor = "Purging"; - $action = 'islandora_purge_object'; + $action = 'islandora_purge_object_by_pid'; } $pids_to_restore = $objects_to_process; if ($form_state['values']['propogate']) { @@ -283,7 +283,7 @@ function islandora_get_contentmodels_with_deleted_members() { * @param String $pid * PID of object to be restored */ -function islandora_restore_object($pid) { +function islandora_restore_object_by_pid($pid) { $fedora_object = islandora_object_load($pid); $fedora_object->state = 'A'; } @@ -294,7 +294,7 @@ function islandora_restore_object($pid) { * @param String $pid * PID of object to be restored */ -function islandora_purge_object($pid) { +function islandora_purge_object_by_pid($pid) { $fedora_object = islandora_object_load($pid); $fedora_object->repository->purgeObject($pid); } From 3f8f74eb5bb4888cd0fff7e1fa393058e37dc89b Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Wed, 21 Aug 2013 14:25:52 -0300 Subject: [PATCH 13/36] return labels from content models --- includes/manage_deleted_objects.inc | 40 +++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index 206ae354..c0be7872 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -95,7 +95,7 @@ function islandora_deleted_objects_form_submit($form, &$form_state) { } /** - * The first form in the deletion managemnt process. + * The second form in the deletion managemnt process. * * @param array $form * The Drupal form definition. @@ -112,15 +112,19 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) { '#attributes' => array('source' => 'previous'), ); $content_models = $form_state['values']['content_models']; - $chosen_contentmodels = array_filter($content_models); - $options = islandora_get_deleted_objects($chosen_contentmodels); - if (empty($options)) { + $valid = function($element) { + return $element; + }; + $chosen_contentmodels = array_filter($content_models, $valid); + + if (empty($chosen_contentmodels)) { $form['message'] = array( '#type' => 'markup', '#markup' => t("There are no deleted objects with the selected content models in this repository."), ); return $form; } + $options = islandora_get_deleted_objects($form_state['values']['mapped_contentmodels']); $form['propogate'] = array( '#title' => t('Apply changes to related objects?'), '#default_value' => TRUE, @@ -172,6 +176,7 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) { function islandora_delete_form_contentmodels(array $form, array &$form_state) { module_load_include('inc', 'islandora', 'includes/utilities'); $contentmodels_with_deleted_members = islandora_get_contentmodels_with_deleted_members(); + $elegible_contentmodels = array_keys($contentmodels_with_deleted_members); if (empty($contentmodels_with_deleted_members)) { $form['message'] = array( '#type' => 'markup', @@ -183,10 +188,14 @@ function islandora_delete_form_contentmodels(array $form, array &$form_state) { '#type' => 'markup', '#markup' => t("Select content models of deleted objects."), ); + $form['mapped_contentmodels'] = array( + '#type' => 'hidden', + '#value' => $contentmodels_with_deleted_members, + ); $table_element = islandora_content_model_select_table_form_element(NULL); foreach ($table_element['#options'] as $option) { - if (!in_array($option['pid'], $contentmodels_with_deleted_members)) { + if (!in_array($option['pid'], $elegible_contentmodels)) { unset($table_element['#options'][$option['pid']]); } } @@ -216,7 +225,8 @@ function islandora_delete_form_contentmodels(array $form, array &$form_state) { function islandora_get_deleted_objects($content_models) { $tuque = islandora_get_tuque_connection(); $repository = $tuque->repository; - $first_contentmodel = array_shift($content_models); + $candidates = array_keys($content_models); + $first_contentmodel = array_shift($candidates); $prefix = "PREFIX fm: <" . FEDORA_MODEL_URI . "> "; $select = "SELECT ?subject ?label ?object FROM <#ri> WHERE { "; $where_clause = "{?subject fm:hasModel ; @@ -225,11 +235,12 @@ function islandora_get_deleted_objects($content_models) { }"; $suffix = '}'; $unions = ''; - foreach ($content_models as $contentmodel) { + foreach ($candidates as $contentmodel) { $unions .= "UNION {?subject fm:hasModel ; fm:state fm:Deleted; fm:hasModel ?object; - } "; + } + "; } $optional = "OPTIONAL{?subject fm:label ?label}"; $query = "$prefix $select $where_clause $unions $optional $suffix"; @@ -238,11 +249,11 @@ function islandora_get_deleted_objects($content_models) { foreach ($objects as $object) { if ($object['object']['value'] != "fedora-system:FedoraObject-3.0") { $pid = $object['subject']['value']; + $cm_pid = $object['object']['value']; $title = $object['label']['value']; - $content_model = islandora_object_load($object['object']['value']); $deleted_objects[$pid] = array( 'title' => $title, 'pid' => $pid, - 'content_model' => $content_model->label, + 'content_model' => $content_models[$cm_pid], ); } } @@ -260,18 +271,21 @@ function islandora_get_contentmodels_with_deleted_members() { $tuque = new IslandoraTuque(); $repository = $tuque->repository; $query = "PREFIX fm: - SELECT DISTINCT ?object FROM <#ri> + SELECT DISTINCT ?object ?label FROM <#ri> WHERE { {?subject fm:state fm:Deleted; - fm:hasModel ?object; + fm:hasModel ?object; } + OPTIONAL{ + ?object fm:label ?label + } }"; $objects = $repository->ri->sparqlQuery($query, -1); $content_models = array(); foreach ($objects as $object) { if ($object['object']['value'] != "fedora-system:FedoraObject-3.0") { - $content_models[] = $object['object']['value']; + $content_models[$object['object']['value']] = $object['label']['value']; } } return $content_models; From f478feabb42de1589303a8458ddf5069d2b35574 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Sat, 24 Aug 2013 10:32:26 -0300 Subject: [PATCH 14/36] refactored form logic --- includes/manage_deleted_objects.inc | 238 +++++++++++++++------------- islandora.api.php | 13 +- islandora.module | 19 ++- 3 files changed, 147 insertions(+), 123 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index c0be7872..f453a730 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -6,7 +6,7 @@ */ /** - * Manages the two deletion management forms. + * The deletion management prep form. * * @param array $form * The Drupal form definition. @@ -16,86 +16,71 @@ * @return array * The Drupal form definition. */ -function islandora_deleted_objects_form($form, &$form_state) { - if (!isset($form_state['stage'])) { - $form_state['stage'] = 'get_content_models'; +function islandora_deleted_objects_prep_form($form, $form_state, $serialized_chosen = NULL) { + module_load_include('inc', 'islandora', 'includes/utilities'); + $chosen_contentmodels = array(); + if ($serialized_chosen) { + $chosen_contentmodels = unserialize($serialized_chosen); } - $form = array(); - switch ($form_state['stage']) { - case 'get_content_models': - $form = islandora_delete_form_contentmodels($form, $form_state); - - break; + $contentmodels_with_deleted_members = islandora_get_contentmodels_with_deleted_members(); + $elegible_contentmodels = array_keys($contentmodels_with_deleted_members); + if (empty($contentmodels_with_deleted_members)) { + $form['message'] = array( + '#type' => 'markup', + '#markup' => t("There are no deleted objects in this repository."), + ); + return $form; + } + $form['message'] = array( + '#type' => 'markup', + '#markup' => t("Select content models of deleted objects."), + ); + $form['mapped_contentmodels'] = array( + '#type' => 'hidden', + '#value' => $contentmodels_with_deleted_members, + ); + $table_element = islandora_content_model_select_table_form_element(NULL); - case 'get_objects': - $form = islandora_delete_form_select_objects($form, $form_state); + foreach ($table_element['#options'] as $option) { + if (!in_array($option['pid'], $elegible_contentmodels)) { + unset($table_element['#options'][$option['pid']]); + } + } - break; + foreach ($table_element['#options'] as $option) { + if (array_key_exists($option['pid'], $chosen_contentmodels)) { + $table_element['#default_value'][$option['pid']] = TRUE; + } } + + $form['contentmodels'] = $table_element; + $form['next'] = array( + '#type' => 'submit', + '#value' => t('Next'), + ); + return $form; } /** - * Submit handler for deletion management. + * Submit handler for deletion management prep form. * * @param array $form * The form. * @param array $form_state * The form state. */ -function islandora_deleted_objects_form_submit($form, &$form_state) { - if (isset($form_state['clicked_button']['#attributes']['source']) && $form_state['clicked_button']['#attributes']['source'] == 'previous') { - $form_state['rebuild'] = TRUE; - $form_state['stage'] = 'get_content_models'; - return; - } - - module_load_include('inc', 'islandora', 'includes/utilities'); - if ($form_state['stage'] == 'get_content_models') { - $form_state['rebuild'] = TRUE; - $form_state['stage'] = 'get_objects'; - return; - } - - $objects_to_process = array_filter($form_state['values']['objects_to_process']); - if ($form_state['clicked_button']['#attributes']['source'] == 'restore') { - $descriptor = "Restoring"; - $action = 'islandora_restore_object_by_pid'; - } - if ($form_state['clicked_button']['#attributes']['source'] == 'purge') { - $descriptor = "Purging"; - $action = 'islandora_purge_object_by_pid'; - } - $pids_to_restore = $objects_to_process; - if ($form_state['values']['propogate']) { - foreach ($objects_to_process as $pid) { - $fedora_object = islandora_object_load($pid); - $hooks = islandora_build_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $fedora_object->models); - foreach ($hooks as $hook) { - $temp = module_invoke_all($hook, $fedora_object); - if (!empty($temp)) { - $pids_to_restore = array_merge_recursive($pids_to_restore, $temp); - } - } - } - } - $batch = array( - 'title' => t('@descriptor selected objects', array('@descriptor' => $descriptor)), - 'file' => drupal_get_path('module', 'islandora') . '/includes/manage_deleted_objects.inc', - 'operations' => array(), - ); - - foreach ($pids_to_restore as $pid) { - $batch['operations'][] = array( - $action, - array($pid), - ); - } - batch_set($batch); +function islandora_deleted_objects_prep_form_submit($form, $form_state) { + $content_models = $form_state['values']['contentmodels']; + $chosen = function($element) { + return $element; + }; + $serialized_contentmodels = serialize(array_filter($content_models, $chosen)); + drupal_goto("admin/islandora/restore/manage/$serialized_contentmodels"); } /** - * The second form in the deletion managemnt process. + * The deletion management prep form. * * @param array $form * The Drupal form definition. @@ -105,17 +90,21 @@ function islandora_deleted_objects_form_submit($form, &$form_state) { * @return array * The Drupal form definition. */ -function islandora_delete_form_select_objects(array $form, array &$form_state) { +function islandora_deleted_objects_manage_form($form, $form_state, $serialized_chosen = NULL) { + $form['previous'] = array( '#type' => 'submit', '#value' => t('Previous'), '#attributes' => array('source' => 'previous'), ); - $content_models = $form_state['values']['content_models']; - $valid = function($element) { - return $element; - }; - $chosen_contentmodels = array_filter($content_models, $valid); + + $chosen_contentmodels = unserialize($serialized_chosen); + $content_models_with_deleted = islandora_get_contentmodels_with_deleted_members(); + foreach ($chosen_contentmodels as $contentmodel) { + if (!array_key_exists($contentmodel, $content_models_with_deleted)) { + unset($chosen_contentmodels[$contentmodel]); + } + } if (empty($chosen_contentmodels)) { $form['message'] = array( @@ -124,7 +113,32 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) { ); return $form; } - $options = islandora_get_deleted_objects($form_state['values']['mapped_contentmodels']); + if (is_array($chosen_contentmodels)) { + foreach ($chosen_contentmodels as $key => $value) { + if (in_array($key, $content_models_with_deleted)) { + $chosen_contentmodels[$key] = $content_models_with_deleted[$key]; + } + } + } + + $options = islandora_get_deleted_objects($chosen_contentmodels); + $per_page = 25; + if (count($options) < 28) { + $per_page = count($options); + } + $current_page = pager_default_initialize(count($options), $per_page); + $options_this_page = array_slice($options, $current_page * $per_page, $per_page); + foreach ($options_this_page as &$option) { + $option['content_model'] = $content_models_with_deleted[$option['content_model']]; + } + $form['serialized_chosen'] = array( + '#type' => 'hidden', + '#value' => $serialized_chosen, + ); + $form['pager'] = array( + '#type' => 'markup', + '#markup' => theme('pager', array('quantity', count($options))), + ); $form['propogate'] = array( '#title' => t('Apply changes to related objects?'), '#default_value' => TRUE, @@ -143,7 +157,7 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) { 'content_model' => t('Content Model'), ), '#multiple' => TRUE, - '#options' => $options, + '#options' => $options_this_page, ); $form['submit'] = array( @@ -158,62 +172,60 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) { '#attributes' => array('source' => 'purge'), ); } - return $form; } /** - * The first form in the deletion management process. + * Submit handler for deletion management form. * * @param array $form - * The Drupal form definition. + * The form. * @param array $form_state - * The Drupal form state. - * - * @return array - * The Drupal form definition. + * The form state. */ -function islandora_delete_form_contentmodels(array $form, array &$form_state) { +function islandora_deleted_objects_manage_form_submit($form, $form_state) { module_load_include('inc', 'islandora', 'includes/utilities'); - $contentmodels_with_deleted_members = islandora_get_contentmodels_with_deleted_members(); - $elegible_contentmodels = array_keys($contentmodels_with_deleted_members); - if (empty($contentmodels_with_deleted_members)) { - $form['message'] = array( - '#type' => 'markup', - '#markup' => t("There are no deleted objects in this repository."), - ); - return $form; - } - $form['message'] = array( - '#type' => 'markup', - '#markup' => t("Select content models of deleted objects."), - ); - $form['mapped_contentmodels'] = array( - '#type' => 'hidden', - '#value' => $contentmodels_with_deleted_members, - ); - $table_element = islandora_content_model_select_table_form_element(NULL); + $serialized_chosen = isset($form_state['values']['serialized_chosen']) ? $form_state['values']['serialized_chosen'] : NULL; - foreach ($table_element['#options'] as $option) { - if (!in_array($option['pid'], $elegible_contentmodels)) { - unset($table_element['#options'][$option['pid']]); - } + if (isset($form_state['clicked_button']['#attributes']['source']) && $form_state['clicked_button']['#attributes']['source'] == 'previous') { + drupal_goto("admin/islandora/restore/prep/$serialized_chosen"); + } + if ($form_state['clicked_button']['#attributes']['source'] == 'restore') { + $descriptor = "Restoring"; + $action = 'islandora_restore_object_by_pid'; + } + if ($form_state['clicked_button']['#attributes']['source'] == 'purge') { + $descriptor = "Purging"; + $action = 'islandora_purge_object_by_pid'; } - if (isset($form_state['values']['chosen'])) { - $chosen_contentmodels = $form_state['values']['chosen']; - foreach ($table_element['#options'] as $option) { - if (in_array($option['pid'], $chosen_contentmodels)) { - $table_element['#default_value'][$option['pid']] = TRUE; + $objects_to_process = array_filter($form_state['values']['objects_to_process']); + $pids_to_restore = $objects_to_process; + if ($form_state['values']['propogate']) { + foreach ($objects_to_process as $pid) { + $fedora_object = islandora_object_load($pid); + $hooks = islandora_build_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $fedora_object->models); + foreach ($hooks as $hook) { + $temp = module_invoke_all($hook, $fedora_object); + if (!empty($temp)) { + $pids_to_restore = array_merge_recursive($pids_to_restore, $temp); + } } } } - $form['content_models'] = $table_element; - $form['next'] = array( - '#type' => 'submit', - '#value' => t('Next'), + $batch = array( + 'title' => t('@descriptor selected objects', array('@descriptor' => $descriptor)), + 'file' => drupal_get_path('module', 'islandora') . '/includes/manage_deleted_objects.inc', + 'operations' => array(), ); - return $form; + foreach ($pids_to_restore as $pid) { + $batch['operations'][] = array( + $action, + array($pid), + ); + } + batch_set($batch); + batch_process("admin/islandora/restore/manage/$serialized_chosen"); } /** @@ -228,7 +240,7 @@ function islandora_get_deleted_objects($content_models) { $candidates = array_keys($content_models); $first_contentmodel = array_shift($candidates); $prefix = "PREFIX fm: <" . FEDORA_MODEL_URI . "> "; - $select = "SELECT ?subject ?label ?object FROM <#ri> WHERE { "; + $select = "SELECT DISTINCT ?subject ?label ?object FROM <#ri> WHERE { "; $where_clause = "{?subject fm:hasModel ; fm:state fm:Deleted; fm:hasModel ?object; diff --git a/islandora.api.php b/islandora.api.php index 49292190..e0cc86b6 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -650,9 +650,14 @@ function hook_CMODEL_PID_islandora_derivative() { /** * Retrieves PIDS of related objects for property updating. * - * @param string $pid - * PID of object + * @param AbstractObject $object + * AbstractObject representing deleted object */ -function hook_islandora_update_related_objects_properties($pid) { - +function hook_islandora_update_related_objects_properties(AbstractObject $object) { + $related_objects = get_all_children_siblings_and_friends($object); + $pids_to_return = array(); + foreach($related_objects as $related_object) { + $pids_to_return[] = $related_object->id; + } + return $pids_to_return; } diff --git a/islandora.module b/islandora.module index ffdd32a6..eb05211e 100644 --- a/islandora.module +++ b/islandora.module @@ -305,12 +305,22 @@ function islandora_menu() { 'access arguments' => array('administer site configuration'), 'type' => MENU_CALLBACK, ); - $items['admin/islandora/restore'] = array( + $items['admin/islandora/restore/prep'] = array( 'description' => 'Restore or permanantly remove objects with Deleted status', 'title' => 'Manage Deleted Objects', 'file' => 'includes/manage_deleted_objects.inc', 'page callback' => 'drupal_get_form', - 'page arguments' => array('islandora_deleted_objects_form'), + 'page arguments' => array('islandora_deleted_objects_prep_form'), + 'type' => MENU_NORMAL_ITEM, + 'access arguments' => array(ISLANDORA_MANAGE_DELETED_OBJECTS), + ); + + $items['admin/islandora/restore/manage'] = array( + 'description' => 'Restore or permanantly remove objects with Deleted status', + 'title' => 'Manage Deleted Objects', + 'file' => 'includes/manage_deleted_objects.inc', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('islandora_deleted_objects_manage_form'), 'type' => MENU_NORMAL_ITEM, 'access arguments' => array(ISLANDORA_MANAGE_DELETED_OBJECTS), ); @@ -818,9 +828,7 @@ function islandora_view_object(AbstractObject $object) { drupal_add_js(array( 'islandora' => array( - - 'print_link' => 'islandora/object/' . $object->id . '/print')), - array('type' => 'setting')); + 'print_link' => 'islandora/object/' . $object->id . '/print')), array('type' => 'setting')); drupal_add_js($path . '/js/add_print.js'); drupal_set_title($object->label); @@ -1500,7 +1508,6 @@ function islandora_islandora_basic_collection_get_query_filters() { } } - /** * Implements hook_islandora_object_ingested(). * From 5a77c93b38c670647dfe2b57c8144e2bfa4d6796 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 29 Aug 2013 00:38:12 -0300 Subject: [PATCH 15/36] changed menu type --- islandora.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index 9df17892..a81de4ec 100644 --- a/islandora.module +++ b/islandora.module @@ -333,7 +333,7 @@ function islandora_menu() { 'file' => 'includes/manage_deleted_objects.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('islandora_deleted_objects_manage_form'), - 'type' => MENU_NORMAL_ITEM, + 'type' => MENU_SUGGESTED_ITEM, 'access arguments' => array(ISLANDORA_MANAGE_DELETED_OBJECTS), ); From 797bfb923df75fda9349aa6d10af73f686c8883f Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 29 Aug 2013 14:00:27 -0300 Subject: [PATCH 16/36] consolidated looping logic --- includes/manage_deleted_objects.inc | 3 --- 1 file changed, 3 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index f453a730..fa3647e3 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -45,9 +45,6 @@ function islandora_deleted_objects_prep_form($form, $form_state, $serialized_cho if (!in_array($option['pid'], $elegible_contentmodels)) { unset($table_element['#options'][$option['pid']]); } - } - - foreach ($table_element['#options'] as $option) { if (array_key_exists($option['pid'], $chosen_contentmodels)) { $table_element['#default_value'][$option['pid']] = TRUE; } From d9f2d1bbcf60e4f64bfca046eb5637d8972c416c Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 29 Aug 2013 14:57:22 -0300 Subject: [PATCH 17/36] removed some whitespaces --- includes/manage_deleted_objects.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index fa3647e3..095d2b43 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -279,11 +279,11 @@ function islandora_get_contentmodels_with_deleted_members() { $tuque = new IslandoraTuque(); $repository = $tuque->repository; - $query = "PREFIX fm: - SELECT DISTINCT ?object ?label FROM <#ri> - WHERE { + $query = "PREFIX fm: + SELECT DISTINCT ?object ?label FROM <#ri> + WHERE { {?subject fm:state fm:Deleted; - fm:hasModel ?object; + fm:hasModel ?object; } OPTIONAL{ ?object fm:label ?label From 3442501dd388f56c8dd832b2568659af6c931c5a Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 30 Aug 2013 11:03:28 -0300 Subject: [PATCH 18/36] clarified propogation message --- includes/manage_deleted_objects.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index 095d2b43..207867d7 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -139,7 +139,7 @@ function islandora_deleted_objects_manage_form($form, $form_state, $serialized_c $form['propogate'] = array( '#title' => t('Apply changes to related objects?'), '#default_value' => TRUE, - '#description' => t("Objects associated with selected objects will also be restored. ie page objects associated with a book object."), + '#description' => t("Objects associated with selected objects will also be purged/restored. ie page objects associated with a book object."), '#type' => 'checkbox', ); $form['chosen'] = array( From 2b912d36cbd43a033b3651c07e89252f61801672 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 30 Aug 2013 11:10:24 -0300 Subject: [PATCH 19/36] updated to islandora_invoke_hook_list --- includes/manage_deleted_objects.inc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index 207867d7..6911fa85 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -162,7 +162,7 @@ function islandora_deleted_objects_manage_form($form, $form_state, $serialized_c '#value' => t('Restore selected objects'), '#attributes' => array('source' => 'restore'), ); - if (user_access(FEDORA_PURGE)) { + if (user_access(ISLANDORA_PURGE)) { $form['purge'] = array( '#type' => 'submit', '#value' => t('Irrevocably purge selected objects'), @@ -200,12 +200,9 @@ function islandora_deleted_objects_manage_form_submit($form, $form_state) { if ($form_state['values']['propogate']) { foreach ($objects_to_process as $pid) { $fedora_object = islandora_object_load($pid); - $hooks = islandora_build_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $fedora_object->models); - foreach ($hooks as $hook) { - $temp = module_invoke_all($hook, $fedora_object); - if (!empty($temp)) { - $pids_to_restore = array_merge_recursive($pids_to_restore, $temp); - } + $temp = islandora_invoke_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $fedora_object->models, array($fedora_object)); + if (!empty($temp)) { + $pids_to_restore = array_merge_recursive($pids_to_restore, $temp); } } } From d6aa4c34f39d46ad3181a342dc85e082e23ada06 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 30 Aug 2013 11:15:49 -0300 Subject: [PATCH 20/36] updated to islandora_invoke_hook_list --- includes/object_properties.form.inc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/includes/object_properties.form.inc b/includes/object_properties.form.inc index fb68e394..be85aa08 100644 --- a/includes/object_properties.form.inc +++ b/includes/object_properties.form.inc @@ -21,13 +21,10 @@ function islandora_object_properties_form(array $form, array &$form_state, AbstractObject $object) { drupal_set_title($object->label); $form_state['object'] = $object; - $hooks = islandora_build_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $object->models); + $temp = islandora_invoke_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $fedora_object->models, array($fedora_object)); $related_objects_pids = array(); - foreach ($hooks as $hook) { - $temp = module_invoke_all($hook, $object); - if (!empty($temp)) { - $related_objects_pids = array_merge_recursive($related_objects_pids, $temp); - } + if (!empty($temp)) { + $pids_to_restore = array_merge_recursive($related_objects_pids, $temp); } return array( 'pid' => array( From 88ff97f4ffa7e2996e83da56674888b29f190e9b Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Tue, 3 Sep 2013 10:13:47 -0300 Subject: [PATCH 21/36] changed variable name --- includes/object_properties.form.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/object_properties.form.inc b/includes/object_properties.form.inc index be85aa08..9079834f 100644 --- a/includes/object_properties.form.inc +++ b/includes/object_properties.form.inc @@ -21,7 +21,7 @@ function islandora_object_properties_form(array $form, array &$form_state, AbstractObject $object) { drupal_set_title($object->label); $form_state['object'] = $object; - $temp = islandora_invoke_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $fedora_object->models, array($fedora_object)); + $temp = islandora_invoke_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $object->models, array($object)); $related_objects_pids = array(); if (!empty($temp)) { $pids_to_restore = array_merge_recursive($related_objects_pids, $temp); From 1438e806cd92a2b74f718dab83609797edc0fb53 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 5 Sep 2013 10:34:01 -0300 Subject: [PATCH 22/36] resolved merge conflicts --- islandora.module | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/islandora.module b/islandora.module index b02bdc61..4f5ea647 100644 --- a/islandora.module +++ b/islandora.module @@ -875,12 +875,9 @@ function islandora_view_object(AbstractObject $object) { drupal_add_js(array( 'islandora' => array( -<<<<<<< HEAD + 'print_link' => 'islandora/object/' . $object->id . '/print')), array('type' => 'setting')); -======= - 'print_link' => 'islandora/object/' . $object->id . '/print_object')), - array('type' => 'setting')); ->>>>>>> dd50626677e1acbc5fe69daf25d13cfa65dae7af + drupal_add_js($path . '/js/add_print.js'); drupal_set_title($object->label); From aa13a2d7df7c64908ec03d151c76a9c6636f4a06 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 5 Sep 2013 10:36:44 -0300 Subject: [PATCH 23/36] formatting --- islandora.module | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/islandora.module b/islandora.module index 4f5ea647..9fb41528 100644 --- a/islandora.module +++ b/islandora.module @@ -873,11 +873,7 @@ function islandora_view_object(AbstractObject $object) { ), array( 'type' => 'setting')); - drupal_add_js(array( - 'islandora' => array( - - 'print_link' => 'islandora/object/' . $object->id . '/print')), array('type' => 'setting')); - + drupal_add_js(array('islandora' => array('print_link' => 'islandora/object/' . $object->id . '/print')), array('type' => 'setting')); drupal_add_js($path . '/js/add_print.js'); drupal_set_title($object->label); From a1f04d274bdb27704c4cca191194edf527ec29fa Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 5 Sep 2013 20:39:04 -0300 Subject: [PATCH 24/36] added limits and offsets to query --- includes/manage_deleted_objects.inc | 80 ++++++++++++++++++----------- includes/object_properties.form.inc | 2 +- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index 6911fa85..7dc8d181 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -117,15 +117,19 @@ function islandora_deleted_objects_manage_form($form, $form_state, $serialized_c } } } - - $options = islandora_get_deleted_objects($chosen_contentmodels); - $per_page = 25; - if (count($options) < 28) { - $per_page = count($options); + $tuque = islandora_get_tuque_connection(); + $repository = $tuque->repository; + // Query brings back fedora-system:FedoraObject-3.0, doubling the results. + $total = $repository->ri->countQuery(islandora_get_deleted_query($chosen_contentmodels), 'sparql') / 2; + $limit = 25; + if ($total < 28) { + $limit = $total; } - $current_page = pager_default_initialize(count($options), $per_page); - $options_this_page = array_slice($options, $current_page * $per_page, $per_page); - foreach ($options_this_page as &$option) { + $current_page = pager_default_initialize($total, $limit); + $offset = $current_page * $limit * 2; + $query_limit = $limit * 2; + $options = islandora_get_deleted_objects($chosen_contentmodels, $query_limit, $offset); + foreach ($options as &$option) { $option['content_model'] = $content_models_with_deleted[$option['content_model']]; } $form['serialized_chosen'] = array( @@ -154,7 +158,7 @@ function islandora_deleted_objects_manage_form($form, $form_state, $serialized_c 'content_model' => t('Content Model'), ), '#multiple' => TRUE, - '#options' => $options_this_page, + '#options' => $options, ); $form['submit'] = array( @@ -228,29 +232,11 @@ function islandora_deleted_objects_manage_form_submit($form, $form_state) { * @return array * array of pids */ -function islandora_get_deleted_objects($content_models) { +function islandora_get_deleted_objects($content_models, $limit, $offset) { $tuque = islandora_get_tuque_connection(); $repository = $tuque->repository; - $candidates = array_keys($content_models); - $first_contentmodel = array_shift($candidates); - $prefix = "PREFIX fm: <" . FEDORA_MODEL_URI . "> "; - $select = "SELECT DISTINCT ?subject ?label ?object FROM <#ri> WHERE { "; - $where_clause = "{?subject fm:hasModel ; - fm:state fm:Deleted; - fm:hasModel ?object; - }"; - $suffix = '}'; - $unions = ''; - foreach ($candidates as $contentmodel) { - $unions .= "UNION {?subject fm:hasModel ; - fm:state fm:Deleted; - fm:hasModel ?object; - } - "; - } - $optional = "OPTIONAL{?subject fm:label ?label}"; - $query = "$prefix $select $where_clause $unions $optional $suffix"; - $objects = $repository->ri->sparqlQuery($query, -1); + $query = islandora_get_deleted_query($content_models, $offset); + $objects = $repository->ri->sparqlQuery($query, $limit, $offset); $deleted_objects = array(); foreach ($objects as $object) { if ($object['object']['value'] != "fedora-system:FedoraObject-3.0") { @@ -273,7 +259,6 @@ function islandora_get_deleted_objects($content_models) { * array of content model pids */ function islandora_get_contentmodels_with_deleted_members() { - $tuque = new IslandoraTuque(); $repository = $tuque->repository; $query = "PREFIX fm: @@ -318,3 +303,36 @@ function islandora_purge_object_by_pid($pid) { $fedora_object = islandora_object_load($pid); $fedora_object->repository->purgeObject($pid); } + +/** + * Get query to find all deleted objects by content type. + * + * @param array $content_models + * Content models to restrict search + * @param int $offset + * offset to be added to search + * + * @return String + * Sparql query + */ +function islandora_get_deleted_query($content_models, $offset = 0) { + $candidates = array_keys($content_models); + $first_contentmodel = array_shift($candidates); + $prefix = "PREFIX fm: <" . FEDORA_MODEL_URI . "> "; + $select = "SELECT DISTINCT ?subject ?label ?object FROM <#ri> WHERE { "; + $where_clause = "{?subject fm:hasModel ; + fm:state fm:Deleted; + fm:hasModel ?object; + }"; + $suffix = "} ORDER BY ?subject offset $offset"; + $unions = ''; + foreach ($candidates as $contentmodel) { + $unions .= "UNION {?subject fm:hasModel ; + fm:state fm:Deleted; + fm:hasModel ?object; + } + "; + } + $optional = "OPTIONAL{?subject fm:label ?label}"; + return "$prefix $select $where_clause $unions $optional $suffix"; +} diff --git a/includes/object_properties.form.inc b/includes/object_properties.form.inc index 9079834f..a3ceb9e9 100644 --- a/includes/object_properties.form.inc +++ b/includes/object_properties.form.inc @@ -24,7 +24,7 @@ function islandora_object_properties_form(array $form, array &$form_state, Abstr $temp = islandora_invoke_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $object->models, array($object)); $related_objects_pids = array(); if (!empty($temp)) { - $pids_to_restore = array_merge_recursive($related_objects_pids, $temp); + $related_objects_pids = array_merge_recursive($related_objects_pids, $temp); } return array( 'pid' => array( From 8bb88cccfebe789196b99f2f2c1a60c33642609a Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 5 Sep 2013 20:57:33 -0300 Subject: [PATCH 25/36] formatting --- includes/manage_deleted_objects.inc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index 7dc8d181..3c19e420 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -88,7 +88,6 @@ function islandora_deleted_objects_prep_form_submit($form, $form_state) { * The Drupal form definition. */ function islandora_deleted_objects_manage_form($form, $form_state, $serialized_chosen = NULL) { - $form['previous'] = array( '#type' => 'submit', '#value' => t('Previous'), @@ -110,6 +109,7 @@ function islandora_deleted_objects_manage_form($form, $form_state, $serialized_c ); return $form; } + if (is_array($chosen_contentmodels)) { foreach ($chosen_contentmodels as $key => $value) { if (in_array($key, $content_models_with_deleted)) { @@ -117,6 +117,7 @@ function islandora_deleted_objects_manage_form($form, $form_state, $serialized_c } } } + $tuque = islandora_get_tuque_connection(); $repository = $tuque->repository; // Query brings back fedora-system:FedoraObject-3.0, doubling the results. @@ -126,9 +127,10 @@ function islandora_deleted_objects_manage_form($form, $form_state, $serialized_c $limit = $total; } $current_page = pager_default_initialize($total, $limit); - $offset = $current_page * $limit * 2; $query_limit = $limit * 2; + $offset = $current_page * $query_limit; $options = islandora_get_deleted_objects($chosen_contentmodels, $query_limit, $offset); + foreach ($options as &$option) { $option['content_model'] = $content_models_with_deleted[$option['content_model']]; } @@ -230,7 +232,7 @@ function islandora_deleted_objects_manage_form_submit($form, $form_state) { * Gets PIDS of all deleted objects. * * @return array - * array of pids + * PIDS of deleted objects */ function islandora_get_deleted_objects($content_models, $limit, $offset) { $tuque = islandora_get_tuque_connection(); @@ -324,7 +326,7 @@ function islandora_get_deleted_query($content_models, $offset = 0) { fm:state fm:Deleted; fm:hasModel ?object; }"; - $suffix = "} ORDER BY ?subject offset $offset"; + $suffix = "} ORDER BY ?subject OFFSET $offset"; $unions = ''; foreach ($candidates as $contentmodel) { $unions .= "UNION {?subject fm:hasModel ; From c9cfdb1cd590da3d000322d6648233595b40e03a Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 6 Sep 2013 10:49:17 -0300 Subject: [PATCH 26/36] removed reference to unused paramater --- includes/manage_deleted_objects.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index 3c19e420..2708efe3 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -238,7 +238,7 @@ function islandora_get_deleted_objects($content_models, $limit, $offset) { $tuque = islandora_get_tuque_connection(); $repository = $tuque->repository; $query = islandora_get_deleted_query($content_models, $offset); - $objects = $repository->ri->sparqlQuery($query, $limit, $offset); + $objects = $repository->ri->sparqlQuery($query, $limit); $deleted_objects = array(); foreach ($objects as $object) { if ($object['object']['value'] != "fedora-system:FedoraObject-3.0") { From e1fe2cedf12c408b32eb8fe921f963fe6874e617 Mon Sep 17 00:00:00 2001 From: yqjiang Date: Fri, 6 Sep 2013 14:11:19 +0000 Subject: [PATCH 27/36] add mpv mimetype --- includes/mime_detect.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index 13b66cc8..6a007ad7 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -162,6 +162,7 @@ class MimeDetect { "xpm" => "image/x-xpixmap", "xwd" => "image/x-windowdump", // videos: + "mpv" => "video/x-matroska", "mpeg" => "video/mpeg", "mpe" => "video/mpeg", "mpg" => "video/mpeg", From 57788b48c194314eebfc1657ecc78d2e27cd1434 Mon Sep 17 00:00:00 2001 From: yqjiang Date: Fri, 6 Sep 2013 16:02:15 +0000 Subject: [PATCH 28/36] change mpv to mkv --- includes/mime_detect.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index 6a007ad7..4035afe5 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -162,7 +162,7 @@ class MimeDetect { "xpm" => "image/x-xpixmap", "xwd" => "image/x-windowdump", // videos: - "mpv" => "video/x-matroska", + "mkv" => "video/x-matroska", "mpeg" => "video/mpeg", "mpe" => "video/mpeg", "mpg" => "video/mpeg", From bffc4f725da5071852573e6efbd18f07c97e728d Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Tue, 10 Sep 2013 13:54:43 -0300 Subject: [PATCH 29/36] fixed permissions --- islandora.module | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/islandora.module b/islandora.module index 9fb41528..d213b777 100644 --- a/islandora.module +++ b/islandora.module @@ -22,7 +22,6 @@ * You should have received a copy of the GNU General Public License * along with the program. If not, see . */ - // Common datastreams. define('ISLANDORA_DS_COMP_STREAM', 'DS-COMPOSITE-MODEL'); @@ -485,6 +484,10 @@ function islandora_permission() { 'title' => t('Revert datastream history'), 'description' => t('Revert to a previous version of a datastream.'), ), + ISLANDORA_MANAGE_DELETED_OBJECTS => array( + 'title' => t('Manage deleted objects'), + 'description' => t('Purge or revert deleted objects.'), + ), ); } @@ -504,6 +507,7 @@ function islandora_print_object(AbstractObject $object) { drupal_set_title($object->label); return theme('islandora_object_print', array('object' => $object)); } + /** * Implements hook_forms(). */ @@ -871,7 +875,7 @@ function islandora_view_object(AbstractObject $object) { 'islandora' => array( 'print_img' => $path . '/images/print-icon.png'), ), array( - 'type' => 'setting')); + 'type' => 'setting')); drupal_add_js(array('islandora' => array('print_link' => 'islandora/object/' . $object->id . '/print')), array('type' => 'setting')); drupal_add_js($path . '/js/add_print.js'); From 5c7b425d0b507a907b3dd64534d4a073786188e0 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Tue, 10 Sep 2013 13:56:12 -0300 Subject: [PATCH 30/36] Clarified text on delete button --- includes/object_properties.form.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/object_properties.form.inc b/includes/object_properties.form.inc index a3ceb9e9..838c4078 100644 --- a/includes/object_properties.form.inc +++ b/includes/object_properties.form.inc @@ -78,7 +78,7 @@ function islandora_object_properties_form(array $form, array &$form_state, Abstr 'delete' => array( '#type' => 'submit', '#access' => islandora_object_access(ISLANDORA_PURGE, $object), - '#value' => t('Delete'), + '#value' => t("Permanently remove '@label' from repository", array('@label' => $object->label)), '#submit' => array('islandora_object_properties_form_delete'), '#limit_validation_errors' => array(array('pid')), ), From 99fcc05e33cfdc34ef53dee56dce944d97c5ae14 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Tue, 10 Sep 2013 13:59:17 -0300 Subject: [PATCH 31/36] coder --- islandora.module | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index d213b777..45458665 100644 --- a/islandora.module +++ b/islandora.module @@ -22,6 +22,7 @@ * You should have received a copy of the GNU General Public License * along with the program. If not, see . */ + // Common datastreams. define('ISLANDORA_DS_COMP_STREAM', 'DS-COMPOSITE-MODEL'); @@ -875,7 +876,7 @@ function islandora_view_object(AbstractObject $object) { 'islandora' => array( 'print_img' => $path . '/images/print-icon.png'), ), array( - 'type' => 'setting')); + 'type' => 'setting')); drupal_add_js(array('islandora' => array('print_link' => 'islandora/object/' . $object->id . '/print')), array('type' => 'setting')); drupal_add_js($path . '/js/add_print.js'); From e3b3bd4c543a38b29ecca7f585bfb06b4840ca78 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Tue, 10 Sep 2013 15:46:11 -0300 Subject: [PATCH 32/36] truncated long labels --- includes/object_properties.form.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/object_properties.form.inc b/includes/object_properties.form.inc index 838c4078..5295f067 100644 --- a/includes/object_properties.form.inc +++ b/includes/object_properties.form.inc @@ -78,7 +78,9 @@ function islandora_object_properties_form(array $form, array &$form_state, Abstr 'delete' => array( '#type' => 'submit', '#access' => islandora_object_access(ISLANDORA_PURGE, $object), - '#value' => t("Permanently remove '@label' from repository", array('@label' => $object->label)), + '#value' => t("Permanently remove '@label' from repository", array( + '@label' => truncate_utf8($object->label, 32, TRUE, TRUE)) + ), '#submit' => array('islandora_object_properties_form_delete'), '#limit_validation_errors' => array(array('pid')), ), From cdcc594065fb073abf785ffd0050fa1c810f2f87 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 13 Sep 2013 13:20:43 -0300 Subject: [PATCH 33/36] made derivative creation object state aware --- includes/derivatives.inc | 2 +- islandora.api.php | 43 +++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/includes/derivatives.inc b/includes/derivatives.inc index fbf4b9e7..c66944b1 100644 --- a/includes/derivatives.inc +++ b/includes/derivatives.inc @@ -37,7 +37,7 @@ function islandora_do_derivatives(AbstractObject $object, array $options) { $options += array( 'force' => FALSE, ); - $hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array()); + $hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array($object)); uasort($hooks, 'drupal_sort_weight'); $results = array(); diff --git a/islandora.api.php b/islandora.api.php index 39c6e454..18e5643b 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -578,6 +578,8 @@ function hook_CMODEL_PID_islandora_overview_object_alter(AbstractObject &$object /* * Defines derivative functions to be executed based on certain conditions. * + * @param AbstractObject $object + * Object to which derivatives will be added * This hook fires when an object/datastream is ingested or a datastream is * modified. * @@ -611,33 +613,38 @@ function hook_CMODEL_PID_islandora_overview_object_alter(AbstractObject &$object * - file: A string denoting the path to the file where the function * is being called from. */ -function hook_islandora_derivative() { - return array( - array( - 'source_dsid' => 'OBJ', - 'destination_dsid' => 'DERIV', - 'weight' => '0', - 'function' => array( - 'islandora_derivatives_test_create_deriv_datastream', - ), +function hook_islandora_derivative(AbstractObject $object) { + + $derivatives[] = array( + 'source_dsid' => 'OBJ', + 'destination_dsid' => 'DERIV', + 'weight' => '0', + 'function' => array( + 'islandora_derivatives_test_create_deriv_datastream', ), - array( + ); + // Test object before adding this derivative. + if ($object['SOMEWEIRDDATASTREAM']->mimetype == "SOMETHING/ODD") { + $derivatives[] = array( 'source_dsid' => 'SOMEWEIRDDATASTREAM', 'destination_dsid' => 'STANLEY', 'weight' => '-1', 'function' => array( 'islandora_derivatives_test_create_some_weird_datastream', ), - ), - array( - 'source_dsid' => NULL, - 'destination_dsid' => 'NOSOURCE', - 'weight' => '-3', - 'function' => array( - 'islandora_derivatives_test_create_nosource_datastream', - ), + ); + } + + $derivatives[] = array( + 'source_dsid' => NULL, + 'destination_dsid' => 'NOSOURCE', + 'weight' => '-3', + 'function' => array( + 'islandora_derivatives_test_create_nosource_datastream', ), ); + + return $derivatives; } /** From 9e3d08615f61a176a59fc0c249e655632955b472 Mon Sep 17 00:00:00 2001 From: William Panting Date: Wed, 18 Sep 2013 12:33:25 -0300 Subject: [PATCH 34/36] undelete docs --- islandora.api.php | 9 +++++++++ islandora.module | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/islandora.api.php b/islandora.api.php index 18e5643b..0dff8d89 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -394,8 +394,17 @@ function hook_islandora_viewer_info() { /** * Returns a list of datastreams that are determined to be undeletable. + * + * The list is used to prevent delete links from being shown. + * + * @param array $models + * An array of content models for the current object. + * + * @return array + * An array of DSIDs that shouldn't be deleted. */ function hook_islandora_undeletable_datastreams(array $models) { + return array('DC', 'MODS'); } /** diff --git a/islandora.module b/islandora.module index 45458665..7fb3b477 100644 --- a/islandora.module +++ b/islandora.module @@ -1237,7 +1237,7 @@ function islandora_islandora_required_objects(IslandoraTuque $connection) { } /** - * Implements islandora_undeleteable_datastreams(). + * Implements hook_islandora_undeleteable_datastreams(). */ function islandora_islandora_undeletable_datastreams(array $models) { return array('DC'); From a4dd199aa153f50e70328f92ba138a44ea911e15 Mon Sep 17 00:00:00 2001 From: William Panting Date: Wed, 18 Sep 2013 12:49:30 -0300 Subject: [PATCH 35/36] preventing RELS-EXT deletion --- islandora.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index 7fb3b477..ebf7f916 100644 --- a/islandora.module +++ b/islandora.module @@ -1240,7 +1240,7 @@ function islandora_islandora_required_objects(IslandoraTuque $connection) { * Implements hook_islandora_undeleteable_datastreams(). */ function islandora_islandora_undeletable_datastreams(array $models) { - return array('DC'); + return array('DC', 'RELS-EXT'); } /** From af0a493f5ce95da994f33c2eebde4c9a7510cd57 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 24 Sep 2013 12:21:53 +0000 Subject: [PATCH 36/36] Fix path broken by 1438e806cd92a2b74f718dab83609797edc0fb53. --- islandora.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index ebf7f916..2964ec96 100644 --- a/islandora.module +++ b/islandora.module @@ -878,7 +878,7 @@ function islandora_view_object(AbstractObject $object) { ), array( 'type' => 'setting')); - drupal_add_js(array('islandora' => array('print_link' => 'islandora/object/' . $object->id . '/print')), array('type' => 'setting')); + drupal_add_js(array('islandora' => array('print_link' => 'islandora/object/' . $object->id . '/print_object')), array('type' => 'setting')); drupal_add_js($path . '/js/add_print.js'); drupal_set_title($object->label);