Cleaning database of old plugin's items?

I decided to deactivate a few plugins on my site that were basically unused and while for the most part they dissapeared without trace, there seem to be some item entries left of them that show up in a few places of the admin interface and the setting's "account statistics" and so on.

Is there some way to automatically (or easy manually) clean the database of those unwanted entries?

Thanks for the help.

  • i raised this point months ago.. i have not seen a solution / script / plugin shared yet.

    ideally i would add a process to the garbage collector plugin that provide a button in the admin area that can clean out the old entities.

    for a manual approach i would write an elgg batch that deletes the entities according to your preferences.

  • Automated garbage collection might be a bit too risky for deleting this kind of data. It would be difficult to tell what data is still needed and what is not.

    There would have to be some kind of a UI where admin could decide what data is to be deleted. It could also have some kind of basic logic to prevent admin from deleting data that some other data is depenging on. (E.g. trying to delete an entity subtype if there still are entities of that subtype.)

    I have been planning to make a such plugin but it's on a very low priority.

  • Each plugin uses a different method for data saving. Unless you know the code of the plugins, you cant completely remove all the database entries created by the plugin. As ura mentioned, you can write a batch script to remove all entities. But some plugins will create extra annotations (like like, rate plugin etc) and metadata's. 

  • i thought that running the object's delete function would auto-remove all 'owned' metadata/annotations etc.

    is that incorrect?

    the ui for the admin here would only need to allow selection of subtypes and/or a date range.. plus a 'go' button.
    additional aspects, such as a list of all entities to be removed and a way of choosing some or all of them, would be helpful yet is not necessary to resolve the primary issue of having specific old subtypes left in the database (such as after a particular plugin is stopped being used on the site or replaced by a new one with a different subtype id).

  • Ok thanks, a pity that it isn't possible easily.

    Since I am mostly dealing with a few entries what would be the best way to find them manually in the database using a tool like phpmyadmin?

  • i thought that running the object's delete function would auto-remove all 'owned' metadata/annotations etc.

    Yes, that is correct. If the deletion is done through the $entity->delete() function, all owned metadata, annotations, relationships and contained objects will be deleted.

    For example entity subtypes are however not owned by a plugin so that's why they stay in the elgg_entity_subtypes table even if you delete a plugin entity.

  • ah ok, so the cleanup script would need to remove all entities, plus the entity_subtypes.

    to manually remove a small selection, i would create a php function rather than doing it directly in phpmyadmin - this will avoid any misunderstandings about the sql structure, since the php functions already remove the data correctly.

    the php function would receive/build a list of guids for the items to remove and then loop through the list, running $entity->delete() for each item.

    once you are sure there are no items of that subtype left in the database, you could (i think) remove the entity_subtype record for that subtype, manually via phpmyadmin.

  • There occurs no risk in leaving some data behind. But if any issues happen while you remove data via phpmyadmin it can kill / corrupt your db. So before start working with db directly, you should think about it twice.

    Never delete anything directly via phpmyadmin unless you are 100% aware of the consequence or the data structure. Use Elgg api's to delete all contents.


  • does a function exist to remove a subtype?

  • does a function exist to remove a subtype?

    remove_subtype($type, $subtype)