Commit c69a859e authored by Vincent Pelletier's avatar Vincent Pelletier

Add a method on IdTool to dump all ids from table and store them in ZODB...

Add a method on IdTool to dump all ids from table and store them in ZODB (persistent mapping on portal_ids).
Call that method before clearing catalog.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24282 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 821b2375
...@@ -148,6 +148,32 @@ class IdTool(BaseTool): ...@@ -148,6 +148,32 @@ class IdTool(BaseTool):
self.dict_length_ids = PersistentMapping() self.dict_length_ids = PersistentMapping()
return self.dict_length_ids.items() return self.dict_length_ids.items()
security.declarePrivate('dumpDictLengthIdsItems')
def dumpDictLengthIdsItems(self):
"""
Store persistently data from SQL table portal_ids.
"""
portal_catalog = getToolByName(self, 'portal_catalog').getSQLCatalog()
query = getattr(portal_catalog, 'z_portal_ids_dump')
dict_length_ids = getattr(self, 'dict_length_ids', None)
if dict_length_ids is None:
dict_length_ids = self.dict_length_ids = PersistentMapping()
for line in query().dictionaries():
id_group = line['id_group']
last_id = line['last_id']
stored_last_id = self.dict_length_ids.get(id_group)
if stored_last_id is None:
self.dict_length_ids[id_group] = Length(last_id)
else:
stored_last_id_value = stored_last_id()
if stored_last_id_value < last_id:
stored_last_id.set(last_id)
else:
if stored_last_id_value > last_id:
LOG('IdTool', WARNING, 'ZODB value (%r) for group %r is higher ' \
'than SQL value (%r). Keeping ZODB value untouched.' % \
(stored_last_id, id_group, last_id))
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getLastLengthGeneratedId') 'getLastLengthGeneratedId')
def getLastLengthGeneratedId(self, id_group, default=None): def getLastLengthGeneratedId(self, id_group, default=None):
......
...@@ -632,10 +632,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -632,10 +632,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
""" """
id_tool = self.getPortalObject().portal_ids id_tool = self.getPortalObject().portal_ids
try: try:
# Call generate new id in order to store the last id into id_tool.dumpDictLengthIdsItems()
# the zodb
id_tool.generateNewLengthId(id_group='portal_activity')
id_tool.generateNewLengthId(id_group='portal_activity_queue')
except ConflictError: except ConflictError:
raise raise
except: except:
......
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