Last active
February 9, 2018 02:05
-
-
Save jkan997/8f16b678ee37f23eb6e8 to your computer and use it in GitHub Desktop.
AEM - Replicate Resource and entire child tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var workflowData = workItem.getWorkflowData(); | |
var jcrSession = workflowSession.getSession(); | |
// Resource resolver | |
var resourceResolverFactory = sling.getService(Packages.org.apache.sling.api.resource.ResourceResolverFactory); | |
var authInfo = new Packages.java.util.HashMap(); | |
authInfo.put("user.jcr.session", jcrSession); | |
var resourceResolver = resourceResolverFactory.getResourceResolver(authInfo); | |
// Replicator | |
var replicator = sling.getService(Packages.com.day.cq.replication.Replicator); | |
var replicationOpts = new Packages.com.day.cq.replication.ReplicationOptions(); | |
var workflowData = workItem.getWorkflowData(); | |
var payloadPath = workflowData.getPayload().toString(); | |
var mainResource = resourceResolver.getResource(payloadPath); | |
function replicate(res) { | |
var resPath = res.getPath(); | |
log.debug("Activating " + resPath); | |
replicator.replicate(jcrSession, Packages.com.day.cq.replication.ReplicationActionType.ACTIVATE, resPath, replicationOpts); | |
var childIt = resourceResolver.listChildren(res); | |
while (childIt.hasNext()) { | |
var childResource = childIt.next(); | |
replicate(childResource); | |
} | |
} | |
replicate(mainResource); |
thank you very much. I just need it .
Wonderful. Thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just remember to change extension to .ecma in AEM