Search code examples
javaliferayliferay-7

How can I update a liferay site's template using java?


I'm working on something and I keep encountering an error when I try to update a site's(group) public site template. I'm trying to do so with a liferay module project in java. Basically, the idea is that once a user has completed an amount of tasks they will get the option to change the site template with the push of a button, which turns the site public(the private pages are kept to allow editting).

For this i am using multiple site templates and the updateLayoutSetPrototypeLinkEnabled method from the LayoutSetLocalServiceUtil class.

long groupId = theme.getScopeGroupId();

String publicTemp = "39d15f9c-609c-6b96-aa94-7261ab5a8f6e";
String privateTemp = "e9d93871-a35b-163f-c19d-08d40af6e99c";

// hier wordt de dashboard en profile toegevoegd
LayoutSetLocalServiceUtil.updateLayoutSetPrototypeLinkEnabled(groupId, true, true, privateTemp);
LayoutSetLocalServiceUtil.updateLayoutSetPrototypeLinkEnabled(groupId, false, true, publicTemp);

This is what happens when somebody presses the button i was talking about. However when I do this, the template I am trying to 'assign' to the site doesn't work. The public pages don't get updated, and stay the same regardless of what I try. Even when using the api/jsonws. When looking at the template it says "The propagation of changes from the Site Template has been disabled temporarily after 4 errors. click-reset-and-propagate-to-reset-the-failure-count-and-propagate-changes-from-the-x" Resetting doesn't work of course.

I did try checking the logs and that gives an error

ERROR [http-nio-8080-exec-134][SitesImpl:1431] Merge fail count increased to 4 for layout set prototype 1417422 and layout set 10712
com.liferay.exportimport.kernel.lar.PortletDataException: com.liferay.friendly.url.exception.DuplicateFriendlyURLEntryException: {mvccVersion=0, ctCollectionId=0, friendlyURLEntryLocalizationId=41189, companyId=20097, friendlyURLEntryId=1433713, languageId=nl_NL, urlTitle=/home1, groupId=1431032, classNameId=36601, classPK=19870}

Well what i've tried so far is to turn off the propagation settings on the site template. Which didn't change anything really. I also tried turning off propagation in the updateLayoutSetPrototypeLinkEnabled method. But this didn't seem to work.

I also tried to assign a different public template first and to then change it to the one i want. But this causes an even bigger error. The last thing I changed in my code was adding a bit of code that i found someone using online, but I must admit I don't really know what it's supposed to do:

LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, true);
SitesUtil.mergeLayoutSetPrototypeLayouts(group, layoutSet);

regardless this didn't solve the issue. Lastly i've tried changing the site template, but even emptying it out completely doesn't work. It's like this specific template is just broken now?

I must admit that i'm a little bit in over my head here and haven't been able to figure it out myself. So my question is, does anybody know what could be causing this error? And am I using the right method to update a site's layout?


Solution

  • It seems my problem was quite simple. My different site templates all shared the same name for their home page. This caused a DuplicateFriendlyURLEntryException.

    Changing the home page friendly url for every template solved the issue. But remember to also delete the pages url history or it still won't work.