Skip to content
This repository

fixes triggering fatal error on preupdate event in case changeset is clea #151

Merged
merged 1 commit into from over 2 years ago

2 participants

Gediminas Morkevicius Jonathan H. Wage
Gediminas Morkevicius

fixes triggering fatal error on preupdate event in case changeset is cleared during onFlush

similar issue is fixed in ORM it should be supported on ODM mongodb also

Jonathan H. Wage jwage merged commit 9e0b7dd into from September 01, 2011
Jonathan H. Wage jwage closed this September 01, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 23, 2011
Gediminas Morkevicius fixes triggering fatal error on preupdate event in case changeset is …
…cleared during onFlush
941c821
This page is out of date. Refresh to see the latest.
4  lib/Doctrine/ODM/MongoDB/UnitOfWork.php
@@ -911,7 +911,7 @@ private function executeUpdates(ClassMetadata $class, array $options = array())
911 911
                         $this->recomputeSingleDocumentChangeSet($class, $document);
912 912
                     }
913 913
 
914  
-                    if ($hasPreUpdateListeners) {
  914
+                    if ($hasPreUpdateListeners && isset($this->documentChangeSets[$oid])) {
915 915
                         $this->evm->dispatchEvent(Events::preUpdate, new Event\PreUpdateEventArgs(
916 916
                             $document, $this->dm, $this->documentChangeSets[$oid])
917 917
                         );
@@ -919,7 +919,7 @@ private function executeUpdates(ClassMetadata $class, array $options = array())
919 919
                     $this->cascadePreUpdate($class, $document);
920 920
                 }
921 921
 
922  
-                if ( ! $class->isEmbeddedDocument) {
  922
+                if ( ! $class->isEmbeddedDocument && isset($this->documentChangeSets[$oid])) {
923 923
                     $persister->update($document, $options);
924 924
                 }
925 925
                 unset($this->documentUpdates[$oid]);
31  tests/Doctrine/ODM/MongoDB/Tests/Mocks/PreUpdateListenerMock.php
... ...
@@ -0,0 +1,31 @@
  1
+<?php
  2
+
  3
+namespace Doctrine\ODM\MongoDB\Tests\Mocks;
  4
+
  5
+use Doctrine\ODM\MongoDB\Event\OnFlushEventArgs;
  6
+use Doctrine\ODM\MongoDB\Event\PreUpdateEventArgs;
  7
+use Doctrine\Common\EventSubscriber;
  8
+
  9
+class PreUpdateListenerMock implements EventSubscriber
  10
+{
  11
+    public function getSubscribedEvents()
  12
+    {
  13
+        return array(
  14
+            'onFlush',
  15
+            'preUpdate'
  16
+        );
  17
+    }
  18
+
  19
+    public function onFlush(OnFlushEventArgs $args)
  20
+    {
  21
+        $uow = $args->getDocumentManager()->getUnitOfWork();
  22
+        foreach ($uow->getScheduledDocumentUpdates() as $document) {
  23
+            $uow->clearDocumentChangeSet(spl_object_hash($document));
  24
+        }
  25
+    }
  26
+
  27
+    public function preUpdate(PreUpdateEventArgs $args)
  28
+    {
  29
+        return; // fatal error
  30
+    }
  31
+}
17  tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php
@@ -218,6 +218,23 @@ public function testParentAssociations()
218 218
         $this->assertEquals(array(array('name' => 'd'), $c, 'b.c.d'), $unitOfWork->getParentAssociation($d));
219 219
     }
220 220
 
  221
+    public function testPreUpdateTriggeredWithEmptyChangeset()
  222
+    {
  223
+        $dm = DocumentManagerMock::create();
  224
+        $evm = $dm->getEventManager()->addEventSubscriber(
  225
+            new \Doctrine\ODM\MongoDB\Tests\Mocks\PreUpdateListenerMock()
  226
+        );
  227
+        $user = new \Documents\ForumUser();
  228
+        $user->username = '12345';
  229
+
  230
+        $dm->persist($user);
  231
+        $dm->flush();
  232
+
  233
+        $user->username = '1234';
  234
+        $dm->persist($user);
  235
+        $dm->flush();
  236
+    }
  237
+
221 238
     protected function getDocumentManager()
222 239
     {
223 240
         return new \Stubs\DocumentManager();
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.