[Pages] Deleting a Page that works as a Content Type's Page Detail does not update related Content Type
Current Behavior
There is a problem with deleting pages that have been set as Page Detail for Content Types. We are able to delete this page without any issues, however, two things happen:
- The content type still refers to this deleted page, which is wrong. It should be cleaned up.
- Other features like XMLSitemap will fail
ERROR xmlsitemap.XMLSitemapJob: Index: 0, Size: 0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653) ~[?:1.8.0_131]
at java.util.ArrayList.get(ArrayList.java:429) ~[?:1.8.0_131]
at com.dotcms.xmlsitemap.XMLSitemapJob.generateSitemapPerHost_aroundBody0(XMLSitemapJob.java:242) [dotcms_4.2.2_999999.jar:?]
at com.dotcms.xmlsitemap.XMLSitemapJob$AjcClosure1.run(XMLSitemapJob.java:1) [dotcms_4.2.2_999999.jar:?]
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149) [aspectjrt-1.8.10.jar:?]
at com.dotcms.aspects.aspectj.AspectJDelegateMethodInvocation.proceed(AspectJDelegateMethodInvocation.java:43) [dotcms_4.2.2_999999.jar:?]
at com.dotcms.aspects.interceptors.CloseDBIfOpenedMethodInterceptor.invoke(CloseDBIfOpenedMethodInterceptor.java:29) [dotcms_4.2.2_999999.jar:?]
at com.dotcms.aspects.aspectj.CloseDBIfOpenedAspect.invoke(CloseDBIfOpenedAspect.java:41) [dotcms_4.2.2_999999.jar:?]
at com.dotcms.xmlsitemap.XMLSitemapJob.generateSitemapPerHost(XMLSitemapJob.java:179) [dotcms_4.2.2_999999.jar:?]
at com.dotcms.xmlsitemap.XMLSitemapJob.execute(XMLSitemapJob.java:126) [dotcms_4.2.2_999999.jar:?]
at org.quartz.core.JobRunShell.run(JobRunShell.java:223) [dot.quartz-all-1.8.6_2.jar:?]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549) [dot.quartz-all-1.8.6_2.jar:?]
This call
https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotcms/xmlsitemap/XMLSitemapJob.java#L235
only checks if the page detail is populated, but it doesn't say much if it's a valid Page Id. Therefore, this fails
https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotcms/xmlsitemap/XMLSitemapJob.java#L242
With the exception posted above.
Possible Solution
- Once a page is fully deleted, make sure it's not being used as a Page Detail for content types. If it's used, show a list of content types that use this one as a Page Detail one.
Known Workarounds
- Re-assign an existing page or delete the bad entry in the DB.
Steps to Reproduce (for bugs)
- Login to demo.dotcms.com site.
- Delete /blog/blog-detail page.
- Go to Blog Content Type and list its properties. Page Detail is empty:
- Look at the Blog definition in data. Its page_detail attribute is still populated
dotcms420=# select inode, name, page_detail from structure where name = 'Blog';
inode | name | page_detail
--------------------------------------+------+--------------------------------------
799f176a-d32e-4844-a07c-1b5fcd107578 | Blog | 8f9892b8-de32-439a-b496-5c6620ac317a
(1 row)
dotcms420=# select * from identifier where id = '8f9892b8-de32-439a-b496-5c6620ac317a';
id | parent_path | asset_name | host_inode | asset_type | syspublish_date | sysexpire_date
----+-------------+------------+------------+------------+-----------------+----------------
(0 rows)
Context
Reported here https://dotcms.zendesk.com/agent/tickets/94959
Your Environment
- dotCMS version used: 4.2.2.
- Browser Name and version: any Browser.
- Operating System and version: Any OS.
- Application Server and version: Any Application server.
- Java Brand and version: Any supported Java 8 version.
- Database and version: Any DB.
- Application module (if apply): N/A.
in addition to the cleanup suggested here which could be done if the delete is done by the UI, REST endpoint, or Webdav, I would suggest that a specialized warning be displayed if the UI is being used to delete this page or a folder that contains this page
After a discussion with @dsilvam @john-thomas-dotcms @brentgriffin and @joseorsini , we agreed to implement the following fix:
Prevent deletion of the page, and display a message saying something like "This page is set as the detail page for the following Content Types: ... Please update the Content Types to use a different detail page before deleting this page." Note: display the full path of the page causing the problem - i.e. if the user deletes the /about folder, the error message should include the full path where the page is located in /about/news/events/detail.html For webdav, just prevent the deletion and write a similar message to the logs so there's a record of why it didn't work.
After implementation:
When the folder is deleted:

When only the page is deleted:

What happens if you delete the containing folder? What happens if you delete the host? And what happens if you push delete the page? Does the bundle fail? Maybe this was the wrong direction - would it be better removing the page link from the content type?
sent from my mobile
On Dec 19, 2017 11:52 AM, "Nollymar Longa" [email protected] wrote:
After implementation:
[image: screen shot 2017-12-19 at 11 43 59 am] https://user-images.githubusercontent.com/8741395/34168638-06d36300-e4b3-11e7-9a3e-9b04682f0072.png
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dotCMS/core/issues/13222#issuecomment-352818623, or mute the thread https://github.com/notifications/unsubscribe-auth/AA5B3GPn6jPSv07r6n06mMOsxsz86IYQks5tB-nCgaJpZM4RD4me .
PR Core: https://github.com/dotCMS/core/pull/13240
@wezell , do you mean to just delete the link from the Detail Page field? Remember it isn't an optional field. We also considered deleting the page and these were the cons @john-thomas-dotcms found:
- Deleting the detail page makes the URL-mapped content type useless. Therefore the user should have to update the content type, not the page.
- If you delete the detail page, the next time you make any changes to the content type it will also delete the URL map pattern (you have to have both the detail page field and the URL map pattern field filled in, or it will wipe them both out when you save the content type). This means that deleting the detail page from the content type automatically is more destructive than it looks.
- The user deleting the page may not have appropriate permissions to modify the content type (or even appropriate permissions to see the Content Types portlet), so giving them the ability to modify a content type indirectly sounds like a bad idea.
- It's pretty easy to go to the content type and delete the detail page (so it's not too much to ask the user to take that extra step).
So what we should do is this: When a page is deleted, find any content types that use it and update those content types nulling out urlmap and detail page (with the user doing the delete, which will check permissions)
This is not a great fix IMO @dsilvam @wezell
It does prevent the delete but the tool should self heal https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotcms/xmlsitemap/XMLSitemapJob.java#L242
the .get(0) is problematic if the system is missing the detail page.
@jtesser @dsilvam I still think this is the right fix - I am looking at this code now for a customer - this would not be an issue because the detail page would not be set -
https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotcms/xmlsitemap/XMLSitemapJob.java#L235
-Will
@nollymar https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotcms/xmlsitemap/XMLSitemapJob.java#L242 let's please check the size of the list before trying to get the first item
QA Tested and Documented: https://auth.dotcms.com/docs/latest/deleting-a-page