|
|
@ -6,7 +6,7 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Manages the two deletion management forms. |
|
|
|
* The deletion management prep form. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param array $form |
|
|
|
* @param array $form |
|
|
|
* The Drupal form definition. |
|
|
|
* The Drupal form definition. |
|
|
@ -16,86 +16,71 @@ |
|
|
|
* @return array |
|
|
|
* @return array |
|
|
|
* The Drupal form definition. |
|
|
|
* The Drupal form definition. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function islandora_deleted_objects_form($form, &$form_state) { |
|
|
|
function islandora_deleted_objects_prep_form($form, $form_state, $serialized_chosen = NULL) { |
|
|
|
if (!isset($form_state['stage'])) { |
|
|
|
module_load_include('inc', 'islandora', 'includes/utilities'); |
|
|
|
$form_state['stage'] = 'get_content_models'; |
|
|
|
$chosen_contentmodels = array(); |
|
|
|
} |
|
|
|
if ($serialized_chosen) { |
|
|
|
$form = array(); |
|
|
|
$chosen_contentmodels = unserialize($serialized_chosen); |
|
|
|
switch ($form_state['stage']) { |
|
|
|
} |
|
|
|
case 'get_content_models': |
|
|
|
$contentmodels_with_deleted_members = islandora_get_contentmodels_with_deleted_members(); |
|
|
|
$form = islandora_delete_form_contentmodels($form, $form_state); |
|
|
|
$elegible_contentmodels = array_keys($contentmodels_with_deleted_members); |
|
|
|
|
|
|
|
if (empty($contentmodels_with_deleted_members)) { |
|
|
|
break; |
|
|
|
$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': |
|
|
|
foreach ($table_element['#options'] as $option) { |
|
|
|
$form = islandora_delete_form_select_objects($form, $form_state); |
|
|
|
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; |
|
|
|
return $form; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Submit handler for deletion management. |
|
|
|
* Submit handler for deletion management prep form. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param array $form |
|
|
|
* @param array $form |
|
|
|
* The form. |
|
|
|
* The form. |
|
|
|
* @param array $form_state |
|
|
|
* @param array $form_state |
|
|
|
* The form state. |
|
|
|
* The form state. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function islandora_deleted_objects_form_submit($form, &$form_state) { |
|
|
|
function islandora_deleted_objects_prep_form_submit($form, $form_state) { |
|
|
|
if (isset($form_state['clicked_button']['#attributes']['source']) && $form_state['clicked_button']['#attributes']['source'] == 'previous') { |
|
|
|
$content_models = $form_state['values']['contentmodels']; |
|
|
|
$form_state['rebuild'] = TRUE; |
|
|
|
$chosen = function($element) { |
|
|
|
$form_state['stage'] = 'get_content_models'; |
|
|
|
return $element; |
|
|
|
return; |
|
|
|
}; |
|
|
|
} |
|
|
|
$serialized_contentmodels = serialize(array_filter($content_models, $chosen)); |
|
|
|
|
|
|
|
drupal_goto("admin/islandora/restore/manage/$serialized_contentmodels"); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The second form in the deletion managemnt process. |
|
|
|
* The deletion management prep form. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param array $form |
|
|
|
* @param array $form |
|
|
|
* The Drupal form definition. |
|
|
|
* The Drupal form definition. |
|
|
@ -105,17 +90,21 @@ function islandora_deleted_objects_form_submit($form, &$form_state) { |
|
|
|
* @return array |
|
|
|
* @return array |
|
|
|
* The Drupal form definition. |
|
|
|
* 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( |
|
|
|
$form['previous'] = array( |
|
|
|
'#type' => 'submit', |
|
|
|
'#type' => 'submit', |
|
|
|
'#value' => t('Previous'), |
|
|
|
'#value' => t('Previous'), |
|
|
|
'#attributes' => array('source' => 'previous'), |
|
|
|
'#attributes' => array('source' => 'previous'), |
|
|
|
); |
|
|
|
); |
|
|
|
$content_models = $form_state['values']['content_models']; |
|
|
|
|
|
|
|
$valid = function($element) { |
|
|
|
$chosen_contentmodels = unserialize($serialized_chosen); |
|
|
|
return $element; |
|
|
|
$content_models_with_deleted = islandora_get_contentmodels_with_deleted_members(); |
|
|
|
}; |
|
|
|
foreach ($chosen_contentmodels as $contentmodel) { |
|
|
|
$chosen_contentmodels = array_filter($content_models, $valid); |
|
|
|
if (!array_key_exists($contentmodel, $content_models_with_deleted)) { |
|
|
|
|
|
|
|
unset($chosen_contentmodels[$contentmodel]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (empty($chosen_contentmodels)) { |
|
|
|
if (empty($chosen_contentmodels)) { |
|
|
|
$form['message'] = array( |
|
|
|
$form['message'] = array( |
|
|
@ -124,7 +113,32 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) { |
|
|
|
); |
|
|
|
); |
|
|
|
return $form; |
|
|
|
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( |
|
|
|
$form['propogate'] = array( |
|
|
|
'#title' => t('Apply changes to related objects?'), |
|
|
|
'#title' => t('Apply changes to related objects?'), |
|
|
|
'#default_value' => TRUE, |
|
|
|
'#default_value' => TRUE, |
|
|
@ -143,7 +157,7 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) { |
|
|
|
'content_model' => t('Content Model'), |
|
|
|
'content_model' => t('Content Model'), |
|
|
|
), |
|
|
|
), |
|
|
|
'#multiple' => TRUE, |
|
|
|
'#multiple' => TRUE, |
|
|
|
'#options' => $options, |
|
|
|
'#options' => $options_this_page, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$form['submit'] = array( |
|
|
|
$form['submit'] = array( |
|
|
@ -158,62 +172,60 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) { |
|
|
|
'#attributes' => array('source' => 'purge'), |
|
|
|
'#attributes' => array('source' => 'purge'), |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $form; |
|
|
|
return $form; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The first form in the deletion management process. |
|
|
|
* Submit handler for deletion management form. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param array $form |
|
|
|
* @param array $form |
|
|
|
* The Drupal form definition. |
|
|
|
* The form. |
|
|
|
* @param array $form_state |
|
|
|
* @param array $form_state |
|
|
|
* The Drupal form state. |
|
|
|
* The form state. |
|
|
|
* |
|
|
|
|
|
|
|
* @return array |
|
|
|
|
|
|
|
* The Drupal form definition. |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
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'); |
|
|
|
module_load_include('inc', 'islandora', 'includes/utilities'); |
|
|
|
$contentmodels_with_deleted_members = islandora_get_contentmodels_with_deleted_members(); |
|
|
|
$serialized_chosen = isset($form_state['values']['serialized_chosen']) ? $form_state['values']['serialized_chosen'] : NULL; |
|
|
|
$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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($table_element['#options'] as $option) { |
|
|
|
if (isset($form_state['clicked_button']['#attributes']['source']) && $form_state['clicked_button']['#attributes']['source'] == 'previous') { |
|
|
|
if (!in_array($option['pid'], $elegible_contentmodels)) { |
|
|
|
drupal_goto("admin/islandora/restore/prep/$serialized_chosen"); |
|
|
|
unset($table_element['#options'][$option['pid']]); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ($form_state['clicked_button']['#attributes']['source'] == 'restore') { |
|
|
|
|
|
|
|
$descriptor = "Restoring"; |
|
|
|
|
|
|
|
$action = 'islandora_restore_object_by_pid'; |
|
|
|
} |
|
|
|
} |
|
|
|
if (isset($form_state['values']['chosen'])) { |
|
|
|
if ($form_state['clicked_button']['#attributes']['source'] == 'purge') { |
|
|
|
$chosen_contentmodels = $form_state['values']['chosen']; |
|
|
|
$descriptor = "Purging"; |
|
|
|
foreach ($table_element['#options'] as $option) { |
|
|
|
$action = 'islandora_purge_object_by_pid'; |
|
|
|
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', |
|
|
|
$batch = array( |
|
|
|
'#value' => t('Next'), |
|
|
|
'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); |
|
|
|
$candidates = array_keys($content_models); |
|
|
|
$first_contentmodel = array_shift($candidates); |
|
|
|
$first_contentmodel = array_shift($candidates); |
|
|
|
$prefix = "PREFIX fm: <" . FEDORA_MODEL_URI . "> "; |
|
|
|
$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 <info:fedora/$first_contentmodel>; |
|
|
|
$where_clause = "{?subject fm:hasModel <info:fedora/$first_contentmodel>; |
|
|
|
fm:state fm:Deleted; |
|
|
|
fm:state fm:Deleted; |
|
|
|
fm:hasModel ?object; |
|
|
|
fm:hasModel ?object; |
|
|
|