diff --git a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php index d732dbc9d1..5641b6ee27 100644 --- a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php +++ b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php @@ -690,7 +690,7 @@ private function computeOrRecomputeChangeSet(ClassMetadata $class, $document, $r // and we have a copy of the original data $originalData = $this->originalDocumentData[$oid]; $isChangeTrackingNotify = $class->isChangeTrackingNotify(); - if ($isChangeTrackingNotify && ! $recompute) { + if ($isChangeTrackingNotify && ! $recompute && isset($this->documentChangeSets[$oid])) { $changeSet = $this->documentChangeSets[$oid]; } else { $changeSet = array(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php index c887c86080..35920aa6c5 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php @@ -240,6 +240,33 @@ public function testChangeTrackingNotify() $this->assertTrue($updates[0] === $item); } + public function testDoubleCommitWithChangeTrackingNotify() + { + $pb = $this->getMockPersistenceBuilder(); + + $class = $this->dm->getClassMetadata('Doctrine\ODM\MongoDB\Tests\NotifyChangedDocument'); + $persister = $this->getMockDocumentPersister($pb, $class); + $this->uow->setDocumentPersister($class->name, $persister); + + $entity = new NotifyChangedDocument(); + $entity->setId(2); + $this->uow->persist($entity); + + $this->uow->commit($entity); + + // Use a custom error handler that will fail the test if the next commit() call raises a notice error + set_error_handler(function() { + restore_error_handler(); + + $this->fail('Expected not to get a notice error after committing an entity multiple times using the NOTIFY change tracking policy.'); + }, E_NOTICE); + + $this->uow->commit($entity); + + // Restore previous error handler if no errors have been raised + restore_error_handler(); + } + public function testGetDocumentStateWithAssignedIdentity() { $pb = $this->getMockPersistenceBuilder(); @@ -686,7 +713,10 @@ public function __construct($name) } } -/** @ODM\Document */ +/** + * @ODM\Document + * @ODM\ChangeTrackingPolicy("NOTIFY") + */ class NotifyChangedDocument implements \Doctrine\Common\NotifyPropertyChanged { private $_listeners = array();