source: products/quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/setuphandlers.py @ 1815

Last change on this file since 1815 was 1810, checked in by liebster, 14 years ago

Fixes old versions bug: Change of content type's domain to 'plone'

File size: 3.5 KB
Line 
1import logging
2from Products.CMFCore.utils import getToolByName
3from Products.CMFCore.Expression import Expression
4
5logger = logging.getLogger('quintagroup.seoptimizer')
6FIX_PTYPES_DOMAIN = ['Document', 'File', 'News Item']
7
8def migrationActions(site):
9    p_props = getToolByName(site, 'portal_properties')
10    seo_props = getToolByName(p_props, 'seo_properties')
11    ctws = list(seo_props.getProperty('content_types_with_seoproperties', []))
12
13    for ptype in site.portal_types.objectValues():
14        for idx, act in enumerate(ptype.listActions()):
15            if act.id == 'seo_properties':
16                if  ptype.id not in ctws:
17                    ctws.append(ptype.id)
18                ptype.deleteActions([idx])
19                logger.log(logging.INFO, "Moved \"SEO Properties\" action from %s type in portal actions." % ptype.id)
20    seo_props.manage_changeProperties(content_types_with_seoproperties=ctws)
21
22def removeSkin(self, layer):
23    """ Remove layers.
24    """
25    skinstool = getToolByName(self, 'portal_skins')
26    for skinName in skinstool.getSkinSelections():
27        original_path = skinstool.getSkinPath(skinName)
28        original_path = [l.strip() for l in original_path.split(',')]
29        new_path= []
30        for l in original_path:
31            if (l == layer) or (l.startswith(layer+'/')):
32                logger.log(logging.INFO, "Removed %s layer from %s skin." % (l, skinName))
33                continue
34            new_path.append(l)
35        skinstool.addSkinSelection(skinName, ','.join(new_path))
36
37def removeActions(self):
38    """ Remove actions.
39    """
40    tool = getToolByName(self, 'portal_types')
41    for ptype in tool.objectValues():
42        if ptype.getId() in ['File','Document','News Item']:
43            acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions())
44            action = acts and acts[0] or None
45            if action != None:
46                acts = list(ptype.listActions())
47                ptype.deleteActions([acts.index(a) for a in acts if a.getId()=='seo_properties'])
48                logger.log(logging.INFO, "Deleted \"SEO Properties\" action for %s type." % ptype.id)
49
50def remove_configlets(context, conf_ids):
51    """ Remove configlets.
52    """
53    configTool = getToolByName(context, 'portal_controlpanel', None)
54    if configTool:
55        for id in conf_ids:
56            configTool.unregisterConfiglet(id)
57            logger.log(logging.INFO, "Unregistered \"%s\" configlet." % id)
58
59def changeDomain(site):
60    """ Fixes old versions bug: Change of content type's domain to 'plone'.
61    """
62    for ptype in [ptypes for ptypes in site.portal_types.objectValues() if ptypes.id in FIX_PTYPES_DOMAIN]:
63        if ptype.i18n_domain == 'quintagroup.seoptimizer':
64            ptype.i18n_domain = 'plone'
65            logger.log(logging.INFO, "I18n Domain of the type \'%s\' changed to \'plone\'." % ptype.id)
66
67def importVarious(context):
68    """ Do customized installation.
69    """
70    if context.readDataFile('seo_install.txt') is None:
71        return
72
73def reinstall(context):
74    """ Do customized reinstallation.
75    """
76    if context.readDataFile('seo_reinstall.txt') is None:
77        return
78    site = context.getSite()
79    migrationActions(site)
80    changeDomain(site)
81
82def uninstall(context):
83    """ Do customized uninstallation.
84    """
85    if context.readDataFile('seo_uninstall.txt') is None:
86        return
87    site = context.getSite()
88    removeSkin(site, 'quintagroup.seoptimizer' )
89    removeActions(site)
90    remove_configlets(site, ('quintagroup.seoptimizer',))
Note: See TracBrowser for help on using the repository browser.