Commit 1e87d0fe authored by iv's avatar iv

ERP5Workflow: add _initPersistentObjects method

This fixes Image.py, which was using _initBTree method.
parent e7a50455
...@@ -1373,10 +1373,8 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1373,10 +1373,8 @@ class ObjectTemplateItem(BaseTemplateItem):
if getattr(obj, '_folder_handler', None) == PERSISTENT_MAPPING_HANDLER: if getattr(obj, '_folder_handler', None) == PERSISTENT_MAPPING_HANDLER:
# XXX(WORKFLOW): if obj._count(), then, we should export the content # XXX(WORKFLOW): if obj._count(), then, we should export the content
# of the btree folder to the persistent mapping one # of the btree folder to the persistent mapping one
obj._cleanup() obj._initPersistentObjects()
obj.__init__(obj.id) elif (getattr(aq_base(obj), '_mt_index', None) is not None and
else:
if (getattr(aq_base(obj), '_mt_index', None) is not None and
obj._count() == 0): obj._count() == 0):
# some btrees were exported in a corrupted state. They're empty but # some btrees were exported in a corrupted state. They're empty but
# their metadata-index (._mt_index) contains entries which in # their metadata-index (._mt_index) contains entries which in
......
...@@ -53,6 +53,8 @@ from zLOG import LOG, WARNING ...@@ -53,6 +53,8 @@ from zLOG import LOG, WARNING
from Products.ERP5Type.ImageUtil import transformUrlToDataURI from Products.ERP5Type.ImageUtil import transformUrlToDataURI
from Products.ERP5Type.Core.Folder import PERSISTENT_MAPPING_HANDLER
# import mixin # import mixin
from Products.ERP5.mixin.text_convertable import TextConvertableMixin from Products.ERP5.mixin.text_convertable import TextConvertableMixin
...@@ -136,7 +138,10 @@ class Image(TextConvertableMixin, File, OFSImage): ...@@ -136,7 +138,10 @@ class Image(TextConvertableMixin, File, OFSImage):
""" """
# Quick hack to maintain just enough compatibility for existing sites # Quick hack to maintain just enough compatibility for existing sites
# Convert to new BTreeFolder2 based class # Convert to new BTreeFolder2 based class
if getattr(aq_base(self), '_count', None) is None: if (getattr(aq_base(self), '_folder_handler', None) ==
PERSISTENT_MAPPING_HANDLER):
self._initPersistentObjects()
elif getattr(aq_base(self), '_count', None) is None:
self._initBTrees() self._initBTrees()
# Make sure old Image objects can still be accessed # Make sure old Image objects can still be accessed
......
...@@ -9,6 +9,7 @@ from App.special_dtml import DTMLFile ...@@ -9,6 +9,7 @@ from App.special_dtml import DTMLFile
from zope.event import notify from zope.event import notify
from OFS.event import ObjectWillBeAddedEvent from OFS.event import ObjectWillBeAddedEvent
from OFS.subscribers import compatibilityCall from OFS.subscribers import compatibilityCall
from OFS.ObjectManager import BadRequestException
from zope.lifecycleevent import ObjectAddedEvent from zope.lifecycleevent import ObjectAddedEvent
from zope.lifecycleevent import ObjectRemovedEvent from zope.lifecycleevent import ObjectRemovedEvent
from zope.container.contained import notifyContainerModified from zope.container.contained import notifyContainerModified
...@@ -45,6 +46,13 @@ class ERP5PersistentMappingFolder(PortalFolderBase): ...@@ -45,6 +46,13 @@ class ERP5PersistentMappingFolder(PortalFolderBase):
def __len__(self): def __len__(self):
return self.objectCount() return self.objectCount()
def _initPersistentObjects(self, object_id=None):
self._cleanup()
if object_id is None:
self.__init__(self.id)
else:
self.__init__(object_id)
security.declareProtected(Permissions.AccessContentsInformation, 'get') security.declareProtected(Permissions.AccessContentsInformation, 'get')
def get(self, name, default=None): def get(self, name, default=None):
return self._getOb(name, default) return self._getOb(name, default)
......
...@@ -613,9 +613,10 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, ...@@ -613,9 +613,10 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder,
# Overload __init__ so that we do not take into account title # Overload __init__ so that we do not take into account title
# This is required for test_23_titleIsNotDefinedByDefault # This is required for test_23_titleIsNotDefinedByDefault
def __init__(self, id): def __init__(self, id, _folder_handler=PERSISTENT_MAPPING_HANDLER):
self.id = id self.id = id
if self._folder_handler == PERSISTENT_MAPPING_HANDLER: self._folder_handler = _folder_handler
if _folder_handler == PERSISTENT_MAPPING_HANDLER:
ERP5PersistentMappingFolder.__init__(self, id) ERP5PersistentMappingFolder.__init__(self, id)
security.declarePublic('newContent') security.declarePublic('newContent')
...@@ -734,6 +735,9 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, ...@@ -734,6 +735,9 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder,
obj = getOb(self, id) obj = getOb(self, id)
setOb(self, id, obj) setOb(self, id, obj)
def _setFolderHandler(self, folder_handler):
self._folder_handler = folder_handler
# Override all BTree and HBTree methods to use if/else # Override all BTree and HBTree methods to use if/else
# method to check wich method must be called # method to check wich method must be called
# We use this method instead of plugin because it make # We use this method instead of plugin because it make
......
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