So Private Pages have been deprecated for a while. There was talk about a migration tool in one of Dave’s blog posts over a year ago, but after posting a comment a few days ago asking about an update, I haven’t heard anything (and haven’t found anything while searching before that).
Any news on this or a guide on how to migrate Private Pages to “Regular Pages” so the Deprecated Release Feature Flag can then be turned off?
5 Answers
5
Sorry, didn’t check this for a few days…
What worked for me (at least everything looks good so far in my local environment) is the following Groovy Script. I added some comments:
import com.liferay.portal.kernel.service.LayoutFriendlyURLLocalServiceUtil
import com.liferay.portal.kernel.service.LayoutLocalServiceUtil
import com.liferay.portal.kernel.service.LayoutSetLocalServiceUtil
// Set groupId
groupId = 12345
// Save layoutPlids of updated child Layouts, otherwise concurrency error is thrown because DB entry is handled twice (once when looping over all Layouts and when setting the child parentLayoutId)
layoutPlids = new ArrayList<Long>()
// Loop over private Layouts of Group
for (layout in LayoutLocalServiceUtil.getLayouts(groupId, true)) {
// If plid already updated, skip
if (layoutPlids.contains(layout.getPlid()))
continue
// Save Layout children before updating layoutId, afterwards there won't be any children anymore
layoutChildren = layout.children
// Get next layoutID for public Layouts - otherwise an error might be thrown if privateLayout is set to false, since there is a DB Index on these fields and a Public Page might already have this layoutId
nextLayoutId = LayoutLocalServiceUtil.getNextLayoutId(groupId, false)
updateLayout(layout, nextLayoutId)
// Loop over children and set the new layoutId as the parentLayoutId, then save plid in list. Only handles first level of children
for (layoutChild in layoutChildren) {
layoutChild.setParentLayoutId(nextLayoutId)
updateLayout(layoutChild, LayoutLocalServiceUtil.getNextLayoutId(groupId, false))
layoutPlids.add(layoutChild.getPlid())
// Also update hidden System Layout with the new parentLayoutId
layoutChildSystem = LayoutLocalServiceUtil.getLayout(layoutChild.getPlid() + 1)
layoutChildSystem.setParentLayoutId(nextLayoutId)
updateLayout(layoutChildSystem, LayoutLocalServiceUtil.getNextLayoutId(groupId, false))
}
}
// Function to update the Layout, LayoutFriendlyURL and LayoutSet
def updateLayout(layout, nextLayoutId) {
// Set new layoutId, set privateLayout to false and updage typeSettings
layout.setLayoutId(nextLayoutId)
layout.setPrivateLayout(false)
layout.setTypeSettings(layout.getTypeSettings().replace("privateLayout=true", "privateLayout=false"))
LayoutLocalServiceUtil.updateLayout(layout)
// Update LayoutFriendlyURL - Only handles the default Locale
layoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil.fetchLayoutFriendlyURL(layout.getPlid(), layout.getDefaultLanguageId())
layoutFriendlyURL.setPrivateLayout(false)
LayoutFriendlyURLLocalServiceUtil.updateLayoutFriendlyURL(layoutFriendlyURL)
// Update LayoutSet
layoutSet = layout.getLayoutSet()
layoutSet.setPrivateLayout(false)
LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet)
}
I don’t think your copyLayout() way will work, since this will just copy the Layout and set its privateLayout=true again? The copyLayoutContent() method doesn’t work for me either, it doesn’t copy anything
Source here…
Either way, we also opened a support ticket for this last week. The first reply was “That’s just the way it is, you’ll have to manually create all the pages as Public Pages again and copy all of their contents.” We replied that is not an acceptable solution (and were surprised Liferay would even use this as an official answer from support for a feature that has been around for years and which they will remove in the future). Now Liferay will discuss it internally with the Product Team.
We want an official migration tool or path from Liferay. While my Script above looks ok locally, we don’t want to find issues when we use it in client environments. @dnebing wrote in this blog entry from January 2025 that a migration is in the works 
@dnebing Any news on this?
I wrote a Groovy Script and have it working locally, but an official migration tool or guide would be nicer 
@ChrisHof Thanks for sharing! The approach looks like the idea I had in mind. I realised the friendly URLs would be a problem, but I overlooked, that the private/public split is also mirrored into the type settings. I’ll see if I can add a layout action that our authors can use to move pages.
The approach using copyLayout (with private set to false) seemed to work:
import com.liferay.portal.kernel.service.LayoutLocalServiceUtil;
import com.liferay.portal.kernel.model.Layout;
import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
import java.util.Map;
import java.util.HashMap;
long sourcePlid = 9578782L;
Layout sourceLayout = LayoutLocalServiceUtil.getLayout(sourcePlid);
Map<Locale, String> newNames = new HashMap<>(sourceLayout.getNameMap());
newNames.replaceAll({key, value -> return "Copy of " + value});
Layout resultLayout = LayoutLocalServiceUtil.copyLayout(
sourceLayout.getUserId(),
sourceLayout.getGroupId(),
false, // private
newNames,
false, // hidden
false, // system
true, // copyPermissions
sourcePlid,
ServiceContextThreadLocal.getServiceContext()
);
// WebContent is copied incomplete, manual testing showed that running
// copyContent gives a sane result
LayoutLocalServiceUtil.copyLayoutContent(
LayoutLocalServiceUtil.getLayout(sourceLayout.getPlid()),
LayoutLocalServiceUtil.getLayout(resultLayout.getPlid())
);
resultLayout = LayoutLocalServiceUtil.getLayout(resultLayout.getPlid());
resultLayout.setParentPlid(734719L);
resultLayout.setParentLayoutId(370L);
LayoutLocalServiceUtil.updateLayout(resultLayout);
out.write(resultLayout.getPlid() + " - " + resultLayout.getFriendlyURL());
though retesting right now shows, that the friendly URL also needs to be updated explicitly.
We have a setup were the public tree is partly a mirror of the private tree. For these cases deleting of the private page is the most appropriate approach, but the other pages still need to be integrated and for these a finer grained approach seems sensible. I doubt that we’ll get a satisfatory approach from liferay, so I’ll continue the evaluation of the copy/relocation options.
What version are you on? LayoutLocalServiceUtil.copyLayoutContent() doesn’t do anything on my end 
For the copyLayoutContent: I’m testing with 7.4.3.132 (we are preparing a DXP update, but the Jakarta migration triggered secondary updates that take longer than we wished). I have observed, that for our portlet pages I saw “broken containers” on the page at the location of the portlets and the call to copyLayoutContent fixed that.
For your code: Be careful with this “Also update hidden System Layout with the new parentLayoutId”. This was helpful for content pages indeed both layouts are required, but if you have other layout types (i.e. portlet) adjacent layouts are not related. Looking at the data I see that the classNameId and classPK columns of the system entries point back to the content page. Maybe that is a viable approach.
Be careful here. I experimentally deleted the “system” row of a content-layout pair and the page was then broken.
Would you mind sharing your approach? I remember briefly(!) experimenting with
– matthias.blaesingLayoutLocalServiceUtil#copyLayoutandLayoutLocalServiceUtil#copyLayoutContent. I had to combine both methods as#copyLayoutgenerated only a partial copy and that had to be fixed by running#copyLayoutContent. On the other hand both functions combined superfically seemed to do the right thing.