Commit d0485400 authored by Julien Muchembled's avatar Julien Muchembled

Fix several bootstrap issues preventing from upgrading an existing site

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43507 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 355775c8
<?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>
<?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>
40893
\ No newline at end of file
40894
\ No newline at end of file
......@@ -10,3 +10,4 @@ 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
portal_property_sheets
\ No newline at end of file
mimetypes_registry
portal_contribution_registry
portal_notifications
portal_property_sheets
portal_sessions
portal_transforms
\ No newline at end of file
portal_types
\ No newline at end of file
......@@ -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'),
......
......@@ -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):
......
......@@ -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',
......
......@@ -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, force=False):
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, force=False):
# 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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment