From 45199e802bc686f29c60617e902d5cf6713c34f5 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 19 Aug 2013 17:58:41 -0300 Subject: [PATCH] converted to sparql - itql was getting messy --- includes/manage_deleted_objects.inc | 45 +++++++++++++++++------------ 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/includes/manage_deleted_objects.inc b/includes/manage_deleted_objects.inc index b2b5077c..75ed2e70 100644 --- a/includes/manage_deleted_objects.inc +++ b/includes/manage_deleted_objects.inc @@ -216,26 +216,29 @@ function islandora_delete_form_contentmodels(array $form, array &$form_state) { function islandora_get_deleted_objects($content_models) { $tuque = islandora_get_tuque_connection(); $repository = $tuque->repository; - $qualifier = ''; - $last_content_model = key(array_slice($content_models, -1, 1, TRUE)); - foreach ($content_models as $content_model) { - $qualifier .= "\$subject <" . FEDORA_MODEL_URI . "hasModel> "; - if ($content_model != $last_content_model) { - $qualifier .= ' or '; - } + $first_contentmodel = array_shift($content_models); + $prefix = "PREFIX fm: <" . FEDORA_MODEL_URI . "> "; + $select = "SELECT ?subject ?label ?object FROM <#ri> WHERE { "; + $where_clause = "{?subject fm:hasModel ; + fm:state fm:Deleted; + fm:hasModel ?object; + }"; + $suffix = '}'; + $unions = ''; + foreach ($content_models as $contentmodel) { + $unions .= "UNION {?subject fm:hasModel ; + fm:state fm:Deleted; + fm:hasModel ?object; + } "; } - - $query = "select \$subject \$title \$object from <#ri>"; - $query .= "where ($qualifier)"; - $query .= "and \$subject <" . FEDORA_MODEL_URI . "state> <" . FEDORA_MODEL_URI . "Deleted>"; - $query .= "and \$subject<" . FEDORA_MODEL_URI . "hasModel> \$object "; - $query .= "and \$subject \$title"; - $objects = $repository->ri->itqlQuery($query, 'unlimited'); + $optional = "OPTIONAL{?subject fm:label ?label}"; + $query = "$prefix $select $where_clause $unions $optional $suffix"; + $objects = $repository->ri->sparqlQuery($query, -1); $deleted_objects = array(); foreach ($objects as $object) { if ($object['object']['value'] != "fedora-system:FedoraObject-3.0") { $pid = $object['subject']['value']; - $title = $object['title']['value']; + $title = $object['label']['value']; $content_model = islandora_object_load($object['object']['value']); $deleted_objects[$pid] = array( 'title' => $title, 'pid' => $pid, @@ -256,11 +259,15 @@ function islandora_get_contentmodels_with_deleted_members() { $tuque = new IslandoraTuque(); $repository = $tuque->repository; - $query = "select \$object from <#ri>"; - $query .= "where \$subject <" . FEDORA_MODEL_URI . "state> <" . FEDORA_MODEL_URI . "Deleted>"; - $query .= "and \$subject<" . FEDORA_MODEL_URI . "hasModel> \$object"; + $query = "PREFIX fm: + SELECT DISTINCT ?object FROM <#ri> + WHERE { + {?subject fm:state fm:Deleted; + fm:hasModel ?object; + } + }"; - $objects = $repository->ri->itqlQuery($query, 'unlimited'); + $objects = $repository->ri->sparqlQuery($query, -1); $content_models = array(); foreach ($objects as $object) { if ($object['object']['value'] != "fedora-system:FedoraObject-3.0") {