dotCMS / dotCMS/core

[DEFECT] Copy content dialog not showing when editing content from duplicated page

Open
#34,461 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

dotCMS : Content Management OKR : Customer Support Team : Maintenance
Dominant language
Java
Stars
970
Forks
486
Avg merge
3d 33m
Merged PRs (30d)
170

Description

Problem Statement

When a contentlet is assigned to a page and that page is duplicated, editing the contentlet from the duplicated page should show a dialog indicating that the content is being used in multiple pages (with options to copy or edit globally). However, the dialog does not appear and the editor opens directly, even though the contentlet is now referenced by 2 pages.

Impact: Users editing content from duplicated pages are not warned that changes will affect all pages using that content, leading to unintended content modifications across multiple pages.

Affected Users: Content editors working with duplicated pages
Frequency: Occurs every time a page is duplicated and content is edited from the duplicate

Steps to Reproduce

  1. Create a contentlet (e.g., a text content)
  2. Assign it to Page A
  3. Duplicate Page A to create Page B (now the contentlet is referenced by 2 pages)
  4. Navigate to Page B in edit mode: /edit-page/content?url=%2Fpage-b&language_id=1&device_inode=&mId=edit&mode=EDIT_MODE
  5. Click to edit the contentlet
  6. Expected: Dialog appears saying "This content is being used in other places" with options to proceed
  7. Actual: Editor opens directly without showing the dialog

Acceptance Criteria

  • When editing a contentlet from a duplicated page, the copy content dialog appears if the contentlet is referenced by more than 1 page
  • The dialog correctly shows the number of pages referencing the contentlet
  • The dialog provides options to copy the content (edit only for this page) or edit globally (affects all pages)
  • After page duplication, the contentlet reference count cache is properly invalidated
  • The fix works for both inline editing (TinyMCE) and block editor contentlets

dotCMS Version

Latest from main branch (affects all versions using MultiTree cache)

Severity

Medium - Some functionality impacted (workaround available via cache flush)

Links

NA

Root Cause & Solution

Root Cause: When a page is duplicated via copyMultiTree(), new rows are inserted into the multi_tree table with the same child (contentlet identifier) but different parent1 (pageId). However, the cache for getAllContentletReferencesCount() is not invalidated, so when the duplicated page is rendered, the backend queries the cache and gets the old count (e.g., 1 instead of 2). This causes data-dot-on-number-of-pages to be set incorrectly, and the frontend doesn't show the dialog because Number(1) > 1 is false.

Solution: Modify MultiTreeAPIImpl.copyMultiTree() to invalidate the contentlet reference count cache for all contentlets being copied when a page is duplicated. This will ensure that getAllContentletReferencesCount() queries the database and returns the correct count on the next page render.

Implementation Details:

  • Add cache invalidation logic at the end of copyMultiTree() method
  • Collect all unique contentlet IDs from the multiTrees being copied
  • Invalidate cache for each contentlet using multiTreeCache.removeContentletReferenceCount()
  • This will force a fresh database query on the next page render, ensuring accurate reference counts

Files to Modify:

  • dotCMS/src/main/java/com/dotmarketing/factories/MultiTreeAPIImpl.java - Add cache invalidation in copyMultiTree() method

Workaround (until fix is implemented):

  • Clear cache manually

Freshdesk ticket link : https://dotcms.freshdesk.com/a/tickets/35130

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in dotCMS/src/main/java/com/dotmarketing/factories/MultiTreeAPIImpl.java, focusing on copyMultiTree() and the multiTreeCache usage. Trace getAllContentletReferencesCount() and removeContentletReferenceCount() to understand the cache flow. Done means duplicated contentlets report the correct page count and the copy-content dialog works for inline and block editor contentlets.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.