Commit 2e35fa17 authored by Vincent Pelletier's avatar Vincent Pelletier

Folder: add reindex_on_commit argument to newContent

To remove the need to directly call immediate reindexation methods,
allowing to prevent further misuses of these.
parent a5e91ad3
......@@ -101,10 +101,17 @@ class FolderMixIn(ExtensionClass.Base):
security.declarePublic('newContent')
def newContent(self, id=None, portal_type=None, id_group=None,
default=None, method=None, container=None, temp_object=0, **kw):
default=None, method=None, container=None, temp_object=0,
reindex_on_commit=False, **kw):
"""Creates a new content.
This method is public, since TypeInformation.constructInstance will perform
the security check.
reindex_on_commit (bool)
Immediately recursively reindex this document on transaction commit, so
it is available in catalog for the next transaction. Useful when
redirecting the user to a page which requires a catalog lookup to display
this newly-created document.
"""
pt = self._getTypesTool()
if container is None:
......@@ -154,7 +161,13 @@ class FolderMixIn(ExtensionClass.Base):
# make sure another zope hasn't started to migrate to HBTree
connection = self._p_jar
connection is None or connection.readCurrent(self)
if reindex_on_commit:
# Immediately reindexing document that we just created is safe, as no
# other transaction can by definition see it, so there cannot be a race
# condition leading to stale catalog content.
transaction.get().addBeforeCommitHook(
self.recursiveImmediateReindexObject,
)
return new_instance
security.declareProtected(
......
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