Commit ab911875 authored by Nicolas Dumazet's avatar Nicolas Dumazet

code allowing to migrate to portal type classes


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41141 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 36c923fb
...@@ -3844,6 +3844,17 @@ class Base( CopyContainer, ...@@ -3844,6 +3844,17 @@ class Base( CopyContainer,
def isItem(self): def isItem(self):
return self.portal_type in self.getPortalItemTypeList() return self.portal_type in self.getPortalItemTypeList()
def _migrateToPortalTypeClass(self):
klass = self.__class__
portal_type = self.getPortalType()
if klass.__module__ not in ('erp5.portal_type', 'erp5.temp_portal_type'):
import erp5.portal_type
newklass = getattr(erp5.portal_type, portal_type)
assert klass != 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):
......
...@@ -32,6 +32,7 @@ from AccessControl import ClassSecurityInfo ...@@ -32,6 +32,7 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass, DTMLFile from Products.ERP5Type.Globals import InitializeClass, DTMLFile
from Products.ERP5Type.Core.Folder import Folder from Products.ERP5Type.Core.Folder import Folder
from Products.ERP5Type import Permissions, _dtmldir from Products.ERP5Type import Permissions, _dtmldir
from zLOG import LOG, INFO, WARNING
class BaseTool (UniqueObject, Folder): class BaseTool (UniqueObject, Folder):
""" """
...@@ -74,4 +75,33 @@ class BaseTool (UniqueObject, Folder): ...@@ -74,4 +75,33 @@ class BaseTool (UniqueObject, Folder):
meta_types.append(meta_type) meta_types.append(meta_type)
return meta_types return meta_types
def _migrateToPortalTypeClass(self):
portal_type = self.getPortalType()
# Tools are causing problems: they used to have no type_class, or wrong
# type_class. First check that everything is alright before trying
# to migrate the tool:
types_tool = self.getPortalObject().portal_types
type_definition = getattr(types_tool, portal_type, None)
if type_definition is None:
LOG('TypesTool', WARNING,
"No portal type was found for Tool '%s'"
" (class %s, portal_type '%s')"
% (self.getRelativeUrl(), self.__class__.__name__, portal_type))
return False
type_class = type_definition.getTypeClass()
if type_class in ('Folder', None):
# wrong type_class, fix it manually:
from Products.ERP5Type import document_class_registry
document_class_name = portal_type.replace(' ', '')
if document_class_name in document_class_registry:
type_definition.setTypeClass(document_class_name)
else:
LOG('TypesTool', WARNING,
'No document class could be found for portal type %s'
% portal_type)
return False
return super(BaseTool, self)._migrateToPortalTypeClass()
InitializeClass(BaseTool) InitializeClass(BaseTool)
...@@ -326,6 +326,15 @@ class TypesTool(TypeProvider): ...@@ -326,6 +326,15 @@ class TypesTool(TypeProvider):
trashbin = UnrestrictedMethod(trash_tool.newTrashBin)(self.id) trashbin = UnrestrictedMethod(trash_tool.newTrashBin)(self.id)
trashbin._setOb(old_types_tool.id, old_types_tool) trashbin._setOb(old_types_tool.id, old_types_tool)
def _migrateToPortalTypeClass(self):
for type_definition in self.contentValues():
if not type_definition._migrateToPortalTypeClass():
LOG('TypesTool', WARNING,
'Type definition %s was not migrated'
% type_definition.getRelativeUrl())
return False
return super(BaseTool, self)._migrateToPortalTypeClass()
# Compatibility code to access old "ERP5 Role Information" objects. # Compatibility code to access old "ERP5 Role Information" objects.
OldRoleInformation = imp.new_module('Products.ERP5Type.RoleInformation') OldRoleInformation = imp.new_module('Products.ERP5Type.RoleInformation')
sys.modules[OldRoleInformation.__name__] = OldRoleInformation sys.modules[OldRoleInformation.__name__] = OldRoleInformation
......
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