Skip to content

Instantly share code, notes, and snippets.

@rah003
Last active November 16, 2015 09:50
Show Gist options
  • Save rah003/2cb0110d94a99d4e4832 to your computer and use it in GitHub Desktop.
Save rah003/2cb0110d94a99d4e4832 to your computer and use it in GitHub Desktop.
List all components used in specified page and all it's subpages
import info.magnolia.repository.RepositoryConstants
import javax.jcr.Node
import info.magnolia.jcr.util.NodeUtil
import org.apache.commons.lang.StringUtils
import info.magnolia.cms.util.QueryUtil
website = ctx.getJCRSession("website")
listComponents(website.getNode("/some-path"))
def listComponents(node) {
pages = NodeUtil.getNodes(node, "mgnl:page")
for (Node page : pages) {
if (page.hasProperty("mgnl:template")) {
path = page.getPath().trim()
title = page.getProperty("title").getString()
println("Page:" + title + ", with path:" + path)
components = QueryUtil.search(RepositoryConstants.WEBSITE, "select * from [mgnl:component] where ISDESCENDANTNODE(["+path+"])")
for (Node component : components) {
println (" " + component.getProperty("mgnl:template").string + ", at " + component.path)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment