Back to index

plone3  3.1.7
two12_two13.py
Go to the documentation of this file.
00001 from Products.CMFCore.utils import getToolByName
00002 
00003 from Products.CMFPlone.migrations.v3_0.alphas import enableZope3Site
00004 from Products.CMFPlone.migrations.v3_0.alphas import registerToolsAsUtilities
00005 
00006 
00007 def two12_two13(portal):
00008     """2.1.2 -> 2.1.3
00009     """
00010     out = []
00011 
00012     # Make the portal a Zope3 site
00013     enableZope3Site(portal, out)
00014 
00015     # register some tools as utilities
00016     registerToolsAsUtilities(portal, out)
00017 
00018     # Put navtree properties in a sensible state
00019     normalizeNavtreeProperties(portal, out)
00020 
00021     # Remove vcXMLRPC.js from ResourceRegistries
00022     removeVcXMLRPC(portal, out)
00023 
00024     # Required due to a fix in PortalTransforms...
00025     migtool = getToolByName(portal, 'portal_migration')
00026     migtool._needRecatalog = True
00027 
00028     # add icons for copy, cut, paste and delete
00029     addActionDropDownMenuIcons(portal, out)
00030 
00031     return out
00032 
00033 
00034 def normalizeNavtreeProperties(portal, out):
00035     """Remove unused navtree properties, add 'name' and 'root' properties. Set
00036     bottomLevel to 0 if it's 65535 (the old marker)
00037     """
00038     toRemove = ['skipIndex_html', 'showMyUserFolderOnly', 'showFolderishSiblingsOnly',
00039                 'showFolderishChildrenOnly', 'showNonFolderishObject', 'showTopicResults',
00040                 'rolesSeeContentView', 'rolesSeeUnpublishedContent', 'rolesSeeContentsView', 
00041                 'batchSize', 'sortCriteria', 'croppingLength', 'forceParentsInBatch', 
00042                 'rolesSeeHiddenContent', 'typesLinkToFolderContents']
00043     toAdd = {'name' : ('string', ''), 
00044              'root' : ('string', '/'), 
00045              'currentFolderOnlyInNavtree' : ('boolean', False)}
00046     portal_properties = getToolByName(portal, 'portal_properties', None)
00047     if portal_properties is not None:
00048         navtree_properties = getattr(portal_properties, 'navtree_properties', None)
00049         if navtree_properties is not None:
00050             for property in toRemove:
00051                 if navtree_properties.getProperty(property, None) is not None:
00052                     navtree_properties._delProperty(property)
00053             for property, value in toAdd.items():
00054                 if navtree_properties.getProperty(property, None) is None:
00055                     navtree_properties._setProperty(property, value[1], value[0])
00056             bottomLevel = navtree_properties.getProperty('bottomLevel', None)
00057             if bottomLevel == 65535:
00058                 navtree_properties.manage_changeProperties(bottomLevel = 0)
00059 
00060 
00061 def removeVcXMLRPC(portal, out):
00062     """Remove vcXMLRPC.js from ResourceRegistries
00063     """
00064     jsreg = getToolByName(portal, 'portal_javascripts', None)
00065     if jsreg is not None:
00066         if 'vcXMLRPC.js' in jsreg.getResourceIds():
00067             jsreg.unregisterResource('vcXMLRPC.js')
00068             out.append('Removed vcXMLRPC.js')
00069 
00070 
00071 def addActionDropDownMenuIcons(portal, out):
00072     """Add icons for copy, cut, paste and delete
00073     """
00074     ai=getToolByName(portal, 'portal_actionicons', None)
00075     if ai is None:
00076         return
00077     icons = dict([
00078         ((x.getCategory(), x.getActionId()), x)
00079         for x in ai.listActionIcons()
00080     ])
00081     added = False
00082     if ('object_buttons', 'cut') not in icons:
00083         ai.addActionIcon('object_buttons', 'cut', 'cut_icon.gif', 'Cut')
00084         added = True
00085     else:
00086         ai.updateActionIcon('object_buttons', 'cut', 'cut_icon.gif', 'Cut')
00087     if ('object_buttons', 'copy') not in icons:
00088         ai.addActionIcon('object_buttons', 'copy', 'copy_icon.gif', 'Copy')
00089         added = True
00090     else:
00091         ai.updateActionIcon('object_buttons', 'copy', 'copy_icon.gif', 'Copy')
00092     if ('object_buttons', 'paste') not in icons:
00093         ai.addActionIcon('object_buttons', 'paste', 'paste_icon.gif', 'Paste')
00094         added = True
00095     else:
00096         ai.updateActionIcon('object_buttons', 'paste', 'paste_icon.gif', 'Paste')
00097     if ('object_buttons', 'delete') not in icons:
00098         ai.addActionIcon('object_buttons', 'delete', 'delete_icon.gif', 'Delete')
00099         added = True
00100     else:
00101         ai.updateActionIcon('object_buttons', 'delete', 'delete_icon.gif', 'Delete')
00102     if added:
00103         out.append('Added icons for copy, cut, paste and delete')
00104     else:
00105         out.append('Updated icons for copy, cut, paste and delete')
00106 
00107 
00108 def reindexCatalog(portal, out):
00109     """Rebuilds the portal_catalog."""
00110     catalog = getToolByName(portal, 'portal_catalog', None)
00111     if catalog is not None:
00112         # Reduce threshold for the reindex run
00113         old_threshold = catalog.threshold
00114         pg_threshold = getattr(catalog, 'pgthreshold', 0)
00115         catalog.pgthreshold = 300
00116         catalog.threshold = 2000
00117         catalog.refreshCatalog(clear=1)
00118         catalog.threshold = old_threshold
00119         catalog.pgthreshold = pg_threshold
00120         out.append("Reindexed portal_catalog.")
00121 
00122 
00123 def indexMembersFolder(portal, out):
00124     """Makes sure the Members folder is cataloged."""
00125     catalog = getToolByName(portal, 'portal_catalog', None)
00126     if catalog is not None:
00127         membershipTool = getToolByName(portal, 'portal_membership', None)
00128         if membershipTool is not None:
00129             members = membershipTool.getMembersFolder()
00130             if members is not None:
00131                 members.indexObject()
00132                 out.append('Recataloged Members folder.')
00133