Unpublish AEM page from code
Hello,
I have a requirement to unpublish a page from AEM and move that unpublished page to another location.
From an author service, I did this,
String pagePath = hit.getPath();
replicator.replicate(session, ReplicationActionType.DEACTIVATE, pagePath); // Unpublish the Page
pageMoveService.movePages(pageManager, deletedDestinationPath, pagePath, deletedPageTitleSuffix); // Move that page in different location
In another Preprocessor, which is written for general page publish/unpublish,
String eventType = replicationAction.getType().getName();
String replicationPath = replicationAction.getPath();
if (!eventType.equals("Activate")) {
Resource resource = resourceResolver.getResource(replicationPath + "/jcr:content");
// Some business logic
}
This works fine, but the issue is, when I request to deactivate the page sometimes it's not being Unpublished instantly. That's why the move operation moved the page and I got unexpected data in the preprocessor.
Requirement:
I need to make sure the page is unpublished, then I need to execute the move operation. How to do that?
Environment: AMS




