Hi I want to know the correct way to use deepCopyFunction for coping one page to another page including the attachment
To utilize the deepCopyPage function in Confluence for copying a page, including attachments, follow these steps.
First, obtain a PageManager reference using ComponentLocator. Create a PageCopyOptions object, specifying attachment inclusion, and retrieve references to the original page and destination parent page.
Then, invoke the deepCopyPage function, passing the options, original page, and destination parent page. Ensure the destination parent page exists, and consider handling potential title conflicts, permission issues, and page hierarchy limits.
java
PageManager pageManager = ComponentLocator.getComponent(PageManager.class);
java
PageCopyOptions pageCopyOptions = PageCopyOptions.builder()
.withAttachments(true)
.build();
java
Page originalPage = pageManager.getPage(originalSpaceKey, originalPageTitle);
Page destinationParentPage = pageManager.getPage(destinationSpaceKey, destinationParentPageTitle);
java
pageManager.deepCopyPage(pageCopyOptions, originalPage, destinationParentPage);
java
import com.atlassian.confluence.pages.PageManager;
import com.atlassian.confluence.pages.Page;
import com.atlassian.confluence.pages.persistence.dao.bulk.copy.PageCopyOptions;
import com.atlassian.sal.api.component.ComponentLocator;
// Get PageManager
PageManager pageManager = ComponentLocator.getComponent(PageManager.class);
// Set up copy options
PageCopyOptions pageCopyOptions = PageCopyOptions.builder()
.withAttachments(true)
.build();
// Get original and destination pages
Page originalPage = pageManager.getPage("SOURCESPACE", "Source Page Title");
Page destinationParentPage = pageManager.getPage("DESTSPACE", "Destination Parent Page Title");
// Perform the deep copy
pageManager.deepCopyPage(pageCopyOptions, originalPage, destinationParentPage);
-------------------------------------------------------------------------
The provided code facilitates the duplication of a Confluence page, including attachments, as a child page under a specified destination parent. Key considerations for successful execution include:
The destination parent page must pre-exist.
The duplicated page retains its original title, potentially necessitating conflict resolution if a similarly titled page already exists.
Adequate permissions are required to perform this operation.
The process may fail due to excessive pages in the hierarchy (default limit: 2000), adjustable by administrators.
Robust exception handling is crucial to mitigate issues such as page non-existence or permission conflicts.
Hope this helps - Happy to help further!!
Thank you very much and have a great one!
Warm regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.