diff --git a/includes/orphaned_objects.inc b/includes/orphaned_objects.inc index 1766d842..44073886 100644 --- a/includes/orphaned_objects.inc +++ b/includes/orphaned_objects.inc @@ -55,7 +55,7 @@ function islandora_manage_orphaned_objects_form(array $form, array $form_state) Please be cautious when deleting, as this action is irreversible.'), 'warning'); $orphaned_objects = islandora_get_orphaned_objects(); $query_method = variable_get('islandora_orphaned_objects_backend', 'Solr'); - + module_load_include('inc', 'islandora', 'includes/utilities'); $rows = array(); foreach ($orphaned_objects as $orphaned_object) { if ($query_method == 'SPARQL') { @@ -204,7 +204,7 @@ function islandora_get_orphaned_objects() { $orphaned_objects[] = $result; } elseif (!in_array($collection, $already_checked)) { - $test = islandora_object_load($collection); + $test = islandora_identify_dead_parents($collection); if (!$test) { $orphaned_objects[] = $result; $dead_parents[] = $collection; @@ -219,7 +219,7 @@ function islandora_get_orphaned_objects() { $orphaned_objects[] = $result; } elseif (!in_array($membership, $already_checked)) { - $test = islandora_object_load($membership); + $test = islandora_identify_dead_parents($membership); if (!$test) { $orphaned_objects[] = $result; $dead_parents[] = $membership; @@ -320,6 +320,30 @@ function islandora_delete_orphaned_objects_create_batch(array $pids) { return $batch; } +/** + * Solr query to check for deceased parents. + * + */ +function islandora_identify_dead_parents($parent) { + $parent_params = "PID"; + $parent_test = substr($parent, strpos($parent, '/') +1); + $parent_query = 'PID:"' . $parent_test . '"'; + $qp = new islandoraSolrQueryProcessor(); + $qp->buildQuery($parent_query); + $qp->solrParams['fl'] = $parent_params; + $qp->solrLimit = 1000000000; + $qp->executeQuery(FALSE); + try { + $parent_results = $qp->islandoraSolrResult['response']['objects']; + } + catch (Exception $e) { + watchdog_exception('Islandora', $e, 'Got an exception searching for parent objects .', array(), WATCHDOG_ERROR); + $parent_results = array(); + } + return($parent_results); +} + + /** * Constructs and performs the deleting batch operation. *