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