Commit 1e87d0fe authored by iv's avatar iv

ERP5Workflow: add _initPersistentObjects method

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