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

use aq_base to prevent getting an object with id dict_ids


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24451 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 93f243da
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
# #
############################################################################## ##############################################################################
from Acquisition import aq_base
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Globals import InitializeClass, DTMLFile, PersistentMapping from Globals import InitializeClass, DTMLFile, PersistentMapping
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
...@@ -58,7 +59,7 @@ class IdTool(BaseTool): ...@@ -58,7 +59,7 @@ class IdTool(BaseTool):
""" """
Get the last id generated Get the last id generated
""" """
if getattr(self, 'dict_ids', None) is None: if getattr(aq_base(self), 'dict_ids', None) is None:
self.dict_ids = PersistentMapping() self.dict_ids = PersistentMapping()
last_id = None last_id = None
if id_group is not None and id_group!='None': if id_group is not None and id_group!='None':
...@@ -72,7 +73,7 @@ class IdTool(BaseTool): ...@@ -72,7 +73,7 @@ class IdTool(BaseTool):
Set a new last id. This is usefull in order to reset Set a new last id. This is usefull in order to reset
a sequence of ids. a sequence of ids.
""" """
if getattr(self, 'dict_ids', None) is None: if getattr(aq_base(self), 'dict_ids', None) is None:
self.dict_ids = PersistentMapping() self.dict_ids = PersistentMapping()
if id_group is not None and id_group!='None': if id_group is not None and id_group!='None':
l = threading.Lock() l = threading.Lock()
...@@ -89,7 +90,7 @@ class IdTool(BaseTool): ...@@ -89,7 +90,7 @@ class IdTool(BaseTool):
Generate a new Id Generate a new Id
""" """
if getattr(self, 'dict_ids', None) is None: if getattr(aq_base(self), 'dict_ids', None) is None:
self.dict_ids = PersistentMapping() self.dict_ids = PersistentMapping()
new_id = None new_id = None
...@@ -155,7 +156,7 @@ class IdTool(BaseTool): ...@@ -155,7 +156,7 @@ class IdTool(BaseTool):
""" """
portal_catalog = getToolByName(self, 'portal_catalog').getSQLCatalog() portal_catalog = getToolByName(self, 'portal_catalog').getSQLCatalog()
query = getattr(portal_catalog, 'z_portal_ids_dump') query = getattr(portal_catalog, 'z_portal_ids_dump')
dict_length_ids = getattr(self, 'dict_length_ids', None) dict_length_ids = getattr(aq_base(self), 'dict_length_ids', None)
if dict_length_ids is None: if dict_length_ids is None:
dict_length_ids = self.dict_length_ids = PersistentMapping() dict_length_ids = self.dict_length_ids = PersistentMapping()
for line in query().dictionaries(): for line in query().dictionaries():
...@@ -181,7 +182,7 @@ class IdTool(BaseTool): ...@@ -181,7 +182,7 @@ class IdTool(BaseTool):
Get the last length id generated Get the last length id generated
""" """
# check in persistent mapping if exists # check in persistent mapping if exists
if getattr(self, 'dict_length_ids', None) is not None: if getattr(aq_base(self), 'dict_length_ids', None) is not None:
last_id = self.dict_length_ids.get(id_group) last_id = self.dict_length_ids.get(id_group)
if last_id is not None: if last_id is not None:
return last_id.value - 1 return last_id.value - 1
...@@ -237,7 +238,7 @@ class IdTool(BaseTool): ...@@ -237,7 +238,7 @@ class IdTool(BaseTool):
commit() commit()
new_id = result[0]['LAST_INSERT_ID()'] new_id = result[0]['LAST_INSERT_ID()']
if store: if store:
if getattr(self, 'dict_length_ids', None) is None: if getattr(aq_base(self), 'dict_length_ids', None) is None:
# Length objects are stored in a persistent mapping: there is one # Length objects are stored in a persistent mapping: there is one
# Length object per id_group. # Length object per id_group.
self.dict_length_ids = PersistentMapping() self.dict_length_ids = PersistentMapping()
......
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