Hi
I want to delete multiple pages from author and publisher. can someone suggest how to achieve this through code.
I have used pagemanager.delete method but it is deleting only in author not in publishers.
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
To delete multiple pages from both the author and publisher in Adobe AEM,
// Inject the ResourceResolverFactory and Replicator services ResourceResolverFactory resolverFactory = sling.getService(ResourceResolverFactory.class) Replicator replicator = sling.getService(Replicator.class) ResourceResolver resolver = null try { // Obtain a resource resolver resolver = resolverFactory.getAdministrativeResourceResolver(null) // Get the PageManager and Replicator services PageManager pageManager = resolver.adaptTo(PageManager.class) // Specify the paths of the pages you want to delete String[] pagePaths = ["/content/mysite/page1", "/content/mysite/page2"] // Add your page paths here for (String pagePath : pagePaths) { // Deactivate the page replicator.replicate(resolver.adaptTo(Session.class), ReplicationActionType.DEACTIVATE, pagePath) // Delete the page from the author instance pageManager.delete(pageManager.getPage(pagePath), true) }
Hi @Nimma05,
If you want to remove the pages from the publisher just unpublish the page from author, it will automatically removes the page from publisher and later you can delete the page in author.
can you please explain the exact use case of deleting the pages through code?
Hi,
I have written the code to deactivate the page and delete. The code is working but the issue is when we are trying to deactivate (through code) multiple pages around thousands of pages in all the publisher it is taking time and instance is getting slow. I am trying to figure out is there any possibility to directly delete the pages from author and it should remove from publisher as well because in my case deactivation is taking so long. So, I am looking for direct step of deletion instead of deactivating page,so automatically it will remove the page from publisher. As how we manually delete the page from author so it will automatically remove from publisher s
Thanks,
Hi @nimm You can use the scheduled job approach and execute the deactivation in phases.
And each time you excute the business logic
1. You can check for the existing jobs if it has been started or not. For that you can use the below logic to check the job status
Job job = jobManager.getJobById(request.getParameter("jobId"));
if(null!=job) {
float percent = (((float) job.getFinishedProgressStep()) / job.getProgressStepCount()) * 100;
// based on the percentage you can define whether your next job should be triggered or not
}
2. You can even check what is the current ReplicationQueue status, how many entries are present in the queue.
API Documentation Reference - https://javadoc.io/doc/com.adobe.aem/aem-sdk-api/latest/com/day/cq/replication/ReplicationQueue.html
Hope you find this helpful!
Thanks
Hi Nimma,
To programmatically unpublish page from author to publish you can use Replicator API with Deactivate action type[1]
To delete pages from author and publish you can use PageManager API[2]
Regards,
Peter
Can you please consider the below scenerio
I have written the code to deactivate the page and delete. The code is working but the issue is when we are trying to deactivate (through code) multiple pages around thousands of pages in all the publisher it is taking time and instance is getting slow. I am trying to figure out is there any possibility to directly delete the pages from author and it should remove from publisher as well because in my case deactivation is taking so long. So, I am looking for direct step of deletion instead of deactivating page,so automatically it will remove the page from publisher. As how we manually delete the page from author so it will automatically remove from publisher s
OOTB, if a published page is being deleted, it will trigger deactivation request. TO avoid system from getting overwhelmed, please try following:
if you delete a page via the pageManager API it should deactivate the page if it's activated.
If you're using Java to interact with your CMS's API and you're finding that the pagemanager.delete method only deletes pages from the author and not the publisher, it suggests that the method may be specific to the authoring environment and doesn't handle deletion from the publisher. To delete pages from both the author and publisher, you'll likely need to use the appropriate APIs provided by your CMS.
Here's a general approach you can take in Java:
Identify the CMS or Platform: Determine what CMS or platform you're using for authoring and publishing content. Each may have its own API or method for managing content.
Authentication: Ensure you have the necessary authentication credentials (API keys, OAuth tokens, etc.) to interact with the CMS's API.
Use the Appropriate API: Depending on the platform, you'll need to use the correct API or method to delete pages. Look for documentation on how to delete pages programmatically. This might involve making HTTP requests to specific endpoints, using client libraries provided by the CMS, or interacting with the CMS's Java SDK if available.
Loop Through Pages: If you need to delete multiple pages, you'll likely need to loop through a list of page IDs or some other identifier and delete each page individually using the API.
Handle Errors: Make sure to handle errors gracefully. Check for errors returned by the API and handle them appropriately in your code.
Here's a simplified example using Java and the HttpClient class to make HTTP requests:
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class PageDeletionExample {
public static void main(String[] args) {
// Assuming you have a list of page IDs to delete
int[] pageIds = {1, 2, 3};
// Assuming you have authentication credentials
String token = "YOUR_API_TOKEN";
HttpClient client = HttpClient.newHttpClient();
for (int pageId : pageIds) {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://your-cms-api.com/pages/" + pageId))
.header("Authorization", "Bearer " + token)
.DELETE()
.build();
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
System.out.println("Page with ID " + pageId + " deleted successfully.");
} else {
System.out.println("Failed to delete page with ID " + pageId + ". Status code: " + response.statusCode());
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
}
Replace "YOUR_API_TOKEN" with your actual API token or authentication method, and "https://your-cms-api.com/pages/" + pageId with the actual endpoint provided by your CMS's API for deleting pages.
Remember to refer to your CMS's documentation for the exact API endpoints and authentication methods. If your CMS provides a Java SDK, it's recommended to use that for interacting with the API as it may provide more convenient methods and error handling.
@Nimma05 , Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
To delete multiple pages from both the author and publisher in Adobe AEM,
// Inject the ResourceResolverFactory and Replicator services ResourceResolverFactory resolverFactory = sling.getService(ResourceResolverFactory.class) Replicator replicator = sling.getService(Replicator.class) ResourceResolver resolver = null try { // Obtain a resource resolver resolver = resolverFactory.getAdministrativeResourceResolver(null) // Get the PageManager and Replicator services PageManager pageManager = resolver.adaptTo(PageManager.class) // Specify the paths of the pages you want to delete String[] pagePaths = ["/content/mysite/page1", "/content/mysite/page2"] // Add your page paths here for (String pagePath : pagePaths) { // Deactivate the page replicator.replicate(resolver.adaptTo(Session.class), ReplicationActionType.DEACTIVATE, pagePath) // Delete the page from the author instance pageManager.delete(pageManager.getPage(pagePath), true) }
Hi All ,
Facing similar issue where in when trying to deactivate the content via ReplicationActionType.DEACTIVATE it is causing performance issues as the content is very huge. Did u find a solution ? can u help if that is the case !
Planning on deactivating only the parent page but not the child content by using custom methods? Has any one tried it . if yes please help , thanks !
@Nimma05 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies