Created
January 30, 2017 23:19
-
-
Save alexkli/1efcd4f3f7bb36801229e282fa0d2f55 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import org.apache.jackrabbit.oak.spi.commit.CommitInfo | |
import org.apache.jackrabbit.oak.spi.commit.EmptyHook | |
import org.apache.jackrabbit.oak.spi.state.NodeStore | |
import org.apache.jackrabbit.oak.commons.PathUtils | |
def removeNodes(def session, String fileWithPaths) { | |
println "Reading paths from ${fileWithPaths}..." | |
new File(fileWithPaths).eachLine { path -> | |
println "Removing node ${path}" | |
NodeStore ns = session.store | |
def nb = ns.root.builder() | |
def aBuilder = nb | |
for(p in PathUtils.elements(path)) { aBuilder = aBuilder.getChildNode(p) } | |
if(aBuilder.exists()) { | |
aBuilder.remove() | |
ns.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY) | |
} else { | |
println "Node ${path} doesn't exist" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same as rmNode() script but allows to delete multiple paths in one go.
Uses a file with multiple paths as input, which might have been created using childCount.groovy and paths filtered out using
Run in oak-run console with