Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def isDryRun = true
- def SEARCH_PATH = "/content";
- def ATTRIBUTE_TO_REMOVE = 'adhocenable="false"';
- def PROPERTIES_TO_CHANGE = ["text", "details", "paragraph", "description", "richText", "paragraphDE", "footnote"];
- def COMPONENTS_TO_CHANGE = ["sapdx/components/modular/socialBox", "sapdx/components/modular/promo_50",
- "foundation/components/table", "sapdx/components/modular/columnIconHighlightBox",
- "sapdx/components/modular/carousel/item", "sapdx/components/modular/multiSocialBox",
- "sapdx/components/modular/fullWidthBanner", "sapdx/components/modular/bannerCenteredFullWidth",
- "sapdx/components/modular/developerDestinationText", "integratedreports/components/promoBox",
- "foundation/components/text", "sapdx/components/modular/promoBox",
- "sapdx/components/modular/comparisonTable", "sapdx/components/modular/heroCentered",
- "sapdx/components/modular/valueProp", "sapdx/components/modular/legalDisclosure",
- "sapdx/components/modular/columnIllustrationHighlightBox", "sapdx/components/modular/hero",
- "sapdx/components/modular/fullWidthPromo"];
- def queryTemplate = "/jcr:root${SEARCH_PATH}//*[@sling:resourceType and jcr:contains('{{propertyName}}', '$ATTRIBUTE_TO_REMOVE')]";
- def affectedNodes = [];
- def affectedProperties = [];
- PROPERTIES_TO_CHANGE.each { propName ->
- def query = queryTemplate.replace('{{propertyName}}', propName);
- def result = executeXPath(query);
- result.each { node ->
- def componentType = node.getProperty('sling:resourceType').getString();
- if (COMPONENTS_TO_CHANGE.contains(componentType)) {
- if (node.hasProperty(propName)) {
- def property = node.getProperty(propName);
- if (!property.isMultiple()) {
- def propertyValue = property.getString();
- if (propertyValue.contains(ATTRIBUTE_TO_REMOVE)) {
- affectedNodes.add(node);
- affectedProperties.add(property);
- }
- }
- }
- }
- }
- }
- println "** Affected properties:";
- affectedProperties.each { property ->
- def oldPropertyValue = property.getString();
- println property.getPath();
- def value = oldPropertyValue.replaceAll(" $ATTRIBUTE_TO_REMOVE", '');
- println "------------------------------"
- println "$oldPropertyValue\n->\n\n$value";
- println "------------------------------"
- if (!isDryRun) {
- property.setValue(value);
- }
- }
- println saveSession(isDryRun);
- println(printAffectedItems(affectedNodes));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement