VersionX removing versions for deleted resources

Hi All

Is there some kind of helper snippet or plugin available for versionX that i can trigger to remove all versions of a resource,snippet, chunk etc that does not exist. I found a snippet that someone wrote that only keeps X amount of versions of a plugin, snippet, resource etc.

I would like to completely remove any version of an item that is no longer in the system.

many thanks

VersionX stores the data in the database tables that start with modx_versionx_ (like modx_versionx_chunk, modx_versionx_resource etc. ).

If this is a one-off thing and you are familiar with SQL you can probably just delete the unwanted rows from the appropriate database table in phpMyAdmin. Or you could write a snippet that deletes them with xPDO.

Thanks i will have a look, im going to assume before i look into it that is uses the same getObject / getCollection models that all other elements use.

if so i can loop through them all and apply some logic to only delete ones that do not exist as resources in the system?

Yes, the extra uses normal xpdoObjects. The class names are vxResource, vxChunk etc.

Perfect so if i was to sort of pseudo code it i guess i could do something along the lines of

getIterator all vxResource 

foreach vxResource {

getObject single modResource where id matches the vxResource

if (getobject == null )  {
vxResource->remove();
}

}

That’s probably not the most efficient way, but it should work.

Agreed, using a getObject for each one will be pretty expensive but its a one off thing so it should work hopefully. Cheers for the help.