source: products/quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/setuphandlers.py @ 1519

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

Added mirgation actions in content type

File size: 3.3 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    old = 'qseo_properties_edit_form'
9    new = '@@seo-context-properties'
10    condition = "python:exists('portal/@@seo-context-properties')"
11    seo_props = site.portal_properties.seo_properties
12    content_types_seoprops_enabled = list(seo_props.getProperty('content_types_seoprops_enabled'))
13    for ptype in site.portal_types.objectValues():
14        acts = filter(lambda x: x.id == 'seo_properties' , ptype.listActions())
15        for act in acts:
16            log = 0
17            if ptype.id not in content_types_seoprops_enabled:
18                content_types_seoprops_enabled.append(ptype.id)
19            if not act.condition:
20                act.condition = Expression(condition)
21                log = 1
22            ac_exp = act.getActionExpression()
23            if old in ac_exp:
24                act.setActionExpression(ac_exp.replace(old, new))
25                log = 1
26            if log:
27                logger.log(logging.INFO, "Updated \"SEO Properties\" action in %s type." % ptype.id)
28    seo_props.manage_changeProperties(content_types_seoprops_enabled=tuple(content_types_seoprops_enabled))
29
30
31def importVarious(context):
32    """ Do customized installation.
33    """
34    if context.readDataFile('seo_install.txt') is None:
35        return
36    site = context.getSite()
37    migrationActions(site)
38
39def removeSkin(self, layer):
40    """ Remove layers.
41    """
42    skinstool = getToolByName(self, 'portal_skins')
43    for skinName in skinstool.getSkinSelections():
44        original_path = skinstool.getSkinPath(skinName)
45        original_path = [l.strip() for l in original_path.split(',')]
46        new_path= []
47        for l in original_path:
48            if (l == layer) or (l.startswith(layer+'/')):
49                logger.log(logging.INFO, "Removed %s layer from %s skin." % (l, skinName))
50                continue
51            new_path.append(l)
52        skinstool.addSkinSelection(skinName, ','.join(new_path))
53
54def removeActions(self):
55    """ Remove actions.
56    """
57    tool = getToolByName(self, 'portal_types')
58    for ptype in tool.objectValues():
59        if ptype.getId() in ['File','Document','News Item']:
60            acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions())
61            action = acts and acts[0] or None
62            if action != None:
63                acts = list(ptype.listActions())
64                ptype.deleteActions([acts.index(a) for a in acts if a.getId()=='seo_properties'])
65                logger.log(logging.INFO, "Deleted \"SEO Properties\" action for %s type." % ptype.id)
66
67def remove_configlets( context, conf_ids ):
68    """ Remove configlets.
69    """
70    configTool = getToolByName(context, 'portal_controlpanel', None)
71    if configTool:
72        for id in conf_ids:
73            configTool.unregisterConfiglet(id)
74            logger.log(logging.INFO, "Unregistered \"%s\" configlet." % id)
75
76def uninstall( context ):
77    """ Do customized uninstallation.
78    """
79    if context.readDataFile('seo_uninstall.txt') is None:
80        return
81    site = context.getSite()
82    removeSkin( site, 'quintagroup.seoptimizer' )
83    removeActions( site )
84    remove_configlets( site, ('quintagroup.seoptimizer',))
Note: See TracBrowser for help on using the repository browser.