Last active
March 12, 2019 05:48
-
-
Save ahmed-musallam/32a82ae4721771bd63811484c476695c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Decodes asset names if they contain any encoded chars. | |
*/ | |
import java.net.URLDecoder | |
START = "/content/dam" | |
// renames a node | |
def renameToDecoded(node) | |
{ | |
existingName = node.getName() | |
decodedName = URLDecoder.decode(existingName, "UTF-8") | |
// decoded name is not the same as the encoded one. | |
if (!existingName.equals(decodedName)) { | |
existingPath = node.getPath() | |
parentPath = node.getParent().getPath() | |
newPath = parentPath + "/" + decodedName | |
node.getSession().move(existingPath, newPath); | |
println "renamed \"${node.getName()}\" to \"${decodedName}\" at path ${parentPath}" | |
// you could always save session in batches.. This way is slower, but will save one by one untill it fails. | |
node.getSession().save(); | |
} | |
} | |
getNode(START).recurse{ | |
if(it.isNodeType("dam:Asset")) { | |
renameToDecoded(it) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment