[CMF-checkins] SVN: CMF/trunk/CMFCore/ Merge from 37626 on 1.5
branch:
Florent Guillaume
fg at nuxeo.com
Mon Aug 1 14:44:41 EDT 2005
Log message for revision 37630:
Merge from 37626 on 1.5 branch:
Refactored reindexObjectSecurity a bit. It now always reindexes the
catalog objects without changing their catalog uid. This is useful for
third-party code that indexes objects with special uids.
Changed:
U CMF/trunk/CMFCore/CMFCatalogAware.py
U CMF/trunk/CMFCore/CatalogTool.py
U CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py
-=-
Modified: CMF/trunk/CMFCore/CMFCatalogAware.py
===================================================================
--- CMF/trunk/CMFCore/CMFCatalogAware.py 2005-08-01 18:42:53 UTC (rev 37629)
+++ CMF/trunk/CMFCore/CMFCatalogAware.py 2005-08-01 18:44:41 UTC (rev 37630)
@@ -80,35 +80,36 @@
security.declareProtected(ModifyPortalContent, 'reindexObjectSecurity')
def reindexObjectSecurity(self, skip_self=False):
+ """Reindex security-related indexes on the object.
+
+ Recurses in the children to reindex them too.
+
+ If skip_self is True, only the children will be reindexed. This
+ is a useful optimization if the object itself has just been
+ fully reindexed, as there's no need to reindex its security twice.
"""
- Reindex security-related indexes on the object
- (and its descendants).
- """
catalog = getToolByName(self, 'portal_catalog', None)
- if catalog is not None:
- path = '/'.join(self.getPhysicalPath())
- for brain in catalog.unrestrictedSearchResults(path=path):
- brain_path = brain.getPath()
- # self is treated at the end of the method
- # Optimization in case of an indexable container
- if brain_path == path:
- continue
- # Get the object
- ob = brain._unrestrictedGetObject()
- if ob is None:
- # Ignore old references to deleted objects.
- LOG('reindexObjectSecurity', PROBLEM,
- "Cannot get %s from catalog" % brain_path)
- continue
- s = getattr(ob, '_p_changed', 0)
- catalog.reindexObject(ob, idxs=self._cmf_security_indexes,
- update_metadata=0)
- if s is None: ob._p_deactivate()
- # Reindex the object itself in here if not explicitly
- # asked to not to
- if not skip_self:
- catalog.reindexObject(self, idxs=self._cmf_security_indexes,
- update_metadata=0)
+ if catalog is None:
+ return
+ path = '/'.join(self.getPhysicalPath())
+ for brain in catalog.unrestrictedSearchResults(path=path):
+ brain_path = brain.getPath()
+ if brain_path == path and skip_self:
+ continue
+ # Get the object
+ ob = brain._unrestrictedGetObject()
+ if ob is None:
+ # BBB: Ignore old references to deleted objects.
+ # Can happen only when using
+ # catalog-getObject-raises off in Zope 2.8
+ LOG('reindexObjectSecurity', PROBLEM,
+ "Cannot get %s from catalog" % brain_path)
+ continue
+ # Recatalog with the same catalog uid.
+ s = getattr(ob, '_p_changed', 0)
+ catalog.reindexObject(ob, idxs=self._cmf_security_indexes,
+ update_metadata=0, uid=brain_path)
+ if s is None: ob._p_deactivate()
# Workflow methods
# ----------------
Modified: CMF/trunk/CMFCore/CatalogTool.py
===================================================================
--- CMF/trunk/CMFCore/CatalogTool.py 2005-08-01 18:42:53 UTC (rev 37629)
+++ CMF/trunk/CMFCore/CatalogTool.py 2005-08-01 18:44:41 UTC (rev 37630)
@@ -320,17 +320,25 @@
self.uncatalog_object(url)
security.declarePrivate('reindexObject')
- def reindexObject(self, object, idxs=[], update_metadata=1):
- '''Update catalog after object data has changed.
+ def reindexObject(self, object, idxs=[], update_metadata=1, uid=None):
+ """Update catalog after object data has changed.
+
The optional idxs argument is a list of specific indexes
to update (all of them by default).
- '''
- url = self.__url(object)
+
+ The update_metadata flag controls whether the object's
+ metadata record is updated as well.
+
+ If a non-None uid is passed, it will be used as the catalog uid
+ for the object instead of its physical path.
+ """
+ if uid is None:
+ uid = self.__url(object)
if idxs != []:
# Filter out invalid indexes.
valid_indexes = self._catalog.indexes.keys()
idxs = [i for i in idxs if i in valid_indexes]
- self.catalog_object(object, url, idxs, update_metadata)
+ self.catalog_object(object, uid, idxs, update_metadata)
# BBB: for Zope 2.8.0
# copied from revision 31005 of ZCatalog.py
Modified: CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py 2005-08-01 18:42:53 UTC (rev 37629)
+++ CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py 2005-08-01 18:44:41 UTC (rev 37630)
@@ -72,7 +72,7 @@
self.obs = []
def indexObject(self, ob):
self.log.append('index %s' % physicalpath(ob))
- def reindexObject(self, ob, idxs=[], update_metadata=0):
+ def reindexObject(self, ob, idxs=[], update_metadata=0, uid=None):
self.log.append('reindex %s %s' % (physicalpath(ob), idxs))
def unindexObject(self, ob):
self.log.append('unindex %s' % physicalpath(ob))
@@ -83,9 +83,6 @@
for ob, obpath in self.obs:
if not (obpath+'/').startswith(path+'/'):
continue
- if obpath == path:
- # Normal PathIndex skips initial value
- continue
res.append(self.brain_class(ob, obpath))
return res
More information about the CMF-checkins
mailing list