Best way to remove component references in pages | Community
Skip to main content
Level 2
May 8, 2020
Solved

Best way to remove component references in pages

  • May 8, 2020
  • 3 replies
  • 5102 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by gaurav3415

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.

 

 

 

3 replies

gaurav3415Accepted solution
May 8, 2020

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.

 

 

 

pharidosAuthor
Level 2
May 8, 2020
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
VeenaVikraman
Community Advisor
Community Advisor
May 8, 2020

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. 

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 8, 2020

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.