6
votes

I am trying to activate some pages from code. I have made a workflow that will modify a page whenever some content is modified in some other pages that have a reference to this page. I was trying to do this by setting properties of activation like:

parentpage.setProperty("cq:lastModified", Calendar.getInstance());
parentpage.setProperty("cq:lastModifiedBy", session.getUserID());

Although this property is getting set each time. But activation is not happening in the publish instance. How do we activate programmatic ally in custom workflow itself?

2

2 Answers

9
votes

Use Replicator OSGi service:

@Component
public class MyComponent {

    @Reference
    private Replicator replicator;

    private void activatePage(Session session) {
    //...
        replicator.replicate(session, ReplicationActionType.ACTIVATE, pathToPage);
    //...
    }
}

You don't need to set any properties.

0
votes

If you do not have the component then you can inject the service as -

Replicator replicator = getSling().getService(Replicator.class);