Commit 2bd1d4ed authored by Jérome Perrin's avatar Jérome Perrin

*: reorganise indexation methods

02011d8e (immediateReindexObject: use super user to reindex script,
2015-12-14) did not apply for inventory, because they were overloading
immediateReindexObject.
Introduce a new level, _immediateReindexObject that will hold the actual
reindexing logic.

Previously this method was using PortalContent.reindexObject which was
monkey patched, to make things less complex and more future proof, move
the monkey patch to a method on base class.

This also drops alternateReindexObject on BalanceTransaction, because it
is already defined in Inventory
parent e605544e
Pipeline #23031 failed with stage
in 0 seconds
......@@ -440,16 +440,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
return factory
security.declarePrivate('alternateReindexObject')
def alternateReindexObject(self, **kw):
"""This method is called when an inventory object is included in a
group of catalogged objects.
"""
return self.immediateReindexObject(**kw)
def immediateReindexObject(self, **kw):
def _immediateReindexObject(self, **kw):
"""Reindexes the object.
This is different indexing that the default Inventory indexing, because
we want to take into account that lines in this balance transaction to
......
......@@ -84,9 +84,9 @@ class Inventory(Delivery):
category_list.extend(value_list)
def immediateReindexObject(self, temp_constructor=None, **kw):
def _immediateReindexObject(self, temp_constructor=None, **kw):
"""
Rewrite reindexObject so that we can insert lines in stock table
Rewrite indexation method so that we can insert lines in stock table
which will be equal to the difference between stock values for
resource in the inventory and the one before the date of this inventory
......
......@@ -2936,9 +2936,12 @@ class Base(
def immediateReindexObject(self, *args, **kw):
if self.isAncestryIndexable():
with super_user():
PortalContent.reindexObject(self, *args, **kw)
self._immediateReindexObject(*args, **kw)
_reindexOnCreation = immediateReindexObject
def _immediateReindexObject(self, *args, **kw):
self.getPortalObject().portal_catalog.reindexCatalogObject(self, *args, **kw)
security.declarePublic('reindexObject')
def reindexObject(self, *args, **kw):
"""
......
......@@ -43,7 +43,6 @@ from Products.ERP5Type.patches import DynamicType
from Products.ERP5Type.patches import Expression
from Products.ERP5Type.patches import sqltest
from Products.ERP5Type.patches import sqlvar
from Products.ERP5Type.patches import CMFCatalogAware
from Products.ERP5Type.patches import ProductContext
from Products.ERP5Type.patches import PropertiedUser
if WITH_LEGACY_WORKFLOW:
......
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2002,2005 Nexedi SARL and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
# CMFCatalogAware patch for accepting arbitrary parameters.
from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
from Acquisition import aq_base
from Products.CMFCore.utils import getToolByName
def reindexCatalogObject(self, idxs=[], *args, **kw):
"""
Reindex the object in the portal catalog.
If idxs is present, only those indexes are reindexed.
The metadata is always updated.
Also update the modification date of the object,
unless specific indexes were requested.
"""
if idxs == []:
# Update the modification date.
if getattr(aq_base(self), 'notifyModified', None) is not None:
self.notifyModified()
catalog = getToolByName(self, 'portal_catalog', None)
if catalog is not None :
catalog.reindexCatalogObject(self, idxs=idxs, *args, **kw)
CMFCatalogAware.reindexObject = reindexCatalogObject
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