Commit cb634656 authored by Julien Muchembled's avatar Julien Muchembled

Fix/optimize Base.getModificationDate() and make it return ZODB date as fallback

Previous implementation only considered workflows that are chained to the
portal type:
- this is slower
- modification_date of old documents may change or disappear, preventing their
  reindexation
- edit_workflow was always considered, regardless it is chained or not

This commit makes getModificationDate more consistent: it simply iterates over
all workflow histories stored on the object.

When there is no workflow history, ZODB date is returned, which makes
getModificationDate useful for objects without any workflow chained, like
simulation movements.

Another optimization is that last history entry is accessed without loading
the whole history.
parent 1338ffb3
...@@ -40,9 +40,11 @@ from AccessControl.PermissionRole import rolesForPermissionOn ...@@ -40,9 +40,11 @@ from AccessControl.PermissionRole import rolesForPermissionOn
from AccessControl.SecurityManagement import getSecurityManager from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.ZopeGuards import guarded_getattr from AccessControl.ZopeGuards import guarded_getattr
from Acquisition import aq_base, aq_inner, aq_acquire, aq_chain from Acquisition import aq_base, aq_inner, aq_acquire, aq_chain
from DateTime import DateTime
import OFS.History import OFS.History
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from OFS.PropertyManager import PropertyManager from OFS.PropertyManager import PropertyManager
from persistent.TimeStamp import TimeStamp
from zExceptions import NotFound, Unauthorized from zExceptions import NotFound, Unauthorized
from ZopePatch import ERP5PropertyManager from ZopePatch import ERP5PropertyManager
...@@ -3158,25 +3160,27 @@ class Base( CopyContainer, ...@@ -3158,25 +3160,27 @@ class Base( CopyContainer,
NOTE: this method is not generic enough. Suggestion: define a modification_date NOTE: this method is not generic enough. Suggestion: define a modification_date
variable on the workflow which is an alias to time. variable on the workflow which is an alias to time.
XXX: Should we return the ZODB date if it's after the last history entry ?
""" """
# Check if edit_workflow defined try:
portal_workflow = getToolByName(self.getPortalObject(), 'portal_workflow') history_list = aq_base(self).workflow_history
wf = portal_workflow.getWorkflowById('edit_workflow') except AttributeError:
wf_list = list(portal_workflow.getWorkflowsFor(self)) pass
if wf is not None: else:
wf_list = [wf] + wf_list max_date = None
max_date = None for history in history_list.itervalues():
for wf in wf_list: try:
try: date = history[-1]['time']
history = wf.getInfoFor(self, 'history', None) except (IndexError, KeyError):
except KeyError: continue
history = None
if history is not None and len(history):
date = history[-1].get('time', None)
# Then get the last line of edit_workflow
if date > max_date: if date > max_date:
max_date = date max_date = date
return max_date if max_date:
# Return a copy of history time, to prevent modification
return DateTime(max_date)
if self._p_serial:
return DateTime(TimeStamp(self._p_serial).timeTime())
# Layout management # Layout management
security.declareProtected(Permissions.AccessContentsInformation, 'getApplicableLayout') security.declareProtected(Permissions.AccessContentsInformation, 'getApplicableLayout')
......
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