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
Views
Replies
Total Likes
Hi @Sady_Rifat ,
You can write a EventHandler and register the handler for Replication deactivation. Once the replication deactivation triggers from your OSGI service and once the replication agent deactivates the content then your event handler will execute. Here in the handler you can do page move operation.
Thanks
Ramesh
Views
Replies
Total Likes
Hello @Uppari_Ramesh, yes I already have replicationAction in my codebase that I already mentioned.
But I need to only move some specific pages based on condition.
for example, if I write the move operation in replicationAction then, if an Author unpublish any page, it will be moved.
Views
Replies
Total Likes
Hi @Sady_Rifat You can even validate the specific condition in Event handler OR if you have path based validation then you define the handler with filter of paths as well. You will get the page path in handler and do your validation and based on that move pages.
Views
Replies
Total Likes
Hi @Sady_Rifat
I think If the page was published before the move, the old path is automatically unpublished. Can you try just move method from PageManager Interface
Views
Replies
Total Likes
@arunpatidar actually I am working with Unpublish a page via pageManger API.
Views
Replies
Total Likes
Hi @Sady_Rifat
After you initiated the deactivation, there is no feedback to know when the system actually finished. What you can do instead is to create and start an ad-hoc Sling job that monitors the page path and checks in loop the value of cq:lastReplicationAction property until it changes from Activate to Deactivate.
This is a nice article on how to use Sling Jobs in case you haven't so far: https://medium.com/@toimrank/aem-sling-jobs-c4ebbb849d68
And in order to control the number of retries and teh delay between two retries (I believe you will need to set this based on your guts, on how much time usually takes for a page to get deativated by your system), you will need to set these two properties for the job: event.job.retrydelay and event.job.retries.
More about these properties in here https://github.com/apache/sling-org-apache-sling-event-api/blob/master/src/main/java/org/apache/slin...
That's a good way, let me try.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Like
Replies