Commit a7d362c5 authored by Jérome Perrin's avatar Jérome Perrin

ERP5Type: do not allow creating / removing subobjects while migrating to HBTree

because objects will be lost.

At same time, simplify code a bit :

- Just use _migration_in_progress attribute directly instead of a variable.
- Set a default value on class, so that we do not have to getattr.
- Do not use  aq_base, this is useless for attributes starting with _
parent 44d7fb96
Pipeline #1822 skipped
...@@ -84,9 +84,6 @@ from zLOG import LOG, WARNING ...@@ -84,9 +84,6 @@ from zLOG import LOG, WARNING
import warnings import warnings
from urlparse import urlparse from urlparse import urlparse
# variable to inform about migration process
migration_process_lock = "_migration_in_progress"
REINDEX_SPLIT_COUNT = 100 # if folder containes more than this, reindexing should be splitted. REINDEX_SPLIT_COUNT = 100 # if folder containes more than this, reindexing should be splitted.
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
...@@ -103,6 +100,8 @@ def dummyTestAfter(object,REQUEST=None): ...@@ -103,6 +100,8 @@ def dummyTestAfter(object,REQUEST=None):
class FolderMixIn(ExtensionClass.Base): class FolderMixIn(ExtensionClass.Base):
"""A mixin class for folder operations, add content, delete content etc. """A mixin class for folder operations, add content, delete content etc.
""" """
# flag to hold the status of migration for this folder
_migration_in_progress = False
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
...@@ -164,6 +163,13 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -164,6 +163,13 @@ class FolderMixIn(ExtensionClass.Base):
**kw) **kw)
if temp_container: if temp_container:
container._setObject(new_id, new_instance.aq_base) container._setObject(new_id, new_instance.aq_base)
elif self._migration_in_progress:
raise RuntimeError("Folder is running migration to HBTree")
else:
# make sure another zope hasn't started to migrate to HBTree
connection = self._p_jar
connection is None or connection.readCurrent(self)
return new_instance return new_instance
security.declareProtected( security.declareProtected(
...@@ -172,6 +178,8 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -172,6 +178,8 @@ class FolderMixIn(ExtensionClass.Base):
""" delete items in this folder. """ delete items in this folder.
`id` can be a list or a string. `id` can be a list or a string.
""" """
if self._migration_in_progress:
raise RuntimeError("Folder is running migration to HBTree")
error_message = 'deleteContent only accepts string or list of strings not ' error_message = 'deleteContent only accepts string or list of strings not '
if isinstance(id, str): if isinstance(id, str):
self._delObject(id) self._delObject(id)
...@@ -637,13 +645,12 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn): ...@@ -637,13 +645,12 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn):
# if folder is already migrated or migration process is in progress # if folder is already migrated or migration process is in progress
# do not do anything beside logging # do not do anything beside logging
if getattr(self, migration_process_lock, None) is not None \ if self._migration_in_progress or self.isHBTree():
or self.isHBTree():
LOG('migrateToHBTree', WARNING, LOG('migrateToHBTree', WARNING,
'Folder %s already migrated'%(self.getPath(),)) 'Folder %s already migrated'%(self.getPath(),))
return return
# lock folder migration early # lock folder migration
setattr(self, migration_process_lock, 1) self._migration_in_progress = True
# we may want to change all objects ids before migrating to new folder type # we may want to change all objects ids before migrating to new folder type
# set new id generator here so that object created while migration # set new id generator here so that object created while migration
...@@ -683,7 +690,7 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn): ...@@ -683,7 +690,7 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn):
Remove remaining attributes from previous btree Remove remaining attributes from previous btree
and migration and migration
""" """
for attr in "_tree", "_mt_index", migration_process_lock: for attr in "_tree", "_mt_index", "_migration_in_progress":
try: try:
delattr(self, attr) delattr(self, attr)
except AttributeError: except AttributeError:
......
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