vangheem
vangheem

Reputation: 3293

How do you migrate an unordered folder to an ordered in Plone

I have a folder content type that derives from ATBTreeFolder which in plone 4(actually in Products.Archetypes) sets the ordering to "unordered".

If I go ahead and set the ordering to be ordered, which is just an empty string, the folder is confused and doesn't show me the contents of the folder. In fact, I'll get error like this:

  File "buildout-cache/eggs/plone.folder-1.0.1-py2.6.egg/plone/folder/default.py", line 130, in getObjectPosition
    raise ValueError('No object with id "%s" exists.' % id)
ValueError: No object with id "someid" exists.

I assume there is some migration that is required to be run to have ordering set on a folder that is originally unordered but I could not find anything available for that sort of situation in plone.app.folder and plone.folder.

Upvotes: 2

Views: 251

Answers (1)

vangheem
vangheem

Reputation: 3293

I have written an upgrade script that seems to solve the problem:

catalog = getToolByName(context, 'portal_catalog')
for brain in catalog(portal_type='MyType'):
    obj = brain.getObject()
    if obj._ordering == 'unordered':
        obj.setOrdering(u'')
    order = obj.getOrdering()
    for id in obj._tree:
        if id not in order._order():
            order.notifyAdded(id)

Upvotes: 5

Related Questions