Browse Source

Merge pull request #703 from whikloj/7.x-ISLANDORA-2178

Respect namespace restrictions in manage deleted objects.

A very necessary update. Thanks, @whikloj!
pull/707/head
Brandon Weigel 7 years ago committed by GitHub
parent
commit
51b01c585a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .travis.yml
  2. 72
      includes/manage_deleted_objects.inc
  3. 5
      includes/orphaned_objects.inc

2
.travis.yml

@ -4,7 +4,7 @@ language: php
matrix: matrix:
include: include:
#5.3.3 Ubuntu Precise exceptions #5.3.3 Ubuntu Precise exceptions
- php: 5.3.3 - php: 5.3.3
dist: precise dist: precise
env: FEDORA_VERSION="3.5" env: FEDORA_VERSION="3.5"

72
includes/manage_deleted_objects.inc

@ -12,11 +12,13 @@
* The Drupal form definition. * The Drupal form definition.
* @param array $form_state * @param array $form_state
* The Drupal form state. * The Drupal form state.
* @param string $serialized_chosen
* A serialized array of chosen content models.
* *
* @return array * @return array
* The Drupal form definition. * The Drupal form definition.
*/ */
function islandora_deleted_objects_prep_form($form, $form_state, $serialized_chosen = NULL) { function islandora_deleted_objects_prep_form(array $form, array $form_state, $serialized_chosen = NULL) {
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
$chosen_contentmodels = array(); $chosen_contentmodels = array();
if ($serialized_chosen) { if ($serialized_chosen) {
@ -67,9 +69,9 @@ function islandora_deleted_objects_prep_form($form, $form_state, $serialized_cho
* @param array $form_state * @param array $form_state
* The form state. * The form state.
*/ */
function islandora_deleted_objects_prep_form_submit($form, $form_state) { function islandora_deleted_objects_prep_form_submit(array $form, array $form_state) {
$content_models = $form_state['values']['contentmodels']; $content_models = $form_state['values']['contentmodels'];
$chosen = function($element) { $chosen = function ($element) {
return $element; return $element;
}; };
$serialized_contentmodels = serialize(array_filter($content_models, $chosen)); $serialized_contentmodels = serialize(array_filter($content_models, $chosen));
@ -83,11 +85,13 @@ function islandora_deleted_objects_prep_form_submit($form, $form_state) {
* The Drupal form definition. * The Drupal form definition.
* @param array $form_state * @param array $form_state
* The Drupal form state. * The Drupal form state.
* @param string $serialized_chosen
* A serialized array of chosen content models.
* *
* @return array * @return array
* The Drupal form definition. * The Drupal form definition.
*/ */
function islandora_deleted_objects_manage_form($form, $form_state, $serialized_chosen = NULL) { function islandora_deleted_objects_manage_form(array $form, array $form_state, $serialized_chosen = NULL) {
$form['previous'] = array( $form['previous'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Previous'), '#value' => t('Previous'),
@ -186,7 +190,7 @@ function islandora_deleted_objects_manage_form($form, $form_state, $serialized_c
* @param array $form_state * @param array $form_state
* The form state. * The form state.
*/ */
function islandora_deleted_objects_manage_form_submit($form, $form_state) { function islandora_deleted_objects_manage_form_submit(array $form, array $form_state) {
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
$serialized_chosen = isset($form_state['values']['serialized_chosen']) ? $form_state['values']['serialized_chosen'] : NULL; $serialized_chosen = isset($form_state['values']['serialized_chosen']) ? $form_state['values']['serialized_chosen'] : NULL;
@ -202,6 +206,7 @@ function islandora_deleted_objects_manage_form_submit($form, $form_state) {
$action = 'islandora_purge_object_by_pid'; $action = 'islandora_purge_object_by_pid';
} }
$objects_to_process = array_filter($form_state['values']['objects_to_process']); $objects_to_process = array_filter($form_state['values']['objects_to_process']);
$pids_to_restore = $objects_to_process; $pids_to_restore = $objects_to_process;
if ($form_state['values']['propogate']) { if ($form_state['values']['propogate']) {
foreach ($objects_to_process as $pid) { foreach ($objects_to_process as $pid) {
@ -231,10 +236,17 @@ function islandora_deleted_objects_manage_form_submit($form, $form_state) {
/** /**
* Gets PIDS of all deleted objects. * Gets PIDS of all deleted objects.
* *
* @param array $content_models
* Get deleted object with one of these content models.
* @param int $limit
* Max to get at one time.
* @param int $offset
* Where to start for paging.
*
* @return array * @return array
* PIDS of deleted objects * PIDS of deleted objects
*/ */
function islandora_get_deleted_objects($content_models, $limit, $offset) { function islandora_get_deleted_objects(array $content_models, $limit, $offset) {
$tuque = islandora_get_tuque_connection(); $tuque = islandora_get_tuque_connection();
$repository = $tuque->repository; $repository = $tuque->repository;
$query = islandora_get_deleted_query($content_models, $offset); $query = islandora_get_deleted_query($content_models, $offset);
@ -246,7 +258,8 @@ function islandora_get_deleted_objects($content_models, $limit, $offset) {
$cm_pid = $object['object']['value']; $cm_pid = $object['object']['value'];
$title = $object['label']['value']; $title = $object['label']['value'];
$deleted_objects[$pid] = array( $deleted_objects[$pid] = array(
'title' => $title, 'pid' => $pid, 'title' => $title,
'pid' => $pid,
'content_model' => $content_models[$cm_pid], 'content_model' => $content_models[$cm_pid],
); );
} }
@ -258,16 +271,18 @@ function islandora_get_deleted_objects($content_models, $limit, $offset) {
* Gets PIDS of all content models associated with deleted objects. * Gets PIDS of all content models associated with deleted objects.
* *
* @return array * @return array
* array of content model pids * array of content model pids.
*/ */
function islandora_get_contentmodels_with_deleted_members() { function islandora_get_contentmodels_with_deleted_members() {
$tuque = new IslandoraTuque(); $tuque = new IslandoraTuque();
$repository = $tuque->repository; $repository = $tuque->repository;
$filter = _islandora_get_manage_deleted_query_filter();
$query = "PREFIX fm: <info:fedora/fedora-system:def/model#> $query = "PREFIX fm: <info:fedora/fedora-system:def/model#>
SELECT DISTINCT ?object ?label FROM <#ri> SELECT DISTINCT ?object ?label FROM <#ri>
WHERE { WHERE {
{?subject fm:state fm:Deleted; {?subject fm:state fm:Deleted;
fm:hasModel ?object; fm:hasModel ?object;
$filter
} }
OPTIONAL{ OPTIONAL{
?object fm:label ?label ?object fm:label ?label
@ -288,7 +303,7 @@ function islandora_get_contentmodels_with_deleted_members() {
* Restores deleted object. * Restores deleted object.
* *
* @param string $pid * @param string $pid
* PID of object to be restored * PID of object to be restored.
*/ */
function islandora_restore_object_by_pid($pid) { function islandora_restore_object_by_pid($pid) {
$fedora_object = islandora_object_load($pid); $fedora_object = islandora_object_load($pid);
@ -299,7 +314,7 @@ function islandora_restore_object_by_pid($pid) {
* Purges deleted object. * Purges deleted object.
* *
* @param string $pid * @param string $pid
* PID of object to be restored * PID of object to be restored.
*/ */
function islandora_purge_object_by_pid($pid) { function islandora_purge_object_by_pid($pid) {
$fedora_object = islandora_object_load($pid); $fedora_object = islandora_object_load($pid);
@ -310,14 +325,14 @@ function islandora_purge_object_by_pid($pid) {
* Get query to find all deleted objects by content type. * Get query to find all deleted objects by content type.
* *
* @param array $content_models * @param array $content_models
* Content models to restrict search * Content models to restrict search.
* @param int $offset * @param int $offset
* offset to be added to search * Offset to be added to search.
* *
* @return string * @return string
* Sparql query * Sparql query
*/ */
function islandora_get_deleted_query($content_models, $offset = 0) { function islandora_get_deleted_query(array $content_models, $offset = 0) {
$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 . "> ";
@ -336,5 +351,34 @@ function islandora_get_deleted_query($content_models, $offset = 0) {
"; ";
} }
$optional = "OPTIONAL{?subject fm:label ?label}"; $optional = "OPTIONAL{?subject fm:label ?label}";
return "$prefix $select $where_clause $unions $optional $suffix"; $filter = _islandora_get_manage_deleted_query_filter();
return "$prefix $select $where_clause $unions $optional $filter $suffix";
}
/**
* Reuse namespace restriction filters for basic collection.
*
* This reuses the hook implementation function to make a local
* namespace filter for managing deleted objects.
*
* @return string
* The Sparql filter statement.
*/
function _islandora_get_manage_deleted_query_filter() {
// Reusing the basic collection query filter.
$filter_modules = array(
'islandora_xacml_api',
'islandora',
);
$filters = array();
foreach ($filter_modules as $module) {
$filters = array_merge_recursive($filters, (array) module_invoke($module, 'islandora_basic_collection_get_query_filters', 'view'));
}
$filter_map = function ($filter) {
return "FILTER($filter)";
};
$filter = implode(' ', array_map($filter_map, $filters));
// Hook filters ?object we need to filter ?subject.
$filter = str_replace('?object', '?subject', $filter);
return $filter;
} }

5
includes/orphaned_objects.inc

@ -245,7 +245,10 @@ function islandora_delete_orphaned_objects_batch_operation($pids, &$context) {
islandora_delete_object($target_object); islandora_delete_object($target_object);
$object_check = islandora_object_load($target_pid); $object_check = islandora_object_load($target_pid);
if ($object_check) { if ($object_check) {
drupal_set_message(t('Could not delete ' . $target_pid . '. You may not have permission to manage this object.'), 'error'); drupal_set_message(t('Could not delete %pid. You may not have permission to manage this object.',
array(
'%pid' => $target_pid,
)), 'error');
} }
else { else {
$context['results']['success'][] = $target_pid; $context['results']['success'][] = $target_pid;

Loading…
Cancel
Save