@ -145,7 +145,7 @@ function islandora_get_orphaned_objects() {
$connection = islandora_get_tuque_connection();
$connection = islandora_get_tuque_connection();
// SPARQL: get orphaned objects, exclude any with a living parent.
// SPARQL: get orphaned objects, exclude any with a living parent.
$object_query = < < < EOQ
$object_query = < < < EOQ
PREFIX islandora: < http: / / islandora . ca / ontology / relsext # >
!prefix
SELECT DISTINCT ?object ?title
SELECT DISTINCT ?object ?title
WHERE {
WHERE {
?object < fedora-model:hasModel > < info:fedora / fedora-system:FedoraObject-3 . 0 > ;
?object < fedora-model:hasModel > < info:fedora / fedora-system:FedoraObject-3 . 0 > ;
@ -156,14 +156,12 @@ WHERE {
} .
} .
FILTER (!bound(?model))
FILTER (!bound(?model))
# Filter by "parent" relationships - isMemberOf, isMemberOfCollection, isPageOf.
# Filter by "parent" relationships
FILTER (?p = < fedora-rels-ext:isMemberOfCollection > || ?p = < fedora-rels-ext:isMemberOf > || ?p = < islandora:isPageOf > )
FILTER (!dead_parent_relationships )
# Exclude objects with live parents - isMemberOf, isMemberOfCollection, isPageOf.
# Exclude objects with live parents
OPTIONAL {
OPTIONAL {
{?object < fedora-rels-ext:isMemberOfCollection > ?liveparent }
!live_parent_relationships .
UNION {?object < fedora-rels-ext:isMemberOf > ?liveparent }
UNION { ?object < islandora:isPageOf > ?liveparent } .
?liveparent < fedora-model:hasModel > < info:fedora / fedora-system:FedoraObject-3 . 0 > .
?liveparent < fedora-model:hasModel > < info:fedora / fedora-system:FedoraObject-3 . 0 > .
}
}
!optionals
!optionals
@ -171,7 +169,13 @@ WHERE {
FILTER (!bound(?liveparent))
FILTER (!bound(?liveparent))
} ORDER BY ?object
} ORDER BY ?object
EOQ;
EOQ;
$parent_relationships = module_invoke_all('islandora_solution_pack_child_relationships', 'all');
$parent_relationships['prefix'] = array_unique($parent_relationships['prefix']);
$parent_relationships['predicate'] = array_unique($parent_relationships['predicate']);
if (count($parent_relationships['predicate']) == 0) {
// No predicates to search for. Exit early.
return array();
}
$optionals = (array) module_invoke('islandora_xacml_api', 'islandora_basic_collection_get_query_optionals', 'view');
$optionals = (array) module_invoke('islandora_xacml_api', 'islandora_basic_collection_get_query_optionals', 'view');
$filter_modules = array(
$filter_modules = array(
'islandora_xacml_api',
'islandora_xacml_api',
@ -184,10 +188,16 @@ EOQ;
$filter_map = function ($filter) {
$filter_map = function ($filter) {
return "FILTER($filter)";
return "FILTER($filter)";
};
};
$parent_map = function ($parent) {
return "?object $parent ?liveparent";
};
// Use separate queries for different object types.
// Use separate queries for different object types.
$sparql_query_objects = format_string($object_query, array(
$sparql_query_objects = format_string($object_query, array(
'!optionals' => !empty($optionals) ? ('OPTIONAL {{' . implode('} UNION {', $optionals) . '}}') : '',
'!optionals' => !empty($optionals) ? ('OPTIONAL {{' . implode('} UNION {', $optionals) . '}}') : '',
'!filters' => !empty($filters) ? implode(' ', array_map($filter_map, $filters)) : '',
'!filters' => !empty($filters) ? implode(' ', array_map($filter_map, $filters)) : '',
'!dead_parent_relationships' => '?p = ' . implode(' || ?p = ', $parent_relationships['predicate']),
'!live_parent_relationships' => '{' . implode(' } UNION { ', array_map($parent_map, $parent_relationships['predicate'])) . '}',
'!prefix' => implode("\n", $parent_relationships['prefix']),
));
));
$results = $connection->repository->ri->sparqlQuery($sparql_query_objects);
$results = $connection->repository->ri->sparqlQuery($sparql_query_objects);
return $results;
return $results;