如何sling:resourceType使用Query和Scipt批量替换值.
例如,我想将sling:resourceType值更改app/component/linkButton为app/component/content/linkbutton1.
该组件正在20页上使用,我希望使用查询而不是在每个页面上手动更改它.
最好的选择是groovy控制台.
完成这项工作的Bellow脚本:
import javax.jcr.Node
getNode('/content/').recurse { resourceNode ->
if (resourceNode.hasProperty('sling:resourceType')) {
final def resourceType = resourceNode.getProperty('sling:resourceType').string
if (resourceType.equals('OLD_RESOURCE_TYPE')) {
println "changing " + resourceNode.path
resourceNode.setProperty('sling:resourceType', 'NEW_RESOURCE_TYPE')
resourceNode.save();
}
}
}
Run Code Online (Sandbox Code Playgroud)