From d8fe213b4cbc1e4646c7e5b27072c3218fe1acaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=A8le=20Vanbaelinghem?= <daniele@nexedi.com> Date: Tue, 27 Apr 2010 12:35:19 +0000 Subject: [PATCH] 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 --- product/ERP5/Document/IdGenerator.py | 4 ++-- .../SQLNonContinuousIncreasingIdGenerator.py | 16 ++++++++++------ product/ERP5/Tool/IdTool.py | 2 -- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/product/ERP5/Document/IdGenerator.py b/product/ERP5/Document/IdGenerator.py index 808681ac34..453e9e5f83 100644 --- a/product/ERP5/Document/IdGenerator.py +++ b/product/ERP5/Document/IdGenerator.py @@ -105,7 +105,7 @@ class IdGenerator(Base): return specialise.getLatestVersionValue().generateNewIdList(id_group=id_group, \ id_count=id_count, default=default) - security.declareProtected(Permissions.AccessContentsInformation, + security.declareProtected(Permissions.ModifyPortalContent, 'initializeGenerator') def initializeGenerator(self): """ @@ -119,7 +119,7 @@ class IdGenerator(Base): self.getReference() specialise.getLatestVersionValue().initializeGenerator() - security.declareProtected(Permissions.AccessContentsInformation, + security.declareProtected(Permissions.ModifyPortalContent, 'clearGenerator') def clearGenerator(self): """ diff --git a/product/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py b/product/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py index 0b706ea794..8b67606221 100644 --- a/product/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py +++ b/product/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py @@ -34,6 +34,7 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type.Utils import ScalarMaxConflictResolver from Products.ERP5.Document.IdGenerator import IdGenerator from _mysql_exceptions import ProgrammingError +from MySQLdb.constants.ER import NO_SUCH_TABLE from zLOG import LOG, INFO class SQLNonContinuousIncreasingIdGenerator(IdGenerator): @@ -86,7 +87,9 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator): new_id = result_query[0]['LAST_INSERT_ID()'] # Commit the changement of new_id commit_method() - except ProgrammingError: + except ProgrammingError, error: + if error[0] != NO_SUCH_TABLE: + raise # If the database not exist, initialise the generator self.initializeGenerator() if self.getStoredInZodb(): @@ -142,7 +145,9 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator): 'idTool_zGetValueList could not be found.' try: get_value_list() - except ProgrammingError: + except ProgrammingError, error: + if error[0] != NO_SUCH_TABLE: + raise drop_method = getattr(portal, 'IdTool_zDropTable', None) create_method = getattr(portal, 'IdTool_zCreateEmptyTable', None) if None in (drop_method, create_method): @@ -161,9 +166,8 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator): 'idTool_zGetLastId and/or idTool_zSetLastId could not be found.' storage = self.getStoredInZodb() # Recovery last_max_id_dict datas in zodb if enabled and is in mysql - if len(self.last_max_id_dict) != 0: - dump_dict = self.last_max_id_dict - elif getattr(portal_ids, 'dict_length_ids', None) is not None: + if len(self.last_max_id_dict) == 0 and \ + getattr(portal_ids, 'dict_length_ids', None) is not None: dump_dict = portal_ids.dict_length_ids for id_group, last_id in dump_dict.items(): last_insert_id = get_last_id_method(id_group=id_group) @@ -172,7 +176,7 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator): if last_insert_id > last_id.value: # Check value in dict 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].set(last_insert_id) continue diff --git a/product/ERP5/Tool/IdTool.py b/product/ERP5/Tool/IdTool.py index 20ec8edd9e..fadd5e7983 100644 --- a/product/ERP5/Tool/IdTool.py +++ b/product/ERP5/Tool/IdTool.py @@ -100,8 +100,6 @@ class IdTool(BaseTool): raise KeyError, 'The generator %s is not present' % (reference,) return id_last_generator - security.declareProtected(Permissions.AccessContentsInformation, - 'getLatestGeneratorValue') def _getLatestGeneratorValue(self, id_generator): """ Return the last generator with the reference -- 2.30.9