From 061ead2013d0ca41b09f5d3c34b8ac3e91395a86 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Mon, 23 Nov 2020 16:29:31 +0000 Subject: [PATCH 1/2] Convert islandora_object_load to a solr query --- includes/orphaned_objects.inc | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/includes/orphaned_objects.inc b/includes/orphaned_objects.inc index 1766d842..530ef303 100644 --- a/includes/orphaned_objects.inc +++ b/includes/orphaned_objects.inc @@ -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,8 @@ function islandora_get_orphaned_objects() { $orphaned_objects[] = $result; } elseif (!in_array($membership, $already_checked)) { - $test = islandora_object_load($membership); +$test=islandora_object_load($membership); + $test = islandora_identify_dead_parents($membership); if (!$test) { $orphaned_objects[] = $result; $dead_parents[] = $membership; @@ -292,6 +293,7 @@ EOQ; )); $results = $connection->repository->ri->sparqlQuery($sparql_query_objects); } +dd($results); return $results; } @@ -320,6 +322,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. * From 42775301fdad034df4b70105762146b559132552 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Mon, 23 Nov 2020 17:28:40 +0000 Subject: [PATCH 2/2] Fix the php error --- includes/orphaned_objects.inc | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/includes/orphaned_objects.inc b/includes/orphaned_objects.inc index 530ef303..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') { @@ -219,7 +219,6 @@ 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; @@ -293,7 +292,6 @@ EOQ; )); $results = $connection->repository->ri->sparqlQuery($sparql_query_objects); } -dd($results); return $results; } @@ -327,21 +325,21 @@ function islandora_delete_orphaned_objects_create_batch(array $pids) { * */ 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(); - } + $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); }