[1516] | 1 | import logging |
---|
[1515] | 2 | from Products.CMFCore.utils import getToolByName |
---|
[1519] | 3 | from Products.CMFCore.Expression import Expression |
---|
[1515] | 4 | |
---|
[1516] | 5 | logger = logging.getLogger('quintagroup.seoptimizer') |
---|
[1810] | 6 | FIX_PTYPES_DOMAIN = ['Document', 'File', 'News Item'] |
---|
[1516] | 7 | |
---|
| 8 | def migrationActions(site): |
---|
[1785] | 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 | |
---|
[1516] | 13 | for ptype in site.portal_types.objectValues(): |
---|
[1785] | 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) |
---|
[1516] | 21 | |
---|
[1515] | 22 | def 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+'/')): |
---|
[1516] | 32 | logger.log(logging.INFO, "Removed %s layer from %s skin." % (l, skinName)) |
---|
[1515] | 33 | continue |
---|
| 34 | new_path.append(l) |
---|
| 35 | skinstool.addSkinSelection(skinName, ','.join(new_path)) |
---|
| 36 | |
---|
| 37 | def 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']) |
---|
[1516] | 48 | logger.log(logging.INFO, "Deleted \"SEO Properties\" action for %s type." % ptype.id) |
---|
[1515] | 49 | |
---|
[1570] | 50 | def remove_configlets(context, conf_ids): |
---|
[1515] | 51 | """ Remove configlets. |
---|
| 52 | """ |
---|
| 53 | configTool = getToolByName(context, 'portal_controlpanel', None) |
---|
| 54 | if configTool: |
---|
| 55 | for id in conf_ids: |
---|
| 56 | configTool.unregisterConfiglet(id) |
---|
[1516] | 57 | logger.log(logging.INFO, "Unregistered \"%s\" configlet." % id) |
---|
[1515] | 58 | |
---|
[1810] | 59 | def 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 | |
---|
[1570] | 67 | def importVarious(context): |
---|
| 68 | """ Do customized installation. |
---|
| 69 | """ |
---|
| 70 | if context.readDataFile('seo_install.txt') is None: |
---|
| 71 | return |
---|
| 72 | |
---|
| 73 | def 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) |
---|
[1810] | 80 | changeDomain(site) |
---|
[1570] | 81 | |
---|
| 82 | def uninstall(context): |
---|
[1515] | 83 | """ Do customized uninstallation. |
---|
| 84 | """ |
---|
| 85 | if context.readDataFile('seo_uninstall.txt') is None: |
---|
| 86 | return |
---|
| 87 | site = context.getSite() |
---|
[1570] | 88 | removeSkin(site, 'quintagroup.seoptimizer' ) |
---|
| 89 | removeActions(site) |
---|
| 90 | remove_configlets(site, ('quintagroup.seoptimizer',)) |
---|