Hi All,
I have two tags
duplicate tag: Anish: atlas-copco:industrial-tools/expert-hub/industries/industrial_assembly
original tag: Dan: atlas-copco:industrial-tools/expert-hub/industries/industrial-assembly.
I want to replace duplicate tag with original tag, so I merged duplicate tag into original tag.
Actually duplicate tag has total references 230(including pages&aasets)
After merging the original tag should contain all the references of duplicate tag.
But duplicate tag has total refernces 230 as like earlier.
Can anyone help me.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @Vani1012,
Answering the question, why merge operation is not replacing references in cq:tags or other properties. Well according to the documentation, this is how it was designed. You can check all the details under Adobe documentation:
To solve your problem you can use groovy console and groovy script. Below is an example, that should help you. Simply replace new and old tags values as well as query in the script using your values.
import javax.jcr.query.Query
OLD_TAG_VALUE = "we-retail:tag-a"
NEW_TAG_VALUE = "we-retail:tag-b"
QUERY = """SELECT * FROM [cq:PageContent] AS page
WHERE ISDESCENDANTNODE([/content/we-retail/language-masters/en])
AND page.[cq:tags] = 'we-retail:tag-a'"""
resourceResolver.findResources(QUERY, Query.JCR_SQL2).each { resource ->
def mvm = resource.adaptTo(ModifiableValueMap)
if (mvm) {
println "Updating $resource.path"
def tags = null
if (mvm.get("cq:tags").getClass().isArray()) {
// support array property
tags = mvm.get("cq:tags", String[])
tagsList = tags as List
Collections.replaceAll(tagsList, OLD_TAG_VALUE, NEW_TAG_VALUE)
tags = tagsList as String[]
} else {
tags = mvm.get("cq:tags", String)
tags = NEW_TAG_VALUE
}
mvm.put("cq:tags", tags)
// saving changes
resourceResolver.commit()
}
}
Hi @Vani1012
To update the original tag in all the references you can use AEM Bulk Editor capability, which can be found at http://localhost:4502/etc/importers/bulkeditor.html
here you can search for assets and pages, export the data in tsv file and edit the tags (find and replace), import back edited tsv file.
Please refer https://www.youtube.com/watch?v=DVWqAD842ac
Hope this helps!
Thanks
@Gaurav_Sachdeva_ The bulk editor isn't showing the correct results
I retriwed list of pages under "/content/languagemasters" which has the tag "atlas-copco:industrial-tools/expert-hub/industries/industrial_assembly".
I have used SQL query and It gave 61 results
SELECT * FROM [cq:PageContent] AS page
WHERE ISDESCENDANTNODE([/content/languagemasters])
AND page.[cq:tags] = 'atlas-copco:industrial-tools/expert-hub/industries/industrial_assembly'
I used bulk editor and configured like this
Root path: /content/languagemasters
query parametrs: "cq:tags": atlas-copco:industrial-tools/expert-hub/industries/industrial_assembly
It given result as 5609
Bulk editor isnt giving correct result.
Why after merging tags the reference pages cq:tag isnt updated
Please Help me here.
I am not sure why bulk editor is not giving correct result.
Another solution I can think of is run a search query and create a list of paths which has this tag.
Add this data in tsv file.
Find and replace this tag.
then upload it in bulk editor.
Hi @Vani1012,
Answering the question, why merge operation is not replacing references in cq:tags or other properties. Well according to the documentation, this is how it was designed. You can check all the details under Adobe documentation:
To solve your problem you can use groovy console and groovy script. Below is an example, that should help you. Simply replace new and old tags values as well as query in the script using your values.
import javax.jcr.query.Query
OLD_TAG_VALUE = "we-retail:tag-a"
NEW_TAG_VALUE = "we-retail:tag-b"
QUERY = """SELECT * FROM [cq:PageContent] AS page
WHERE ISDESCENDANTNODE([/content/we-retail/language-masters/en])
AND page.[cq:tags] = 'we-retail:tag-a'"""
resourceResolver.findResources(QUERY, Query.JCR_SQL2).each { resource ->
def mvm = resource.adaptTo(ModifiableValueMap)
if (mvm) {
println "Updating $resource.path"
def tags = null
if (mvm.get("cq:tags").getClass().isArray()) {
// support array property
tags = mvm.get("cq:tags", String[])
tagsList = tags as List
Collections.replaceAll(tagsList, OLD_TAG_VALUE, NEW_TAG_VALUE)
tags = tagsList as String[]
} else {
tags = mvm.get("cq:tags", String)
tags = NEW_TAG_VALUE
}
mvm.put("cq:tags", tags)
// saving changes
resourceResolver.commit()
}
}
@Vani1012 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Like
Replies