Commit 92191de3 authored by Sebastien Robin's avatar Sebastien Robin

allow to rebuild portal_ids from values stored on ZODB

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36171 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 33aff85f
...@@ -209,3 +209,26 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator): ...@@ -209,3 +209,26 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
'idTool_zDropTable and/or idTool_zCreateTable could not be found.' 'idTool_zDropTable and/or idTool_zCreateTable could not be found.'
drop_method() drop_method()
create_method() create_method()
security.declareProtected(Permissions.AccessContentsInformation,
'rebuildSqlTable')
def rebuildSqlTable(self):
"""
After a mysql crash, it could be needed to restore values stored in
zodb into mysql
TODO : take into account the case where the value is stored every X
generation
"""
portal = self.getPortalObject()
getattr(portal, 'IdTool_zDropTable')()
getattr(self, 'SQLNonContinuousIncreasingIdGenerator_zCreateTable')()
security.declareProtected(Permissions.AccessContentsInformation,
'rebuildSqlTable')
def getPersistentIdDict(self):
"""
Return all data stored in zodb
"""
return dict([(x[0],x[1].value) for x in
getattr(self, 'last_max_id_dict', {}).iteritems()])
...@@ -32,6 +32,7 @@ import unittest ...@@ -32,6 +32,7 @@ import unittest
import transaction import transaction
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from _mysql_exceptions import ProgrammingError
class TestIdTool(ERP5TypeTestCase): class TestIdTool(ERP5TypeTestCase):
...@@ -259,6 +260,25 @@ class TestIdTool(ERP5TypeTestCase): ...@@ -259,6 +260,25 @@ class TestIdTool(ERP5TypeTestCase):
id_generator='test_application_sql', id_generator='test_application_sql',
id_group='a04', id_count=3)) id_group='a04', id_count=3))
def test_05_RebuildTableForDefaultSQLNonContinuousIncreasingIdGenerator(self):
"""
It should be possible to reconstruct the portal_ids table thanks to
data stored in ZODB
"""
portal = self.getPortalObject()
generator = self.id_tool._getLatestGeneratorValue(
'mysql_non_continuous_increasing')
self.assertTrue(generator is not None)
generator.generateNewId(id_group='foo_bar', default=4)
self.assertEquals(generator.last_max_id_dict['foo_bar'].value, 4)
portal.IdTool_zDropTable()
sql_connection = self.getSQLConnection()
query = 'select last_id from portal_ids where id_group="foo_bar"'
self.assertRaises(ProgrammingError, sql_connection.manage_test, query)
generator.rebuildSqlTable()
result = sql_connection.manage_test(query)
self.assertEqual(result[0].last_id, 4)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestIdTool)) suite.addTest(unittest.makeSuite(TestIdTool))
......
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