Change mysql error to only check if the table not exists and

change the bad security on the methods, thanks you Jerome.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34821 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0e92fdf5
...@@ -105,7 +105,7 @@ class IdGenerator(Base): ...@@ -105,7 +105,7 @@ class IdGenerator(Base):
return specialise.getLatestVersionValue().generateNewIdList(id_group=id_group, \ return specialise.getLatestVersionValue().generateNewIdList(id_group=id_group, \
id_count=id_count, default=default) id_count=id_count, default=default)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.ModifyPortalContent,
'initializeGenerator') 'initializeGenerator')
def initializeGenerator(self): def initializeGenerator(self):
""" """
...@@ -119,7 +119,7 @@ class IdGenerator(Base): ...@@ -119,7 +119,7 @@ class IdGenerator(Base):
self.getReference() self.getReference()
specialise.getLatestVersionValue().initializeGenerator() specialise.getLatestVersionValue().initializeGenerator()
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.ModifyPortalContent,
'clearGenerator') 'clearGenerator')
def clearGenerator(self): def clearGenerator(self):
""" """
......
...@@ -34,6 +34,7 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces ...@@ -34,6 +34,7 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Utils import ScalarMaxConflictResolver from Products.ERP5Type.Utils import ScalarMaxConflictResolver
from Products.ERP5.Document.IdGenerator import IdGenerator from Products.ERP5.Document.IdGenerator import IdGenerator
from _mysql_exceptions import ProgrammingError from _mysql_exceptions import ProgrammingError
from MySQLdb.constants.ER import NO_SUCH_TABLE
from zLOG import LOG, INFO from zLOG import LOG, INFO
class SQLNonContinuousIncreasingIdGenerator(IdGenerator): class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
...@@ -86,7 +87,9 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator): ...@@ -86,7 +87,9 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
new_id = result_query[0]['LAST_INSERT_ID()'] new_id = result_query[0]['LAST_INSERT_ID()']
# Commit the changement of new_id # Commit the changement of new_id
commit_method() commit_method()
except ProgrammingError: except ProgrammingError, error:
if error[0] != NO_SUCH_TABLE:
raise
# If the database not exist, initialise the generator # If the database not exist, initialise the generator
self.initializeGenerator() self.initializeGenerator()
if self.getStoredInZodb(): if self.getStoredInZodb():
...@@ -142,7 +145,9 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator): ...@@ -142,7 +145,9 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
'idTool_zGetValueList could not be found.' 'idTool_zGetValueList could not be found.'
try: try:
get_value_list() get_value_list()
except ProgrammingError: except ProgrammingError, error:
if error[0] != NO_SUCH_TABLE:
raise
drop_method = getattr(portal, 'IdTool_zDropTable', None) drop_method = getattr(portal, 'IdTool_zDropTable', None)
create_method = getattr(portal, 'IdTool_zCreateEmptyTable', None) create_method = getattr(portal, 'IdTool_zCreateEmptyTable', None)
if None in (drop_method, create_method): if None in (drop_method, create_method):
...@@ -161,9 +166,8 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator): ...@@ -161,9 +166,8 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
'idTool_zGetLastId and/or idTool_zSetLastId could not be found.' 'idTool_zGetLastId and/or idTool_zSetLastId could not be found.'
storage = self.getStoredInZodb() storage = self.getStoredInZodb()
# Recovery last_max_id_dict datas in zodb if enabled and is in mysql # Recovery last_max_id_dict datas in zodb if enabled and is in mysql
if len(self.last_max_id_dict) != 0: if len(self.last_max_id_dict) == 0 and \
dump_dict = self.last_max_id_dict getattr(portal_ids, 'dict_length_ids', None) is not None:
elif getattr(portal_ids, 'dict_length_ids', None) is not None:
dump_dict = portal_ids.dict_length_ids dump_dict = portal_ids.dict_length_ids
for id_group, last_id in dump_dict.items(): for id_group, last_id in dump_dict.items():
last_insert_id = get_last_id_method(id_group=id_group) last_insert_id = get_last_id_method(id_group=id_group)
...@@ -172,7 +176,7 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator): ...@@ -172,7 +176,7 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
if last_insert_id > last_id.value: if last_insert_id > last_id.value:
# Check value in dict # Check value in dict
if storage and (not self.last_max_id_dict.has_key(id_group) or \ if storage and (not self.last_max_id_dict.has_key(id_group) or \
self.last_max_id_dict.has_key[id_group] != last_insert_id): self.last_max_id_dict[id_group].value < last_insert_id):
self.last_max_id_dict[id_group] = ScalarMaxConflictResolver(last_insert_id) self.last_max_id_dict[id_group] = ScalarMaxConflictResolver(last_insert_id)
self.last_max_id_dict[id_group].set(last_insert_id) self.last_max_id_dict[id_group].set(last_insert_id)
continue continue
......
...@@ -100,8 +100,6 @@ class IdTool(BaseTool): ...@@ -100,8 +100,6 @@ class IdTool(BaseTool):
raise KeyError, 'The generator %s is not present' % (reference,) raise KeyError, 'The generator %s is not present' % (reference,)
return id_last_generator return id_last_generator
security.declareProtected(Permissions.AccessContentsInformation,
'getLatestGeneratorValue')
def _getLatestGeneratorValue(self, id_generator): def _getLatestGeneratorValue(self, id_generator):
""" """
Return the last generator with the reference Return the last generator with the reference
......
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