March 17, 2020
Estimated Post Reading Time ~

Groovy Scripts

update-contexthub-path.txt

import com.day.cq.commons.jcr.JcrConstants
def oldContexthubPath =  "/etc/cloudsettings/default/contexthub"
def newContexthubPath = "/conf/your-project/settings/cloudsettings/default/contexthub"
def oldSegmentPath = "/etc/segmentation/contexthub"
def newSegmentPath = "/conf/we-retail/settings/wcm/segments"
def query = createXpathQuery(oldContexthubPath)
def result = query.execute()
println 'No Of Pages found :' + result.nodes.size();
result.nodes.each{node ->
    node.set('cq:contextHubPath', newContexthubPath)
    node.set('cq:contextHubSegmentsPath', newSegmentPath)
    println node.path
}
save() 
def createXpathQuery(oldContexthubPath) {
    def queryManager = session.workspace.queryManager
    def statement = "/jcr:root/content/your-project//*[@cq:contextHubPath ='"+oldContexthubPath+"']"
    def query = queryManager.createQuery(statement, "xpath")
    query
}

update-design-path.txt

import com.day.cq.commons.jcr.JcrConstants
def oldDesignPath =  "/etc/designs/your-project"
def newDesignPath = "/apps/settings/wcm/designs/your-project"
def query = createXpathQuery(oldDesignPath)
def result = query.execute()
println 'No Of Pages found :' + result.nodes.size();
result.nodes.each{node ->
    node.set('cq:designPath', newDesignPath)
    println node.path
}
save() 
def createXpathQuery(oldDesignPath) {
    def queryManager = session.workspace.queryManager
    def statement = "/jcr:root/content/your-project//*[@cq:designPath='"+oldDesignPath+"']"
    def query = queryManager.createQuery(statement, "xpath")
    query
}

update-rolloutconfigs-path.txt

import com.day.cq.commons.jcr.JcrConstants
def oldPath =  "/etc/msm/rolloutconfigs/default"
def newPath = ["/apps/msm/wcm/rolloutconfigs/default"]
def query = createXpathQuery(oldPath)
def result = query.execute()
println 'No Of Pages found :' + result.nodes.size();
result.nodes.each{node ->
    node.set('cq:rolloutConfigs', newPath)
    println node.path
}
save() 
def createXpathQuery(oldPath) {
    def queryManager = session.workspace.queryManager
    def statement = "/jcr:root/content/your-project//*[@cq:rolloutConfigs ='"+oldPath+"']"
    def query = queryManager.createQuery(statement, "xpath")
    query
}


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.