Commit c6ebe1e2 authored by Nicolas Dumazet's avatar Nicolas Dumazet

simplify code by using exceptions instead of boolean return values


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41366 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 58dbb687
...@@ -42,7 +42,7 @@ import ERP5Defaults ...@@ -42,7 +42,7 @@ import ERP5Defaults
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules
from zLOG import LOG, INFO, WARNING from zLOG import LOG, INFO, WARNING, ERROR
from string import join from string import join
import os import os
import warnings import warnings
...@@ -1391,22 +1391,20 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): ...@@ -1391,22 +1391,20 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
security.declareProtected(Permissions.ManagePortal, 'migrateToPortalTypeClass') security.declareProtected(Permissions.ManagePortal, 'migrateToPortalTypeClass')
def migrateToPortalTypeClass(self): 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. """Compatibility code that allows migrating a site to portal type classes.
We consider that a Site is migrated if its Types Tool is migrated We consider that a Site is migrated if its Types Tool is migrated
(it will always be migrated last)""" (it will always be migrated last)"""
# 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)
if self.portal_types.__class__.__module__ == 'erp5.portal_type': if self.portal_types.__class__.__module__ == 'erp5.portal_type':
# nothing to do # nothing to do
return True return
# 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.
id_list = self.objectIds() id_list = self.objectIds()
# make sure that Types Tool is migrated last # make sure that Types Tool is migrated last
...@@ -1415,17 +1413,8 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): ...@@ -1415,17 +1413,8 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
for id in id_list: for id in id_list:
method = getattr(self[id], '_migrateToPortalTypeClass', None) method = getattr(self[id], '_migrateToPortalTypeClass', None)
if method is None: if method is None:
print id
continue continue
if not method(): 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) Globals.InitializeClass(ERP5Site)
......
...@@ -3864,8 +3864,6 @@ class Base( CopyContainer, ...@@ -3864,8 +3864,6 @@ class Base( CopyContainer,
assert klass != newklass assert klass != newklass
self.__class__ = newklass self.__class__ = newklass
return True
security.declareProtected(Permissions.DeletePortalContent, security.declareProtected(Permissions.DeletePortalContent,
'migratePortalType') 'migratePortalType')
def migratePortalType(self, portal_type): def migratePortalType(self, portal_type):
......
...@@ -78,16 +78,17 @@ class BaseTool (UniqueObject, Folder): ...@@ -78,16 +78,17 @@ class BaseTool (UniqueObject, Folder):
def _migrateToPortalTypeClass(self): def _migrateToPortalTypeClass(self):
portal_type = self.getPortalType() portal_type = self.getPortalType()
# Tools are causing problems: they used to have no type_class, or wrong # Tools are causing problems: they used to have no type_class, or wrong
# type_class. First check that everything is alright before trying # type_class, or sometimes have no type definitions at all.
# Check that everything is alright before trying
# to migrate the tool: # to migrate the tool:
types_tool = self.getPortalObject().portal_types types_tool = self.getPortalObject().portal_types
type_definition = getattr(types_tool, portal_type, None) type_definition = getattr(types_tool, portal_type, None)
if type_definition is None: if type_definition is None:
LOG('TypesTool', WARNING, from Products.ERP5.Document.Document import NotConvertedError
"No portal type was found for Tool '%s'" raise NotConvertedError(
"No portal type definition was found for Tool '%s'"
" (class %s, portal_type '%s')" " (class %s, portal_type '%s')"
% (self.getRelativeUrl(), self.__class__.__name__, portal_type)) % (self.getRelativeUrl(), self.__class__.__name__, portal_type))
return False
type_class = type_definition.getTypeClass() type_class = type_definition.getTypeClass()
if type_class in ('Folder', None): if type_class in ('Folder', None):
...@@ -97,10 +98,10 @@ class BaseTool (UniqueObject, Folder): ...@@ -97,10 +98,10 @@ class BaseTool (UniqueObject, Folder):
if document_class_name in document_class_registry: if document_class_name in document_class_registry:
type_definition.setTypeClass(document_class_name) type_definition.setTypeClass(document_class_name)
else: else:
LOG('TypesTool', WARNING, from Products.ERP5.Document.Document import NotConvertedError
raise NotConvertedError(
'No document class could be found for portal type %s' 'No document class could be found for portal type %s'
% portal_type) % portal_type)
return False
return super(BaseTool, self)._migrateToPortalTypeClass() return super(BaseTool, self)._migrateToPortalTypeClass()
......
...@@ -328,11 +328,7 @@ class TypesTool(TypeProvider): ...@@ -328,11 +328,7 @@ class TypesTool(TypeProvider):
def _migrateToPortalTypeClass(self): def _migrateToPortalTypeClass(self):
for type_definition in self.contentValues(): for type_definition in self.contentValues():
if not type_definition._migrateToPortalTypeClass(): type_definition._migrateToPortalTypeClass()
LOG('TypesTool', WARNING,
'Type definition %s was not migrated'
% type_definition.getRelativeUrl())
return False
return super(TypesTool, self)._migrateToPortalTypeClass() return super(TypesTool, self)._migrateToPortalTypeClass()
# Compatibility code to access old "ERP5 Role Information" objects. # Compatibility code to access old "ERP5 Role Information" objects.
......
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