În upgrades/configure.zcml:
<genericsetup:upgradeStep
title="Upgrade my.addon to v3"
description="Update bla bla items"
source="2"
destination="3"
handler=".update.update_to_3"
profile="my.addon:default" />
În /profiles/default/metadata.xml:
<version>3</version>
În /upgrades/update.py:
def update_to_3(context):
logger.info("Upgrading to 3.")
catalog = portal.get_tool(name='portal_catalog')
query = {'portal_type': [
'my.contenttype.blabla',
'my.contenttype.foobar',
]}
results = catalog.searchResults(**query)
logger.info('Got %s results.' % len(results))
items_count = 0
for brain in results:
obj = brain.getObject()
if items_count % 100 == 0:
logger.info('Went through %s brains' % items_count)
items_count += 1
modified = False
if some_conditions:
new_value = "something"
modified = True
if modified is True:
logger.info('Updating %s' % obj.absolute_url())
logger.info("NEW VALUE %s" % new_value)
obj.blablafield = new_value
obj.reindexObject()
obj._p_changed = True
logger.info("Finished upgrade 3.")
Deschizi /@@overview-controlpanel, mergi la Add-ons, cauți my.addon, rulezi upgrade.
Sau: /manage_main, portal_setup, Upgrades (/portal_setup/manage_upgrades), selectezi profil, show old upgrades, selectezi, rulezi.