Skip to content

Instantly share code, notes, and snippets.

@ahmed-musallam
Last active March 12, 2019 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmed-musallam/32a82ae4721771bd63811484c476695c to your computer and use it in GitHub Desktop.
Save ahmed-musallam/32a82ae4721771bd63811484c476695c to your computer and use it in GitHub Desktop.
/**
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