From 324d84b310b3ad55cf17fc95429bc257c4aacd67 Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Sun, 7 Jan 2018 22:35:28 +0100 Subject: [PATCH] Disallow nested commits --- lib/Doctrine/ODM/MongoDB/MongoDBException.php | 8 ++++++++ lib/Doctrine/ODM/MongoDB/UnitOfWork.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ODM/MongoDB/MongoDBException.php b/lib/Doctrine/ODM/MongoDB/MongoDBException.php index 7be96eee08..376d360a43 100644 --- a/lib/Doctrine/ODM/MongoDB/MongoDBException.php +++ b/lib/Doctrine/ODM/MongoDB/MongoDBException.php @@ -139,4 +139,12 @@ public static function failedToEnsureDocumentSharding($className, $errorMessage) $errorMessage )); } + + /** + * @return MongoDBException + */ + public static function commitInProgress() + { + return new self('There is already a commit operation in progress. Did you call flush from an event listener?'); + } } diff --git a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php index ff2c060d7a..56ddbde779 100644 --- a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php +++ b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php @@ -385,7 +385,7 @@ public function commit(array $options = array()) $this->commitsInProgress++; if ($this->commitsInProgress > 1) { - @trigger_error('There is already a commit operation in progress. Calling flush in an event subscriber is deprecated and will be forbidden in 2.0.', E_USER_DEPRECATED); + throw MongoDBException::commitInProgress(); } try { if ($this->orphanRemovals) {