[Erp5-report] r43507 jm - in /erp5/trunk/products: ERP5/bootstrap/erp5_core/ToolTemplateIte...

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Feb 21 08:11:44 CET 2011


Author: jm
Date: Mon Feb 21 08:11:44 2011
New Revision: 43507

URL: http://svn.erp5.org?rev=43507&view=rev
Log:
Fix several bootstrap issues preventing from upgrading an existing site

Removed:
    erp5/trunk/products/ERP5/bootstrap/erp5_core/ToolTemplateItem/portal_property_sheets.xml
    erp5/trunk/products/ERP5/bootstrap/erp5_core/ToolTemplateItem/portal_types.xml
Modified:
    erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/revision
    erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/template_keep_path_list
    erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/template_tool_id_list
    erp5/trunk/products/ERP5Type/Tool/BaseTool.py
    erp5/trunk/products/ERP5Type/Tool/PropertySheetTool.py
    erp5/trunk/products/ERP5Type/Tool/TypesTool.py
    erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py

Removed: erp5/trunk/products/ERP5/bootstrap/erp5_core/ToolTemplateItem/portal_property_sheets.xml
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/bootstrap/erp5_core/ToolTemplateItem/portal_property_sheets.xml?rev=43506&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/bootstrap/erp5_core/ToolTemplateItem/portal_property_sheets.xml [utf8] (original)
+++ erp5/trunk/products/ERP5/bootstrap/erp5_core/ToolTemplateItem/portal_property_sheets.xml (removed)
@@ -1,56 +0,0 @@
-<?xml version="1.0"?>
-<ZopeData>
-  <record id="1" aka="AAAAAAAAAAE=">
-    <pickle>
-      <global name="Property Sheet Tool" module="erp5.portal_type"/>
-    </pickle>
-    <pickle>
-      <dictionary>
-        <item>
-            <key> <string>_count</string> </key>
-            <value>
-              <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
-            </value>
-        </item>
-        <item>
-            <key> <string>_mt_index</string> </key>
-            <value>
-              <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
-            </value>
-        </item>
-        <item>
-            <key> <string>_tree</string> </key>
-            <value>
-              <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
-            </value>
-        </item>
-        <item>
-            <key> <string>id</string> </key>
-            <value> <string>portal_property_sheets</string> </value>
-        </item>
-      </dictionary>
-    </pickle>
-  </record>
-  <record id="2" aka="AAAAAAAAAAI=">
-    <pickle>
-      <global name="Length" module="BTrees.Length"/>
-    </pickle>
-    <pickle> <int>0</int> </pickle>
-  </record>
-  <record id="3" aka="AAAAAAAAAAM=">
-    <pickle>
-      <global name="OOBTree" module="BTrees.OOBTree"/>
-    </pickle>
-    <pickle>
-      <none/>
-    </pickle>
-  </record>
-  <record id="4" aka="AAAAAAAAAAQ=">
-    <pickle>
-      <global name="OOBTree" module="BTrees.OOBTree"/>
-    </pickle>
-    <pickle>
-      <none/>
-    </pickle>
-  </record>
-</ZopeData>

Removed: erp5/trunk/products/ERP5/bootstrap/erp5_core/ToolTemplateItem/portal_types.xml
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/bootstrap/erp5_core/ToolTemplateItem/portal_types.xml?rev=43506&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/bootstrap/erp5_core/ToolTemplateItem/portal_types.xml [utf8] (original)
+++ erp5/trunk/products/ERP5/bootstrap/erp5_core/ToolTemplateItem/portal_types.xml (removed)
@@ -1,60 +0,0 @@
-<?xml version="1.0"?>
-<ZopeData>
-  <record id="1" aka="AAAAAAAAAAE=">
-    <pickle>
-      <global name="Types Tool" module="erp5.portal_type"/>
-    </pickle>
-    <pickle>
-      <dictionary>
-        <item>
-            <key> <string>_count</string> </key>
-            <value>
-              <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
-            </value>
-        </item>
-        <item>
-            <key> <string>_mt_index</string> </key>
-            <value>
-              <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
-            </value>
-        </item>
-        <item>
-            <key> <string>_tree</string> </key>
-            <value>
-              <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
-            </value>
-        </item>
-        <item>
-            <key> <string>id</string> </key>
-            <value> <string>portal_types</string> </value>
-        </item>
-        <item>
-            <key> <string>last_id</string> </key>
-            <value> <string>2</string> </value>
-        </item>
-      </dictionary>
-    </pickle>
-  </record>
-  <record id="2" aka="AAAAAAAAAAI=">
-    <pickle>
-      <global name="Length" module="BTrees.Length"/>
-    </pickle>
-    <pickle> <int>0</int> </pickle>
-  </record>
-  <record id="3" aka="AAAAAAAAAAM=">
-    <pickle>
-      <global name="OOBTree" module="BTrees.OOBTree"/>
-    </pickle>
-    <pickle>
-      <none/>
-    </pickle>
-  </record>
-  <record id="4" aka="AAAAAAAAAAQ=">
-    <pickle>
-      <global name="OOBTree" module="BTrees.OOBTree"/>
-    </pickle>
-    <pickle>
-      <none/>
-    </pickle>
-  </record>
-</ZopeData>

Modified: erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/revision
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/revision?rev=43507&r1=43506&r2=43507&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/revision [utf8] (original)
+++ erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/revision [utf8] Mon Feb 21 08:11:44 2011
@@ -1 +1 @@
-40893
\ No newline at end of file
+40894
\ No newline at end of file

Modified: erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/template_keep_path_list
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/template_keep_path_list?rev=43507&r1=43506&r2=43507&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/template_keep_path_list [utf8] (original)
+++ erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/template_keep_path_list [utf8] Mon Feb 21 08:11:44 2011
@@ -9,4 +9,5 @@ portal_contribution_registry/text_by_con
 portal_contribution_registry/text_extension.xml
 portal_contribution_registry/web_page_by_content.xml
 portal_contribution_registry/webpage_extension.xml
-portal_contribution_registry/webpage_mimetype.xml
\ No newline at end of file
+portal_contribution_registry/webpage_mimetype.xml
+portal_property_sheets
\ No newline at end of file

Modified: erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/template_tool_id_list
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/template_tool_id_list?rev=43507&r1=43506&r2=43507&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/template_tool_id_list [utf8] (original)
+++ erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/template_tool_id_list [utf8] Mon Feb 21 08:11:44 2011
@@ -1,7 +1,5 @@
 mimetypes_registry
 portal_contribution_registry
 portal_notifications
-portal_property_sheets
 portal_sessions
-portal_transforms
-portal_types
\ No newline at end of file
+portal_transforms
\ No newline at end of file

Modified: erp5/trunk/products/ERP5Type/Tool/BaseTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Tool/BaseTool.py?rev=43507&r1=43506&r2=43507&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Tool/BaseTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Tool/BaseTool.py [utf8] Mon Feb 21 08:11:44 2011
@@ -77,6 +77,7 @@ class BaseTool (UniqueObject, Folder):
           id_set = set(x[:-4] for x in files if x[-4:] == '.xml')
         else:
           id_set = set(quote(x) for x in content_id_list)
+          id_set.difference_update(self.objectIds())
         dirs[:] = id_set.intersection(dirs)
         for file in id_set:
           load(os.path.join(root, file + '.xml'),

Modified: erp5/trunk/products/ERP5Type/Tool/PropertySheetTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Tool/PropertySheetTool.py?rev=43507&r1=43506&r2=43507&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Tool/PropertySheetTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Tool/PropertySheetTool.py [utf8] Mon Feb 21 08:11:44 2011
@@ -50,8 +50,12 @@ class PropertySheetTool(BaseTool):
   security = ClassSecurityInfo()
   security.declareObjectProtected(Permissions.AccessContentsInformation)
 
+  def _isBootstrapRequired(self):
+    return not self.has_key('BaseType')
+
   def _bootstrap(self):
-    super(PropertySheetTool, self)._bootstrap('erp5_property_sheets',
+    bt_name = 'erp5_property_sheets'
+    super(PropertySheetTool, self)._bootstrap(bt_name,
                                               'PropertySheetTemplateItem', (
       'BaseType',
       'BusinessTemplate',
@@ -59,7 +63,18 @@ class PropertySheetTool(BaseTool):
       'SimpleItem',
       'Version',
       'Comment',
+      # the following ones are required to upgrade an existing site
+      'Reference',
+      'BaseCategory',
+      'SQLIdGenerator',
     ))
+    def install():
+      template_tool = self.getPortalObject().portal_templates
+      if template_tool.getInstalledBusinessTemplate(bt_name) is None:
+        from Products.ERP5.ERP5Site import getBootstrapBusinessTemplateUrl
+        url = getBootstrapBusinessTemplateUrl(bt_name)
+        template_tool.download(url).activate().install()
+    transaction.get().addBeforeCommitHook(install)
 
   security.declarePublic('getTranslationDomainNameList')
   def getTranslationDomainNameList(self):

Modified: erp5/trunk/products/ERP5Type/Tool/TypesTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Tool/TypesTool.py?rev=43507&r1=43506&r2=43507&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Tool/TypesTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Tool/TypesTool.py [utf8] Mon Feb 21 08:11:44 2011
@@ -99,6 +99,29 @@ class TypesTool(TypeProvider):
   security = ClassSecurityInfo()
   security.declareObjectProtected(Permissions.AccessContentsInformation)
 
+  def _isBootstrapRequired(self):
+    if not self.has_key('Standard Property'):
+      return True
+    # bootstrap is not required, but we may have a few bugfixes to apply
+    # so that the user can upgrade Business Templates
+    property_sheet_type = self.get('Property Sheet')
+    try:
+      if property_sheet_type.aq_base.type_class != 'PropertySheet':
+        property_sheet_type.type_class = 'PropertySheet'
+    except AttributeError:
+      pass
+    try:
+      script = self.getPortalObject().portal_workflow \
+        .dynamic_class_generation_interaction_workflow.scripts \
+        .DynamicClassGeneration_resetDynamicDocuments
+      new = '.resetDynamicDocumentsOnceAtTransactionBoundary('
+      if new not in script._body:
+        script._body = script._body.replace('.resetDynamicDocuments(', new)
+        script._makeFunction()
+    except AttributeError:
+      pass
+    return False
+
   def _bootstrap(self):
     super(TypesTool, self)._bootstrap('erp5_core', 'PortalTypeTemplateItem', (
       'Business Template',

Modified: erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py?rev=43507&r1=43506&r2=43507&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py [utf8] Mon Feb 21 08:11:44 2011
@@ -399,8 +399,48 @@ def initializeDynamicModules():
   erp5.temp_portal_type = registerDynamicModule('erp5.temp_portal_type',
                                                 loadTempPortalTypeClass)
 
-required_tool_list = (('portal_types', 'Standard Property'),
-                      ('portal_property_sheets', 'BaseType'))
+def _maybe_bootstrap(portal):
+  global _maybe_bootstrap
+  bootstrap = None
+  from Products.ERP5Type.Tool.PropertySheetTool import PropertySheetTool
+  from Products.ERP5Type.Tool.TypesTool import TypesTool
+  for tool_class in TypesTool, PropertySheetTool:
+    # if the instance has no property sheet tool, or incomplete
+    # property sheets, we need to import some data to bootstrap
+    # (only likely to happen on the first run ever)
+    tool_id = tool_class.id
+    tool = getattr(portal, tool_id, None)
+    if tool is None:
+      portal._setObject(tool_id, tool_class(),
+                        set_owner=False, suppress_events=True)
+      tool = getattr(portal, tool_id)
+    elif not tool._isBootstrapRequired():
+      continue
+
+    if not bootstrap:
+      migrate = True
+      LOG('ERP5Site', INFO, 'bootstrap %s...' % tool_id)
+      from Products.ERP5.ERP5Site import getBootstrapDirectory
+      bootstrap = getBootstrapDirectory()
+      cwd = os.getcwd()
+    try:
+      os.chdir(bootstrap)
+      tool._bootstrap()
+    finally:
+      os.chdir(cwd)
+
+  if bootstrap:
+    if not getattr(portal, '_v_bootstrapping', False):
+      LOG('ERP5Site', INFO, 'Transition successful, please update your'
+          ' business templates')
+    # XXX: if some portal types are missing, for instance
+    # if some Tools have no portal types, this is likely to fail with an
+    # error. On the other hand, we can't proceed without this change,
+    # and if we dont import the xml, the instance wont start.
+    portal.migrateToPortalTypeClass()
+
+  _maybe_bootstrap = lambda portal: None
+
 last_sync = -1
 def synchronizeDynamicModules(context, force=False):
   """
@@ -431,54 +471,7 @@ def synchronizeDynamicModules(context, f
 
   Base.aq_method_lock.acquire()
   try:
-
-    migrated = False
-    for tool_id, line_id in required_tool_list:
-      # if the instance has no property sheet tool, or incomplete
-      # property sheets, we need to import some data to bootstrap
-      # (only likely to happen on the first run ever)
-      tool = getattr(portal, tool_id, None)
-      if tool is not None:
-        if getattr(tool, line_id, None) is None:
-          # tool exists, but is incomplete
-          portal._delObject(tool_id)
-        else:
-          # tool exists, Base Type is represented; probably OK
-          continue
-
-      if not migrated:
-        # XXX: if some portal types are missing, for instance
-        # if some Tools have no portal types, this is likely to fail with an
-        # error. On the other hand, we can't proceed without this change,
-        # and if we dont import the xml, the instance wont start.
-        portal.migrateToPortalTypeClass()
-        migrated = True
-
-      LOG('ERP5Site', INFO, 'importing transitional %s tool'
-          ' from Products.ERP5.bootstrap to be able to load'
-          ' core items...' % tool_id)
-
-      from Products.ERP5.ERP5Site import getBootstrapDirectory
-      cwd = os.getcwd()
-      try:
-        os.chdir(getBootstrapDirectory())
-        tool_path = os.path.join('erp5_core', 'ToolTemplateItem',
-                                 tool_id + '.xml')
-        assert os.path.exists(tool_path), 'Please update ERP5 product'
-        try:
-          tool = portal._importObjectFromFile(tool_path, id=tool_id,
-            verify=False, set_owner=False, suppress_events=True)
-          tool._bootstrap()
-        except Exception:
-          import traceback; traceback.print_exc()
-          raise
-      finally:
-        os.chdir(cwd)
-
-      if not getattr(portal, '_v_bootstrapping', False):
-        LOG('ERP5Site', INFO, 'Transition successful, please update your'
-            ' business templates')
-
+    _maybe_bootstrap(portal)
     LOG("ERP5Type.dynamic", 0, "Resetting dynamic classes")
     for class_name, klass in inspect.getmembers(erp5.portal_type,
                                                 inspect.isclass):
@@ -500,6 +493,6 @@ def synchronizeDynamicModules(context, f
 
   # Some method generations are based on portal methods, and portal
   # methods cache results. So it is safer to invalidate the cache.
-  cache_tool = getattr(context, 'portal_caches', None)
+  cache_tool = getattr(portal, 'portal_caches', None)
   if cache_tool is not None:
     cache_tool.clearCache()



More information about the Erp5-report mailing list