Commit 9a5a0788 authored by Arnaud Fontaine's avatar Arnaud Fontaine

SelectionTool: Changing storage or memcached settings were not taken into effect until restart.

parent 0af872e5
......@@ -57,6 +57,12 @@ if cache_plugin_list:\n
cache_tool = getToolByName(document.getPortalObject(), \'portal_caches\')\n
if cache_tool is not None:\n
cache_tool.updateCache()\n
\n
selection_tool = document.getPortalObject()\n
if selection_tool.getStorage() == document.getRelativeUrl():\n
selection_tool.clearCachedContainer()\n
if selection_tool.getAnonymousStorage() == document.getRelativeUrl():\n
selection_tool.clearCachedContainer(is_anonymous=True)\n
</string> </value>
</item>
<item>
......
......@@ -57,6 +57,12 @@ if cache_plugin_list:\n
cache_tool = getToolByName(document.getPortalObject(), \'portal_caches\')\n
if cache_tool is not None:\n
cache_tool.activate().updateCache()\n
\n
selection_tool = document.getPortalObject()\n
if selection_tool.getStorage() == document.getRelativeUrl():\n
selection_tool.activate().clearCachedContainer()\n
if selection_tool.getAnonymousStorage() == document.getRelativeUrl():\n
selection_tool.activate().clearCachedContainer(is_anonymous=True)\n
</string> </value>
</item>
<item>
......
2013-11-07 arnaud.fontaine
* SelectionTool: Changing storage or memcached settings were not taken into effect until restart.
2013-10-04 arnaud.fontaine
* ZODB Components: Rename common view to ComponentMixin_view (naming conventions and clash with erp5_pdm).
......
41136
\ No newline at end of file
41137
\ No newline at end of file
......@@ -140,6 +140,20 @@ class SelectionTool( BaseTool, SimpleItem ):
storage_item_list.extend([['/'.join((mp.getParentValue().getTitle(), mp.getTitle(),)), mp.getRelativeUrl()] for mp in memcached_plugin_list])
return storage_item_list
security.declareProtected(ERP5Permissions.ModifyPortalContent, 'updateCache')
def clearCachedContainer(self, is_anonymous=False):
"""
Clear Container currently being used for Selection Tool because either the
storage has changed or the its settings
"""
if is_anonymous:
container_id = '_v_anonymous_selection_container'
else:
container_id = '_v_selection_container'
if getattr(aq_base(self), container_id, None):
delattr(self, container_id)
security.declareProtected( ERP5Permissions.ManagePortal, 'setStorage')
def setStorage(self, storage, anonymous_storage=None, RESPONSE=None):
"""
......@@ -147,11 +161,13 @@ class SelectionTool( BaseTool, SimpleItem ):
"""
if storage in [item[1] for item in self.getStorageItemList()]:
self.storage = storage
self.clearCachedContainer()
else:
raise ValueError, 'Given storage type (%s) is now supported.' % (storage,)
anonymous_storage = anonymous_storage or None
if anonymous_storage in [item[1] for item in self.getStorageItemList()] + [None]:
self.anonymous_storage = anonymous_storage
self.clearCachedContainer(is_anonymous=True)
else:
raise ValueError, 'Given storage type (%s) is now supported.' % (anonymous_storage,)
if RESPONSE is not None:
......
......@@ -386,6 +386,71 @@ class TestSelectionToolMemcachedStorage(TestSelectionTool):
def testDeleteGlobalSelection(self):
pass
def testChangeSelectionToolContainer(self):
"""
After changing SelectionTool container, the new one should be used
straightaway, and more specifically volatile variables should have
been reset
"""
from Products.ERP5Form.Tool.SelectionTool import (MemcachedContainer,
PersistentMappingContainer)
# testGetSelectionFor() already checked if the Selection can be retrieved
# from the container set in afterSetUp(), so no need to check again here
self.portal_selections.setStorage('selection_data')
transaction.commit()
self.assertEqual(getattr(self.portal_selections, '_v_selection_container',
None), None)
self.assertEqual(self.portal_selections.getSelectionFor('test_selection'),
None)
self.assertTrue(isinstance(getattr(self.portal_selections,
'_v_selection_container', None),
PersistentMappingContainer))
self.portal_selections.setStorage('portal_memcached/default_memcached_plugin')
transaction.commit()
self.assertEqual(getattr(self.portal_selections, '_v_selection_container',
None), None)
self.assertNotEqual(self.portal_selections.getSelectionFor('test_selection'),
None)
self.assertTrue(isinstance(getattr(self.portal_selections,
'_v_selection_container', None),
MemcachedContainer))
def testChangeMemcached(self):
"""
After Memcached has been changed, the new setting should be used and more
specifically container volative variables should have been reset
"""
self.assertNotEqual(self.portal_selections.getSelectionFor('test_selection'),
None)
memcached_plugin = self.portal.portal_memcached.default_memcached_plugin
url_string_before = memcached_plugin.getUrlString()
memcached_plugin.setUrlString('127.0.0.1:4242')
transaction.commit()
try:
self.assertEqual(getattr(self.portal_selections, '_v_selection_container',
None), None)
self.assertEqual(self.portal_selections.getSelectionFor('test_selection'),
None)
self.assertNotEqual(getattr(self.portal_selections, '_v_selection_container',
None), None)
finally:
memcached_plugin.setUrlString(url_string_before)
transaction.commit()
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestSelectionTool))
......
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