[Erp5-report] r41142 nicolas.dumazet - /erp5/trunk/products/ERP5/ERP5Site.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Dec 6 09:28:34 CET 2010


Author: nicolas.dumazet
Date: Mon Dec  6 09:28:34 2010
New Revision: 41142

URL: http://svn.erp5.org?rev=41142&view=rev
Log:
code allowing migration to portal type classes

Modified:
    erp5/trunk/products/ERP5/ERP5Site.py

Modified: erp5/trunk/products/ERP5/ERP5Site.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/ERP5Site.py?rev=41142&r1=41141&r2=41142&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/ERP5Site.py [utf8] (original)
+++ erp5/trunk/products/ERP5/ERP5Site.py [utf8] Mon Dec  6 09:28:34 2010
@@ -42,7 +42,7 @@ import ERP5Defaults
 from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
 from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules
 
-from zLOG import LOG, INFO
+from zLOG import LOG, INFO, WARNING
 from string import join
 import os
 import warnings
@@ -1389,6 +1389,44 @@ class ERP5Site(FolderMixIn, CMFSite, Cac
     if self.getERP5SiteGlobalId() in [None, '']:
       self.erp5_site_global_id = global_id
 
+  security.declareProtected(Permissions.ManagePortal, 'migrateToPortalTypeClass')
+  def migrateToPortalTypeClass(self):
+    """Migrate site to portal type classes"""
+    # XXX do we want to call this automatically? Where? (note that it's likely
+    # to fail as portal types are usually not perfectly configured, and it
+    # requires user action to fix issues)
+    # TODO better errors than the warnings in LOG + AssertionError
+    assert self._migrateToPortalTypeClass()
+
+  def _migrateToPortalTypeClass(self):
+    """Compatibility code that allows migrating a site to portal type classes.
+    
+    We consider that a Site is migrated if its Types Tool is migrated
+    (it will always be migrated last)"""
+    if self.portal_types.__class__.__module__ == 'erp5.portal_types':
+      # nothing to do
+      return True
+
+    id_list = self.objectIds()
+
+    # make sure that portal_types is migrated last
+    id_list.remove('portal_types')
+    id_list.append('portal_types')
+    for id in id_list:
+      method = getattr(self[id], '_migrateToPortalTypeClass', None)
+      if method is None:
+        print id
+        continue
+      if not method():
+        LOG('ERP5Site', WARNING, 'Site did not migrate to portal type classes')
+        return False
+
+    # note that the site itself is not migrated (ERP5Site is not a portal type)
+    # only the tools and top level modules are.
+    # Normally, PersistentMigrationMixin should take care of the rest.
+
+    return True
+
 Globals.InitializeClass(ERP5Site)
 
 def getBootstrapDirectory():



More information about the Erp5-report mailing list