Back to index

plone3  3.1.7
two11_two12.py
Go to the documentation of this file.
00001 import string
00002 from Products.CMFCore.ActionInformation import Action
00003 from Products.CMFCore.utils import getToolByName
00004 from Products.CMFCore.permissions import AddPortalContent
00005 from Products.CMFPlone.migrations.migration_util import safeGetMemberDataTool, \
00006      safeEditProperty
00007 from Products.CMFPlone.migrations.v3_0.alphas import migrateOldActions
00008 from Products.CMFPlone.migrations.v3_0.alphas import enableZope3Site
00009 from Products.CMFPlone.migrations.v3_0.alphas import registerToolsAsUtilities
00010 
00011 
00012 def two11_two12rc1(portal):
00013     """2.1.1 -> 2.1.2-rc1
00014     """
00015     out = []
00016 
00017     # Make the portal a Zope3 site
00018     enableZope3Site(portal, out)
00019 
00020     # register some tools as utilities
00021     registerToolsAsUtilities(portal, out)
00022 
00023     # Remove plone_3rdParty\CMFTopic from skin layers
00024     removeCMFTopicSkinLayer(portal, out)
00025 
00026 
00027     # We need to migrate all existing actions to new-style actions first
00028     migrateOldActions(portal, out)
00029     # Add rename object action
00030     addRenameObjectButton(portal, out)
00031 
00032     # add se-highlight.js (plone_3rdParty) to ResourceRegistries
00033     addSEHighLightJS(portal, out)
00034     
00035     # Don't let Discussion item have a workflow
00036     removeDiscussionItemWorkflow(portal, out)
00037 
00038     # Add new member data item
00039     addMemberData(portal, out)
00040 
00041     return out
00042 
00043 
00044 def two12rc2_two12(portal):
00045     """2.1.2-rc2 -> 2.1.2
00046     """
00047     out = []
00048 
00049     # Make the portal a Zope3 site
00050     enableZope3Site(portal, out)
00051 
00052     # register some tools as utilities
00053     registerToolsAsUtilities(portal, out)
00054 
00055     # Reinstall PortalTransforms to activate the
00056     # configurable safe_html transformation.
00057     reinstallPortalTransforms(portal, out)
00058 
00059     return out
00060 
00061 
00062 def removeCMFTopicSkinLayer(portal, out):
00063     """Removes plone_3rdParty\CMFTopic layer from all skins."""
00064 
00065     st = getToolByName(portal, 'portal_skins', None)
00066     if st is not None:
00067         old = 'plone_3rdParty/CMFTopic'
00068         skins = st.getSkinSelections()
00069         for skin in skins:
00070             path = st.getSkinPath(skin)
00071             path = map(string.strip, string.split(path,','))
00072             if old in path:
00073                 path.remove(old)
00074             st.addSkinSelection(skin, ','.join(path))
00075         out.append("Removed plone_3rdParty\CMFTopic layer from all skins.")
00076 
00077 
00078 def addRenameObjectButton(portal,out):
00079     """Add the missing rename action for renaming single content items.
00080     """
00081     actionsTool = getToolByName(portal, 'portal_actions', None)
00082     if actionsTool is not None:
00083         category = actionsTool.object_buttons
00084         for action in category.objectIds():
00085             # if action exists, remove and re-add
00086             if action == 'rename':
00087                 category._delObject('rename')
00088                 out.append("Removed rename contentmenu action from actions tool.")
00089                 break
00090 
00091         rename = Action('rename',
00092             title='Rename',
00093             i18n_domain='plone',
00094             url_expr='python:"%s/object_rename"%(object.isDefaultPageInFolder() and object.getParentNode().absolute_url() or object_url)',
00095             available_expr='python:portal.portal_membership.checkPermission("Delete objects", object.aq_inner.getParentNode()) and portal.portal_membership.checkPermission("Copy or Move", object) and portal.portal_membership.checkPermission("Add portal content", object) and object is not portal and not (object.isDefaultPageInFolder() and object.getParentNode() is portal)',
00096             permissions=(AddPortalContent,),
00097             visible=True)
00098 
00099         category['rename'] = rename
00100         out.append("Added rename contentmenu action to actions tool.")
00101 
00102 
00103 def addSEHighLightJS(portal, out):
00104     """Add se-highlight.js (plone_3rdParty) to ResourceRegistries.
00105     """
00106     jsreg = getToolByName(portal, 'portal_javascripts', None)
00107     script = 'se-highlight.js'
00108     if jsreg is not None:
00109         script_ids = jsreg.getResourceIds()
00110         # Failsafe: first make sure the stylesheet doesn't exist in the list
00111         if script not in script_ids:
00112             jsreg.registerScript(script)
00113             try:
00114                 jsreg.moveResourceAfter(script, 'highlightsearchterms.js')
00115             except ValueError:
00116                 # put it at the bottom of the stack
00117                 jsreg.moveResourceToBottom(script)
00118             out.append("Added " + script + " to portal_javascipt")
00119 
00120 
00121 def removeDiscussionItemWorkflow(portal, out):
00122     """Discussion Item should not have a workflow associated with it, since
00123     it may then have permissions out-of-sync with the parent.
00124     """
00125     wftool = getToolByName(portal, 'portal_workflow', None)
00126     if wftool is not None:
00127         wftool.setChainForPortalTypes(('Discussion Item',), ())
00128         out.append("Removing workflow from Discussion Item")
00129 
00130 
00131 def addMemberData(portal, out):
00132     """Add the must_change_password property to member data"""
00133     mt = safeGetMemberDataTool(portal)
00134     if mt is not None:
00135         safeEditProperty(mt, 'must_change_password', 0, 'boolean')
00136         out.append('Added must_change_password property to member data')
00137 
00138 
00139 def reinstallPortalTransforms(portal, out):
00140     """Reinstalls PortalTransforms."""
00141     reinstall = False
00142     if 'portal_transforms' not in portal.keys():
00143         reinstall = True
00144     if 'portal_transforms' in portal.keys():
00145         transforms = portal.portal_transforms
00146         try:
00147             transforms.safe_html.get_parameter_value('disable_transform')
00148         except (AttributeError, KeyError):
00149             reinstall = True
00150     if reinstall:
00151         qi = getToolByName(portal, 'portal_quickinstaller', None)
00152         if qi is not None:
00153             qi.reinstallProducts(['PortalTransforms'])
00154             out.append('Reinstalled PortalTransforms.')