How to force all your old content into the new 'normalized-id-format'

by Sidnei da Silva last modified Dec 30, 2008 03:03 PM
Sometimes, when you migrate an old website, you might want to forcefully rename your old objects

Here's a simple script you can use.

  1. Create a 'Script (Python)'
  2. Paste this in there:
stuff = []
u = context.plone_utils
for r in context.portal_catalog(path='/path/to/content'):
  stuff.append(r.getPath())


stuff.sort()
stuff.reverse()

for f in stuff:
   parts = f.split('/')
   parent, fname = parts[:-1], parts[-1]
   fname, normalized = fname, u.normalizeString(fname)
   if fname != normalized:
      p = context.restrictedTraverse(parent)
      p.manage_renameObjects(ids=[fname], new_ids=[normalized])
      print fname, normalized

print 'done'
return printed

 

Now, run the script and have fun! :)