diff --git a/product/CMFActivity/tests/testCMFActivity.py b/product/CMFActivity/tests/testCMFActivity.py index 700ea24454d04edea367060241bc18bda69c7953..109b0ffa74b9cb6d52ccb3a38f58d506790a5e4c 100644 --- a/product/CMFActivity/tests/testCMFActivity.py +++ b/product/CMFActivity/tests/testCMFActivity.py @@ -3442,6 +3442,16 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ).getTitle() self.tic() + def test_activateOnZsqlBrain(self): + portal = self.getPortal() + organisation_module = self.getOrganisationModule() + if not organisation_module.hasContent(self.company_id): + organisation_module.newContent(id=self.company_id) + self.tic() + organisation = organisation_module.searchFolder(id=self.company_id)[0] + organisation.activate().getTitle() + self.tic() + def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestCMFActivity)) diff --git a/product/ZSQLCatalog/Extensions/zsqlbrain.py b/product/ZSQLCatalog/Extensions/zsqlbrain.py index e1ad611470998f75dd71e47e39b6ae1f04a6dc76..cab88989e0acdcd96712f5580a37c848fd48f598 100644 --- a/product/ZSQLCatalog/Extensions/zsqlbrain.py +++ b/product/ZSQLCatalog/Extensions/zsqlbrain.py @@ -23,6 +23,11 @@ from AccessControl.SecurityInfo import allow_class from zLOG import LOG, WARNING +try: + from Products.CMFActivity.ActiveObject import DEFAULT_ACTIVITY +except ImportError: + DEFAULT_ACTIVITY = None + _MARKER = [] class ZSQLBrain(Acquisition.Implicit): @@ -120,6 +125,35 @@ class ZSQLBrain(Acquisition.Implicit): except: pass + # If CMFActivity is available, we add ZSQLBrain.activate() that does + # not call getObject() for better performance and less memory usage. + if DEFAULT_ACTIVITY is not None: + def activate(self, activity=DEFAULT_ACTIVITY, active_process=None, + activate_kw=None, **kw): + """ + This method returns an ActiveWrapper without calling getObject(). + + See CMFActivity.ActiveObject.activate() for the detail of API. + """ + try: + activity_tool = self.aq_parent.getPortalObject().portal_activities + except AttributeError: + return self # Do nothing if no portal_activities + # here we cannot have local default_activate_parameter because + # we don't want to access the object. if we really need local + # one, we can just call like brain.getObject().activate() + # instead. + new_kw = activity_tool.getDefaultActivateParameterDict(inherit_placeless=False) + if activate_kw: + new_kw.update(activate_kw) + new_kw.update(kw) + + # activate returns an ActiveWrapper + # a queue can be provided as well as extra parameters + # which can be used for example to define deferred tasks + return activity_tool.activateObject( + self.getPath(), activity, active_process, **new_kw) + allow_class(ZSQLBrain) class ZSQLBrainNoObject(ZSQLBrain):