Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 2.76 KB | None | 0 0
  1. def isDryRun = true
  2.  
  3. def SEARCH_PATH = "/content";
  4. def ATTRIBUTE_TO_REMOVE = 'adhocenable="false"';
  5. def PROPERTIES_TO_CHANGE = ["text", "details", "paragraph", "description", "richText", "paragraphDE", "footnote"];
  6. def COMPONENTS_TO_CHANGE = ["sapdx/components/modular/socialBox", "sapdx/components/modular/promo_50",
  7.                             "foundation/components/table", "sapdx/components/modular/columnIconHighlightBox",
  8.                             "sapdx/components/modular/carousel/item", "sapdx/components/modular/multiSocialBox",
  9.                             "sapdx/components/modular/fullWidthBanner", "sapdx/components/modular/bannerCenteredFullWidth",
  10.                             "sapdx/components/modular/developerDestinationText", "integratedreports/components/promoBox",
  11.                             "foundation/components/text", "sapdx/components/modular/promoBox",
  12.                             "sapdx/components/modular/comparisonTable", "sapdx/components/modular/heroCentered",
  13.                             "sapdx/components/modular/valueProp", "sapdx/components/modular/legalDisclosure",
  14.                             "sapdx/components/modular/columnIllustrationHighlightBox", "sapdx/components/modular/hero",
  15.                             "sapdx/components/modular/fullWidthPromo"];
  16.  
  17.  
  18. def queryTemplate = "/jcr:root${SEARCH_PATH}//*[@sling:resourceType and jcr:contains('{{propertyName}}', '$ATTRIBUTE_TO_REMOVE')]";
  19. def affectedNodes = [];
  20. def affectedProperties = [];
  21.  
  22. PROPERTIES_TO_CHANGE.each { propName ->
  23.     def query = queryTemplate.replace('{{propertyName}}', propName);
  24.     def result = executeXPath(query);
  25.     result.each { node ->
  26.         def componentType = node.getProperty('sling:resourceType').getString();
  27.         if (COMPONENTS_TO_CHANGE.contains(componentType)) {
  28.             if (node.hasProperty(propName)) {
  29.                 def property = node.getProperty(propName);
  30.                 if (!property.isMultiple()) {
  31.                     def propertyValue = property.getString();
  32.                     if (propertyValue.contains(ATTRIBUTE_TO_REMOVE)) {
  33.                         affectedNodes.add(node);
  34.                         affectedProperties.add(property);
  35.                     }
  36.                 }
  37.             }
  38.         }
  39.     }
  40. }
  41.  
  42. println "** Affected properties:";
  43.  
  44. affectedProperties.each { property ->
  45.     def oldPropertyValue = property.getString();
  46.     println property.getPath();
  47.     def value = oldPropertyValue.replaceAll(" $ATTRIBUTE_TO_REMOVE", '');
  48.  
  49.     println "------------------------------"
  50.     println "$oldPropertyValue\n->\n\n$value";
  51.     println "------------------------------"
  52.  
  53.     if (!isDryRun) {
  54.         property.setValue(value);
  55.     }
  56. }
  57.  
  58. println saveSession(isDryRun);
  59. println(printAffectedItems(affectedNodes));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement