Deleting un-referenced items
AnsweredI'm trying to write a cleaning script that will go through an app and delete any items that are not referenced from other apps.
I can see the information under ->refs
in the PodioItem::get
method and in the PodioItem::get_references
method, but I can't see any information about it in PodioItem::filter
, and I can't filter based on whether items are referenced.
Is there a better way to run this than to grab 500 items with filter
, get
each item from its ID, check if it has references, delete it if it doesn't, get
the next item, repeat, then grab the next 500 items and start again?
-
Jonathan, you need to be careful with this as you are doing a form of referential integrity (as it used to be called) but Podio is more of a Object relational model.
Even if an object is deleted recording that it was attached at some point to another app item is a valid use case in some situations.
You could use the app ref item returned to then make another call with a GET and check for an error return. You will burn through api calls however... -
@Steve I don't think I explained myself well enough.
Basically we have a large number of items in an app which were imported badly. All items in this app should be referenced from app reference fields in other apps. If they're not referenced by any other items, then they're unneeded and so should be deleted to remove clutter.
What I want to do is look at each item, see if any other items in other apps are linking to it from an app reference field, and if it is completely 'orphaned' (i.e. not linked to), delete it. I can't seem to work out a way to do this without a
get
call for every item in the app, as the information I need (references) is not included infilter
responses. -
Hi Jonathan,
You're right that you cannot filter items by "does any other items reference this". What you can do, though, is to use the
refs
property on an item, which is the number of other items referencing this item (it will thus be 0 if no other items reference it). This property is not included by default, so you need to specify that you'd like it to be included. To do so, pass in array("fields" => "refs") as the options-argument to PodioItem::filter.Best,
Andreas
Please sign in to leave a comment.
Comments
4 comments