2
votes

In AEM content hierarchy, I have a folder in which I have 4000 pages. And out of these pages, 3700 pages are following the naming convention of xyz-1, xyz-2, xyz-3..uptill xyz-3700 like this. I have a requirement to delete these pages starting with xyz but not the other 300 pages which have different names. I have tried below command with *, but this doesn’t work. Can anybody help me here to get this resolved?

curl  -F":operation=delete" -F":applyTo=/content/foo/bar/xyz*" http://localhost:4502 -u admin:admin

1

1 Answers

2
votes

Curl Needs a full path to execute the statement. You can pass individual paths like below, but it will not solve your issue as you have a lot of pages

curl -u admin:admin -F":operation=delete" -F":applyTo=/content/aem-flash/en/xyz-1" -F":applyTo=/content/aem-flash/en/xyz-2" http://localhost:4502

You have to write a script to delete all of them. There are multiple options, you can either write a standalone code and deploy as a bundle or connect from Eclipse

If you do not want to deploy a bundle, you can use groovy script to execute your code.

Below Groovy script should work for your requirement if all the pages are in the same parent node. If you would like to query the whole site, please update the query accordingly

import javax.jcr.Node

def buildQuery(page) {
    def queryManager = session.workspace.queryManager;
    def statement = 'select * from cq:Page where jcr:path like \''+page.path+'/xyz-%\'';
    queryManager.createQuery(statement, 'sql');
}

final def page = getPage('/content/aem-flash/en/')
final def query = buildQuery(page);
final def result = query.execute()

result.nodes.each { node ->
println 'node path is: ' + node.path
node.remove();
session.save();
}


Solution with CURL

I found another way to use CURL command alone but it sends multiple requests to the server and might not be good.

The below command makes 4000 requests even the record is not present in the environment, it's just like a loop.

As regex is not supported by default in Windows, this will not work in a command prompt. It should work fine in a linux environment. If you want this to be executed in Windows, you can use Git bash console or other tools. I have tried in Git Bash and it worked fine.

curl -X DELETE "http://localhost:4502/content/aem-flash/en/xyz-[0-4000]" -u admin:admin