Easy way to generate a list of orphaned objects?

107 views
Skip to first unread message

Brandon Weigel

unread,
Jul 25, 2017, 3:21:51 PM7/25/17
to islandora
The phenomenon of objects getting orphaned when a collection is deleted has been discussed in the past, I believe, but we've got no solution for it. I recently discovered a number of objects in my repository that have no parent collection, and their RELS-EXT lists their parent as a collection that no longer exists.

I'd like to write up a module that lists all objects where the isMemberOfCollection is a value that no longer exists, so that they can be looked at and dealt with. Is there a simple way to generate such a list?

Phil Redmon

unread,
Jul 25, 2017, 3:29:14 PM7/25/17
to islandora
For books:
SELECT ?object ?book
WHERE {
  ?object <fedora-model:hasModel> <info:fedora/fedora-system:FedoraObject-3.0> ;
               <fedora-rels-ext:isMemberOf> ?book .
  OPTIONAL {
    ?book <fedora-model:hasModel> ?model .
  }
  FILTER(!bound(?model))
}
For objects:
SELECT ?object ?collection
WHERE {
  ?object <fedora-model:hasModel> <info:fedora/fedora-system:FedoraObject-3.0> ;
               <fedora-rels-ext:isMemberOfCollection> ?collection .
  OPTIONAL {
    ?collection <fedora-model:hasModel> ?model .
  }
  FILTER(!bound(?model))
}

On Tue, Jul 25, 2017 at 2:21 PM Brandon Weigel <jeanpau...@gmail.com> wrote:
The phenomenon of objects getting orphaned when a collection is deleted has been discussed in the past, I believe, but we've got no solution for it. I recently discovered a number of objects in my repository that have no parent collection, and their RELS-EXT lists their parent as a collection that no longer exists.

I'd like to write up a module that lists all objects where the isMemberOfCollection is a value that no longer exists, so that they can be looked at and dealt with. Is there a simple way to generate such a list?

--
For more information about using this group, please read our Listserv Guidelines: http://islandora.ca/content/welcome-islandora-listserv
---
You received this message because you are subscribed to the Google Groups "islandora" group.
To unsubscribe from this group and stop receiving emails from it, send an email to islandora+...@googlegroups.com.
Visit this group at https://groups.google.com/group/islandora.
To view this discussion on the web visit https://groups.google.com/d/msgid/islandora/7516e09c-b312-47af-be2a-7fa586491d9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brandon Weigel

unread,
Aug 1, 2017, 1:40:42 PM8/1/17
to islandora
Thanks for that, Phil. I guess the next question is, how does one incorporate a SPARQL query like this into Drupal PHP code? 

Phil Redmon

unread,
Aug 1, 2017, 1:46:35 PM8/1/17
to islandora
Assuming you want to identify orphan book pages and objects, and batch delete them, I use the risearch to run it, clean up the output, and then use mark jordan's bulk delete module:


Brandon Weigel

unread,
Aug 1, 2017, 2:04:13 PM8/1/17
to islandora
I'm more interested in generating a list within the UI, and allowing administrators to decide what to do with the objects. They may want to migrate them instead of deleting them, or at least inspect them individually before doing so. Hence my goal of making a module... something that can be run as needed by a non-technical person in the front end.

David John Evans

unread,
Aug 1, 2017, 2:42:12 PM8/1/17
to isla...@googlegroups.com
I maintain the SPARQL Views module for Drupal 7 (https://drupal.org/project/sparql_views), which might help you out. I imagine you'd also want the Views Bulk Operations module (https://www.drupal.org/project/views_bulk_operations), and possibly a custom module to implement the specific operations you want to perform on the objects.

To unsubscribe from this group and stop receiving emails from it, send an email to islandora+unsubscribe@googlegroups.com.

Daniel Aitken

unread,
Aug 1, 2017, 2:44:04 PM8/1/17
to isla...@googlegroups.com
There's actually a handy example in the Tuque docs for doing just this

It also shows what the response from such a query looks like; with that, you can then populate a bunch of options in a form select, for example, doing something to the effect of:

$query = <<<EOQ
[... The query Phil provided ...]
EOQ;
$connection = islandora_get_tuque_connection();
$results = $connection->repository->ri->sparqlQuery($query, -1);
$mapper = function ($result) {
  return $result['pid']['value'];
};
$options = drupal_map_assoc(array_map($mapper, $results));
[... and then go stick that $options list in a form ...]

The simple workflow module provides a decent example of how this can be done in the management form; the list of objects is populated using islandora_simple_workflow_get_inactive_objects() which also demonstrates how to make the results respect XACML and query optionals.

- Dan

Brandon Weigel

unread,
Aug 16, 2017, 11:56:21 AM8/16/17
to islandora
Thanks for the tips, everyone! I'm currently hacking islandora_simple_workflow as per Daniel's suggestion, replacing the original SPARQL query with Phil's (adding ?title to the list) and it seems to be working pretty well! Once I change the "publish" option to a "delete" option it should be ready to use.

Alex Garnett

unread,
Sep 22, 2017, 6:23:51 PM9/22/17
to islandora
Hey Brandon,

Any update on this? I've been orphaning a *lot* of objects lately by deciding I want to re-do ingest of nested collections, and I can zap them all manually, but if you were planning on adding a simpler hook to wipe them out, I'd love it...

Brandon Weigel

unread,
Sep 25, 2017, 9:17:04 AM9/25/17
to islandora
Hey Alex! Sorry I didn't post an update. I completed my module a while ago now, and it's ready for use: https://github.com/bondjimbond/islandora_orphaned_objects 

I've been using it in production, and found over 7,500 orphaned objects. It was pretty nice clearing all that junk out. And our repository isn't that old... I'd be quite curious to know how many invisible orphans a longer-established repository has.

Hope it works well for you!
Reply all
Reply to author
Forward
0 new messages