Hi I want to know the correct way to use deepCopyFunction for coping one page to another page including the attachment
Hi @Siddhant Jain
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);
PageCopyOptions pageCopyOptions = PageCopyOptions.builder()
.withAttachments(true)
.build();
Page originalPage = pageManager.getPage(originalSpaceKey, originalPageTitle);
Page destinationParentPage = pageManager.getPage(destinationSpaceKey, destinationParentPageTitle);
pageManager.deepCopyPage(pageCopyOptions, originalPage, destinationParentPage);
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
// Set up copy options
// 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
-------------------------------------------------------------------------
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
Instead of PageManager reference using ComponentLocator why we can't use PageManger constructor
We can't use the PageManager constructor directly because PageManager is an interface, not a concrete class.
The Confluence framework provides its implementation at runtime, and ComponentLocator is used to retrieve the properly initialized instance. This ensures that all dependencies are correctly managed within Confluence's service framework.
To learn more - Accessing Confluence Components from Plugin Modules
Hope this helps!!
It looks like you're new here. Sign in or register to get started.