Hi,
I am trying to delete all the pages which does not have any child pages in the certain path in AEM . Can someone please tell me how i can achieve this through Node/Page API?
Thanks for your replies!
Solved! Go to Solution.
Here is a good link that will give you some ideas of using JCR SQLs to query for pages.
http://labs.6dglobal.com/blog/2014-10-07/9-jcr-sql-2-queries-every-aem-dev-should-know/
You have to write a query to get all AEM pages (type of
JCR PageManager API : https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/wcm/api/PageManager.html
Jitendra
Here is a good link that will give you some ideas of using JCR SQLs to query for pages.
http://labs.6dglobal.com/blog/2014-10-07/9-jcr-sql-2-queries-every-aem-dev-should-know/
Query to get all the pages
Select * from [cq:Page] As a where isdescendantnode (s,'/content')
once you have the list of pages, loop through the list of Nodes and check
if (node.hasNodes()) and run the above query again with the current resourcepath as the path
Select * from [cq:Page] As a where isdescendantnode (s,'<resourcePath>')
if the resultlist is > 0, then it would have the child page nodes and then use the PageManager API to delete the same
import com.day.cq.wcm.api.PageManager; ResourceResolver resolver = <Get instance of resource resolver> <If you have request object then request.getResourceResolver()> PageManager pm = resolver.adaptTo(PageManager.class); pm.delete(Resource pagepath, boolean false, boolean true) throws WCMException
** This is to just give you an idea... and not the actualy code
Hi,
given the huge amount of cq:Page nodes below /content I wouldn't do it with JCR query. Just use a recursive algorithm to find all cq:Pages with the given criteria and execute the action. Should be enough and probably faster the doing queries.
Jörg
You can do recursive call using node.getChildren and repeat for each child and remove if it doesnt have any children.
You can further check if it is page node and delete.
Note : To persist a removal, a save
must be performed that includes the (former) parent of the removed item within its scope.
Views
Replies
Total Likes
Your whole requirement is very confusing, specially " I need to delete all the parents that don't have this property. ".
I am not sure how can you do so. However, if you want to remove all the pages with some property (e.g. property1), do the query to get a list of pages & then you can remove one by one.
Jitendra
yes.. it can be your logic to find which page node to delete. However, you will have to traverse using the APIs and based on your condition you can perform the actions.
Regards,
bsloki
Views
Replies
Total Likes