diff --git a/includes/orphaned_objects.inc b/includes/orphaned_objects.inc index 606a988d..54a156ce 100644 --- a/includes/orphaned_objects.inc +++ b/includes/orphaned_objects.inc @@ -156,21 +156,24 @@ WHERE { } . FILTER (!bound(?model)) - # Filter by "parent" relationships - isMemberOf, isMemberOfCollection, isPageOf. - FILTER (?p = || ?p = || ?p = ) + # Filter by "parent" relationships + FILTER (!dead_parent_relationships) -# Exclude objects with live parents - isMemberOf, isMemberOfCollection, isPageOf. - OPTIONAL { - {?object ?liveparent } - UNION {?object ?liveparent } - UNION { ?object ?liveparent } . - ?liveparent . + # Exclude objects with live parents - isMemberOf, isMemberOfCollection, isPageOf. + OPTIONAL { + !live_parent_relationships . + ?liveparent . } !optionals !filters FILTER (!bound(?liveparent)) } ORDER BY ?object EOQ; + $parent_relationships = array('', '', ''); + if (module_exists('islandora_compound_object')) { + $predicate = variable_get('islandora_compound_object_relationship', 'isConstituentOf'); + $parent_relationships[] = ""; + } $optionals = (array) module_invoke('islandora_xacml_api', 'islandora_basic_collection_get_query_optionals', 'view'); $filter_modules = array( @@ -184,10 +187,15 @@ EOQ; $filter_map = function ($filter) { return "FILTER($filter)"; }; + $parent_map = function ($parent) { + return "?object $parent ?liveparent"; + }; // Use separate queries for different object types. $sparql_query_objects = format_string($object_query, array( '!optionals' => !empty($optionals) ? ('OPTIONAL {{' . implode('} UNION {', $optionals) . '}}') : '', '!filters' => !empty($filters) ? implode(' ', array_map($filter_map, $filters)) : '', + '!dead_parent_relationships' => '?p = ' . implode(' || ?p = ', $parent_relationships), + '!live_parent_relationships' => '{' . implode(' } UNION { ', array_map($parent_map,$parent_relationships)) . '}', )); $results = $connection->repository->ri->sparqlQuery($sparql_query_objects); return $results;