Back to index

plone3  3.1.7
__init__.py
Go to the documentation of this file.
00001 """Migration functions for ATContentTypes 1.2. These are called during the
00002    usual CMFPlone migration.
00003 """
00004 import transaction
00005 
00006 from Acquisition import aq_base
00007 
00008 from Products.ATContentTypes.config import TOOLNAME
00009 from Products.ATContentTypes.tool.atct import ATCTTool
00010 from Products.CMFCore.utils import getToolByName
00011 
00012 def upgradeATCTTool(portal, out):
00013     tool = getToolByName(portal, TOOLNAME, None)
00014     if not hasattr(aq_base(tool), '_version'):
00015         # the tool already has been upgraded
00016         return
00017     # First we get all relevant old configuration and make sure we get
00018     # real copies of the various objects
00019     old_conf = {}
00020     old_conf['album_batch_size'] = int(getattr(tool, 'album_batch_size', 30))
00021     old_conf['album_image_scale'] = str(getattr(tool, 'album_image_scale', 'thumb'))
00022     old_conf['image_types'] = list(getattr(tool, 'image_types', ['Image', 'News Item']))
00023     old_conf['folder_types'] = list(getattr(tool, 'folder_types', ['Image']))
00024     old_conf['single_image_scale'] = str(getattr(tool, 'single_image_scale', 'preview'))
00025     old_conf['topic_indexes'] = tool.topic_indexes.copy()
00026     old_conf['topic_metadata'] = tool.topic_metadata.copy()
00027     old_conf['allowed_portal_types'] = tuple(tool.allowed_portal_types)
00028     
00029     # Remove the old tool completely
00030     del(tool)
00031     portal._delObject(TOOLNAME)
00032     transaction.savepoint(optimistic=True)
00033     
00034     # Create new tool
00035     portal._setObject(TOOLNAME, ATCTTool())
00036     tool = portal.get(TOOLNAME)
00037     # And apply the configuration again
00038     tool._setPropValue('album_batch_size', old_conf['album_batch_size'])
00039     tool._setPropValue('album_image_scale', old_conf['album_image_scale'])
00040     tool._setPropValue('image_types', tuple(old_conf['image_types']))
00041     tool._setPropValue('folder_types', tuple(old_conf['folder_types']))
00042     tool._setPropValue('single_image_scale', old_conf['single_image_scale'])
00043     tool._setPropValue('allowed_portal_types', old_conf['allowed_portal_types'])
00044 
00045     # XXX Index and metadata should be updated instead of being reapplied
00046     tool._setPropValue('topic_indexes', old_conf['topic_indexes'])
00047     tool._setPropValue('topic_metadata', old_conf['topic_metadata'])
00048 
00049     transaction.savepoint(optimistic=True)
00050     
00051     out.append('Upgraded the ATContentTypes tool.')