Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Best way to remove component references in pages

Avatar

Level 2

Hi,

We have a component that needs to be removed but there are almost 100+ pages referencing the component, what is the best way to remove the component references from all those pages?

 

AEM 6.4.6.0

 

Thanks,

Prabu

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 1

From querydebug all the paths of pages containing component reference can be fetched, Below is the sample query-

path=/content
1_property=sling:resourceType
1_property.value=<path/of/the/component>
1_property.operation=like

 

Create a servlet/scheduler 

-hit the path

-get the resource

-iterate over its nodes

-delete the component node

-save the session.

 

 

 

View solution in original post

4 Replies

Avatar

Correct answer by
Level 1

From querydebug all the paths of pages containing component reference can be fetched, Below is the sample query-

path=/content
1_property=sling:resourceType
1_property.value=<path/of/the/component>
1_property.operation=like

 

Create a servlet/scheduler 

-hit the path

-get the resource

-iterate over its nodes

-delete the component node

-save the session.

 

 

 

Avatar

Level 2
Thanks gaurav and everyone for the response. I was thinking if there is any 3rd party modules (like acs-commons) available to leverage it. Sounds like we have to come up on our own. Thanks

Avatar

Community Advisor

I would write a servlet , query the pages with component reference and remove the component via servlet. The steps would be pretty much same as what @gaurav3415  mentioned above. 

Avatar

Community Advisor

By creating a servlet using JCR_SQL2. The servlet will query all the pages for any pages that have the existing component's "sling:resourceType", and delete the node using the session object. Please vigorously test this in Dev, QA, Staging, before calling from Prod.