Browse Source

Allow orphaned object report to find orphaned compound objects. (#710)

* Allow orphaned object report to find orphaned compound objects.

* Add hook for child relationships

* Add conditional checking if we are working with an empty set.

* Add way to filter hook on content model.

* Sacrifical commit for coding standards gods.

* Less python in example.

* More uniqueness
7.x-1.12
Jonathan Green 6 years ago committed by Diego Pino Navarro
parent
commit
f3b3ffc472
  1. 30
      includes/orphaned_objects.inc
  2. 27
      islandora.api.php
  3. 9
      islandora.module

30
includes/orphaned_objects.inc

@ -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,22 +156,26 @@ 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 } ?liveparent <fedora-model:hasModel> <info:fedora/fedora-system:FedoraObject-3.0> .
UNION { ?object <islandora:isPageOf> ?liveparent } .
?liveparent <fedora-model:hasModel> <info:fedora/fedora-system:FedoraObject-3.0> .
} }
!optionals !optionals
!filters !filters
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;

27
islandora.api.php

@ -966,3 +966,30 @@ function hook_islandora_datastream_filename_alter(&$filename, AbstractDatastream
); );
} }
} }
/**
* Allow solution packs to register relationships used for children.
*
* @param string|array $cmodels
* This takes either:
* - string: the string 'all'. Function returns all child relationships.
* - array: an array of cmodel PIDs to return the relationships for.
*
* @return array
* - prefix (array): This is is a valid snip-it of SPARQL to register
* prefixes used in the predicates array.
* - predicate (array): This array contains predicates used by the solution
* pack for child objects.
*/
function hook_islandora_solution_pack_child_relationships($cmodels) {
if ($cmodels === 'all' || in_array('my:cmodel_pid', $cmodels)) {
return array(
'prefix' => array('PREFIX islandora: <http://islandora.ca/ontology/relsext#>'),
'predicate' => array(
'<fedora-rels-ext:isMemberOfCollection>',
'<fedora-rels-ext:isMemberOf>',
'<islandora:isPageOf>',
),
);
}
}

9
islandora.module

@ -2215,3 +2215,12 @@ function islandora_islandora_breadcrumbs_backends() {
), ),
); );
} }
/**
* Implements hook_islandora_solution_pack_child_relationships
*/
function islandora_islandora_solution_pack_child_relationships($cmodels) {
// Return empty arrays from core implementation so that these keys always
// exist when the hook is called, even if no module responds.
return array('predicate' => array(), 'prefix' => array());
}

Loading…
Cancel
Save