留言板

Clean Liferay DB-Dependencies after undeploying portlets

Morad Ahmad,修改在6 年前。

Clean Liferay DB-Dependencies after undeploying portlets

Junior Member 帖子: 71 加入日期: 10-6-16 最近的帖子
Hi,

I must remove some unused portlets from a portlet-project (not the hole project). For that I
- reomve Portlet Class + Utils
- jsp ...
- remove declarations in portlet.xml, liferay-portlet.xml and liferay-display.xml resource declaration in ... ??.xml

Now I notice in database tables
- table portlet still contain the portlets
- table portletletreferences still contain references to the portlets
- table resourceaction still contain references to the portlets

What is the best way to clean tables?
- Directly delete from table portlet and clean references in both portletletreferences and resourceaction
- Use Liferay Services in a script or job to clean tables
- ???

Is it a good idea to define database constraints to ensure consistency?

Thanks,
Morad.
thumbnail
David H Nebinger,修改在6 年前。

RE: Clean Liferay DB-Dependencies after undeploying portlets

Liferay Legend 帖子: 14918 加入日期: 06-9-2 最近的帖子
Morad Ahmad:
Now I notice in database tables
- table portlet still contain the portlets
- table portletletreferences still contain references to the portlets
- table resourceaction still contain references to the portlets

What is the best way to clean tables?
- Directly delete from table portlet and clean references in both portletletreferences and resourceaction
- Use Liferay Services in a script or job to clean tables
- ???


Just don't do it. There is no reason to worry about records in the database, in fact you're not even supposed to be looking around in there to begin with. Just leave them alone, they won't affect anything.

Is it a good idea to define database constraints to ensure consistency?


No. The fact that you're asking the question is a clear indication that you don't understand how the Liferay database works, how it handles updates and upgrades, etc.

Stay out of the database, it is not yours, it belongs to Liferay. Period.










Come meet me at Devcon 2017 or 2017 LSNA!
Morad Ahmad,修改在6 年前。

RE: Clean Liferay DB-Dependencies after undeploying portlets

Junior Member 帖子: 71 加入日期: 10-6-16 最近的帖子
thanks for your info,

I understand not to access database tables directly. but their must be a way (using Liferay Services PortletLocalServiceUtil and PortletPreferencesLocalServiceUtil) to delete database entries for not more existing portlets.

I think about an update process :

public class CleanUnusedPortlets_2017_09_27 extends UpgradeProcess {

...

private static final String appname = "_WAR_tangoportlet";
private static final String[] portlet_ids = { "cityMap", "sitesmap", "mymeetups", "DefaultUserLinks" };

private void doCleanUnusedPortlets() {
long companyId = PortalUtil.getDefaultCompanyId();
for (String id : portlet_ids) {
deletePortlet(companyId, id + appname);
}
}

private void deletePortlet(long companyId, String portletId) {
// 1. remove portlet entry
// 2. remove all portletprefernces for portletId
// 3. remove all resourceaction for portletId
// ...
}

...

}
thumbnail
David H Nebinger,修改在6 年前。

RE: Clean Liferay DB-Dependencies after undeploying portlets

Liferay Legend 帖子: 14918 加入日期: 06-9-2 最近的帖子
Morad Ahmad:
I understand not to access database tables directly. but their must be a way (using Liferay Services PortletLocalServiceUtil and PortletPreferencesLocalServiceUtil) to delete database entries for not more existing portlets.


You're missing the point. If it were supported, don't you think Liferay would have already done it?

Liferay takes great care in determining what to clean up. It is not automated because redeploys, deploys across the cluster, etc. would all negatively impact the portal.

Your plan does not take into account any of those undeployed portlets and their possible placement on a page. Liferay will give you a handy little blue box indicating the portlet has been undeployed, but that's because the relevant records are all there so you can clean up the pages after the fact. If you go around deleting records out of the database, I can't tell you that the page will even render, let alone handle the removals correctly afterwards.

The point is you wouldn't even know the records were in the database if you hadn't have been diving around in there in the first place.

Just close your database browser and forget that the records even exist. You will be much better off and your environment will be more stable.









Come meet me at Devcon 2017 or 2017 LSNA!
Morad Ahmad,修改在6 年前。

RE: Clean Liferay DB-Dependencies after undeploying portlets

Junior Member 帖子: 71 加入日期: 10-6-16 最近的帖子
Dear David,

thank you so much for answering. But I am not really "happy" with that!

The point is I don't use the portlets any more. I remove all classes, Jsps ... and don't have pages where they are used. I expect either to have a manual way to "delete" these portlets, or that liferay detect that it automatically and clean the related entries in the database. Otherwise I will have in long term an unclean database state...

Best Regards,
Morad.
thumbnail
David H Nebinger,修改在6 年前。

RE: Clean Liferay DB-Dependencies after undeploying portlets

Liferay Legend 帖子: 14918 加入日期: 06-9-2 最近的帖子
Morad Ahmad:
Otherwise I will have in long term an unclean database state...


You perceive it is unclean because you don't understand how it works.

I get that, it is one big grey box that stuff goes in and out of yet few if any of us have a real understanding of how it is all used.

But I can tell you this - there are no foreign keys defined in the database.

This statement alone means you can never be 100% sure that a manually deleted record out of the database won't come back to bite you in the ass later on.

I catch a lot of flack for always advocating the position that no one should be looking in the database. This is backed by my 10 years of experience with Liferay. Manual database modification can make an otherwise stable environment unstable, most of the time immediately but other times it will be some time later when a database restore is out of the question due to data loss.

You're worried about what, 4 records in the portlet table? That's nothing. What you're missing though are records in the permissions table related to those portlets, the preferences information tied to the portlets, any other references that may be littered about the database.

So sure, you go ahead and delete those 4 records if you want. But at some point I guarantee you will regret it. Maybe pages fail right away, maybe some future upgrade process when Liferay is trying to reconcile all of its data but some is missing. I've had more than one upgrade fail because of "cleaned" data from the database that was incomplete.










Come meet me at Devcon 2017 or 2017 LSNA!
Morad Ahmad,修改在6 年前。

RE: Clean Liferay DB-Dependencies after undeploying portlets

Junior Member 帖子: 71 加入日期: 10-6-16 最近的帖子
Dear David I don't plan to modify the database directly. But I search for a clean liferay way to remove unsed portlets using liferay services. As I understand you their is no way to that out of the box and I should leave it so?!
thumbnail
David H Nebinger,修改在6 年前。

RE: Clean Liferay DB-Dependencies after undeploying portlets

Liferay Legend 帖子: 14918 加入日期: 06-9-2 最近的帖子
Morad Ahmad:
Dear David I don't plan to modify the database directly. But I search for a clean liferay way to remove unsed portlets using liferay services. As I understand you their is no way to that out of the box and I should leave it so?!


That's my recommendation, yes. They won't hurt anything, they won't appear in the "add application" menu, you won't see a reference to them anywhere.









Come meet me at Devcon 2017 or 2017 LSNA!