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