Foren

Execute cleanup code when a portlet is deleted?

thumbnail
Cameron McBride, geändert vor 12 Jahren.

Execute cleanup code when a portlet is deleted?

Expert Beiträge: 269 Beitrittsdatum: 08.02.11 Neueste Beiträge
If you have a portlet that uses the service builder for some database stuff, let's say user bookmarks in this example. There is a portlet on the home page where users can add their own bookmarks. 1000 users add 1000 bookmarks. The admin deletes the portlet. Now in the database there are 1000x1000 entries that are orphaned.

Is there some method that I can implement that will get executed when a portlet is deleted?

I can see several other places that this needs to happen to keep the database from going out of control:
- When the portlet is deleted
- When the page is deleted
- When the site is deleted
- When the user is deleted

How can we make sure our database gets cleaned up on those 4 times?
thumbnail
Sagar A Vyas, geändert vor 12 Jahren.

RE: Execute cleanup code when a portlet is deleted?

Liferay Master Beiträge: 679 Beitrittsdatum: 17.04.09 Neueste Beiträge
Hi Cameron,

What i am thinking is in DB When user ,Page , Site deleted corresponding entry also got deleted.

But data entered by User is never delete.

If we continue with your example bookmark , If admin delete portlet that will not delete corresponding entry from DB, i think it should not cause deleting portlet from page or from community that does not mean that this portlet and related Data entry is not exist in portal it might appear in future.

As per my knowledge there is no way that you can identify whether particular portlet deleted or not and if deleted remove entry programmatic.

If you find something related to this please share it with us.

Thanks,
Sagar Vyas
thumbnail
Cameron McBride, geändert vor 12 Jahren.

RE: Execute cleanup code when a portlet is deleted?

Expert Beiträge: 269 Beitrittsdatum: 08.02.11 Neueste Beiträge
Sagar A Vyas:
What i am thinking is in DB When user ,Page , Site deleted corresponding entry also got deleted.


Does that mean there is something I can add to my portlet so when the user or site is deleted the DB will be cleaned up?

Here is a simple scenario that I tried with 6.0.6 CE, using out-of-the-box content.
1. Create a new community
2. Create one bookmark in the community
3. In the table BookmarksEntry you can see the one bookmark
4. If you search the portal you will see your bookmark returned, as expected
5. Delete the community
6. Check the database again, the bookmark is still there!
7. Search again, the bookmark still shows up!
8. Reindex Bookmarks from Plugins Configuration and it will be gone.
9. Even after reindexing, the bookmark still remains in the database.

#6 seems like a problem, #7 seems like a critical problem. All of that communities content will just remain out there and still be searchable?

Now in this example it was just one single bookmark. What about a large scale deployment over the course of several years. It seems like the database could easily go out of control with orphaned items.