Finding SNS nodes

Find same name sibling(SNS) nodes

Before Jackrabbit Oak, it was possible to create same name sibling nodes(SNS) in CRX 2.

However, to upgrade to CRX 3 Oak, those nodes need to be removed.

To find those nodes, use the Groovy script below in Felix script console.

Once installed, the script console is available at /system/console/scriptconsole.

Don't forget to install the Groovy bundle after installing Script console.

The script logs the SNS nodes paths in a logger named sns that you need to create in the OSGI console.

properties of sns logger:

org.apache.sling.commons.log.pattern="{5}"
org.apache.sling.commons.log.names="sns"]
org.apache.sling.commons.log.file="logs/sns.log"
org.apache.sling.commons.log.level="debug"

Groovy script

def traverseAndLogSNS(node, session, log){
 if(node.index != 1) {
  log.info(node.path)
  //session.removeItem(node.path)
  return
 }
 if(node.hasNodes()) {
  def ni = node.nodes
  while(ni.hasNext()){
   traverseAndLogSNS(ni.nextNode(), session, log)
  }
 }
}

def repo = osgi.getService(org.apache.sling.jcr.api.SlingRepository)
def session = repo.loginAdministrative(null)
def root = session.getRootNode()
def log = org.slf4j.LoggerFactory.getLogger("sns")

traverseAndLogSNS(root, session, log)

session.save()
session.logout()

The script can be esily adapted to log only sns nodes under a certain path.

 Adobe

Krijg sneller en gemakkelijker hulp

Nieuwe gebruiker?

Adobe MAX 2024

Adobe MAX
De creativiteitsconferentie

14–16 oktober Miami Beach en online

Adobe MAX

De creativiteitsconferentie

14–16 oktober Miami Beach en online

Adobe MAX 2024

Adobe MAX
De creativiteitsconferentie

14–16 oktober Miami Beach en online

Adobe MAX

De creativiteitsconferentie

14–16 oktober Miami Beach en online