Affects Version/s: 7.0.X, Master
Component/s: WCM > Sites Management > Pages Administration
The public API LayoutLocalServiceUtil.deleteLayout(long plid) and LayoutLocalServiceUtil.deleteLayout(Layout layout) do not have an implementation in the LayoutLocalServiceImpl class. As such, when they are called, the autogenerated LayoutLocalServiceBaseImpl implementation of these methods is used. The autogenerated implementation only deletes the Layout itself; it does not delete any objects that may be dependent on the Layout. This is in contrast to the methods that we call to delete Layouts in our code (most commonly, LayoutLocalServiceUtil.deleteLayout(Layout layout, boolean updateLayoutSet, ServiceContext serviceContext)), which delete the Layout and every object that is dependent on it. If someone calls either of these two public APIs, it could cause functionality to break because they will be left with many orphaned objects.
This is a common problem throughout our code, and ideally, something will be done to fix the problem as a whole some day. Many [$MODEL_NAME]BaseLocalServiceImpl methods do not have an implementation in the [$MODEL_NAME]LocalServiceImpl class, yet should never be called because their logic is incorrect (as the logic was autogenerated). This is most common with add[$MODEL_NAME] and delete[$MODEL_NAME] methods, which do not add or remove the necessary associated objects. For now, we will just fix these two methods since someone has just discovered this issue while attempting to use them.
Steps to Reproduce
1. Start up Liferay and log in as the admin user.
2. Add a new page.
3. Look at the Layout table of your database and find the entry corresponding to the page you just added. Make a note of its plid.
4. Navigate to Control Panel > Configuration > Server Administration > Script.
5. Paste the following line in the Script box, replacing "yourPlidHere" with the plid you discovered in step 3:
6. Navigate back to the Site Pages menu and verify that your page was deleted.
7. Attempt to add another page of the same name.
Expected Result: The page is added successfully
Actual Result: The page fails to be added with a nondescript " An unexpected error occurred." message in the UI, and nothing in the logs. Investigating this error reveals that it failed when trying to generate a friendlyURL for the Layout, since an entry of the same friendlyURL exists in the LayoutFriendlyURL table, but its corresponding Layout no longer exists.