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

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

Added reinstall method: migrate actions from portal_types to portal_actions

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