Upgrading to Liferay DXP part #1 — portletIds
Upgrading to Liferay DXP part #1— portletIds
This blog post is part of the Liferay DXP upgrade series.
Are you working on an upgrade project from Liferay 6.2 to Liferay DXP?
Then, it is very likely, that you will have to deal with this specific use case:
How to replace old portletIds that use old name convention with new ones?
The problem in detail
In your custom portlets, your former portletid was probably close to this:
public static final String OLD_PORTLET_ID = “1_WAR_notificationsportlet”;
Now, our goal will be to replace it with a new OSGI convention, that translates to:
public static final String NEW_PORTLET_ID = “com_liferay_notifications_web_portlet_NotificationsPortlet”;
At the end of the process, we would like that portlet preferences, and other portlet references use an updated portletid.
Liferay UpgradeProcess for the help
Liferay comes with a very neat solution to address this issue — it is called ‘UpgradeProcess’ and you can have multiple of them per module. We will refer to NotificationsWebUpgrade implementation as an example:
Here, all portlet ids:
will be replaced with
What is crucial for us, is that this process takes care of replacing the portletid references such as:
4. User Notification Delivery
5. User Notification Events
6. Instanceable PortletPreferences
For even more details, take a look here: https://github.com/liferay/liferay-portal/blob/65059440dfaf2b8b365a20f99e83e4cdb15478aa/portal-kernel/src/com/liferay/portal/kernel/upgrade/BaseUpgradePortletId.java#L386
Integrating UpgradeStepRegistrator for portletIds
Now, we will want to integrate this UpgradeStep into our custom portlet.
In our example, we will use a simple module created using the following template:
blade create -t mvc-portlet custom-portlet
Then, we will provide the implementation: