Skip to content

Commit

Permalink
Fix handling of upserts during scheduling for deletion (#2334)
Browse files Browse the repository at this point in the history
* Fix handling of upserts during scheduling for deletion

* Added test
  • Loading branch information
webmozart authored Jun 29, 2021
1 parent 5aa06c0 commit f20b3cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/ODM/MongoDB/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,10 @@ public function scheduleForDelete(object $document, bool $isView = false): void
unset($this->documentUpdates[$oid]);
}

if (isset($this->documentUpserts[$oid])) {
unset($this->documentUpserts[$oid]);
}

if (isset($this->documentDeletions[$oid])) {
return;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ public function testRegisterRemovedOnNewEntityIsIgnored()
$this->assertFalse($this->uow->isScheduledForDelete($user));
}

public function testScheduleForDeleteShouldUnregisterScheduledUpserts()
{
$class = $this->dm->getClassMetadata(ForumUser::class);
$user = new ForumUser();
$user->id = new ObjectId();
$this->assertFalse($this->uow->isScheduledForInsert($user));
$this->assertFalse($this->uow->isScheduledForUpsert($user));
$this->assertFalse($this->uow->isScheduledForDelete($user));
$this->uow->scheduleForUpsert($class, $user);
$this->assertFalse($this->uow->isScheduledForInsert($user));
$this->assertTrue($this->uow->isScheduledForUpsert($user));
$this->assertFalse($this->uow->isScheduledForDelete($user));
$this->uow->scheduleForDelete($user);
$this->assertFalse($this->uow->isScheduledForInsert($user));
$this->assertFalse($this->uow->isScheduledForUpsert($user));
$this->assertTrue($this->uow->isScheduledForDelete($user));
}

public function testThrowsOnPersistOfMappedSuperclass()
{
$this->expectException(MongoDBException::class);
Expand Down

0 comments on commit f20b3cd

Please sign in to comment.