Skip to content

Commit 1d41d8b

Browse files
committed
Revert "Resolved a bug where a soft-deleted object isn't remove from the ObjectManager"
This reverts commit 211b6fe. I find it unmotivated to clear the cache of the object manager at flush. See the discussion at doctrine-extensions#2930.
1 parent 3ca38e8 commit 1d41d8b

File tree

5 files changed

+3
-76
lines changed

5 files changed

+3
-76
lines changed

CHANGELOG.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ a release.
2323
### Fixed
2424
- Compatibility with `doctrine/mongodb-odm` ^2.11 (#2945)
2525

26-
## [3.20.0] - 2025-04-04
27-
### Fixed
28-
- SoftDeleteable: Resolved a bug where a soft-deleted object isn't remove from the ObjectManager (#2930)
29-
3026
### Added
3127
- IP address provider for use with extensions with IP address references (#2928)
3228

@@ -114,7 +110,7 @@ a release.
114110
- Dropped support for doctrine/dbal < 3.2
115111

116112
### Deprecated
117-
- Calling `Gedmo\Mapping\Event\Adapter\ORM::getObjectManager()` and `getObject()` on EventArgs that do not implement `getObjectManager()` and `getObject()` (such as old EventArgs implementing `getEntityManager()` and `getEntity()`)
113+
- Calling `Gedmo\Mapping\Event\Adapter\ORM::getObjectManager()` and `getObject()` on EventArgs that do not implement `getObjectManager()` and `getObject()` (such as old EventArgs implementing `getEntityManager()` and `getEntity()`)
118114
- Calling `Gedmo\Uploadable\Event\UploadableBaseEventArgs::getEntityManager()` and `getEntity()`. Call `getObjectManager()` and `getObject()` instead.
119115

120116
## [3.13.0] - 2023-09-06

src/SoftDeleteable/SoftDeleteableListener.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ class SoftDeleteableListener extends MappedEventSubscriber
5151
*/
5252
public const POST_SOFT_DELETE = 'postSoftDelete';
5353

54-
/**
55-
* Objects soft-deleted on flush.
56-
*
57-
* @var array<object>
58-
*/
59-
private array $softDeletedObjects = [];
60-
6154
/**
6255
* @return string[]
6356
*/
@@ -66,7 +59,6 @@ public function getSubscribedEvents()
6659
return [
6760
'loadClassMetadata',
6861
'onFlush',
69-
'postFlush',
7062
];
7163
}
7264

@@ -110,7 +102,7 @@ public function onFlush(EventArgs $args)
110102

111103
$evm->dispatchEvent(
112104
self::PRE_SOFT_DELETE,
113-
$preSoftDeleteEventArgs,
105+
$preSoftDeleteEventArgs
114106
);
115107
}
116108

@@ -137,27 +129,10 @@ public function onFlush(EventArgs $args)
137129
$postSoftDeleteEventArgs
138130
);
139131
}
140-
141-
$this->softDeletedObjects[] = $object;
142132
}
143133
}
144134
}
145135

146-
/**
147-
* Detach soft-deleted objects from object manager.
148-
*
149-
* @return void
150-
*/
151-
public function postFlush(EventArgs $args)
152-
{
153-
$ea = $this->getEventAdapter($args);
154-
$om = $ea->getObjectManager();
155-
foreach ($this->softDeletedObjects as $index => $object) {
156-
$om->detach($object);
157-
unset($this->softDeletedObjects[$index]);
158-
}
159-
}
160-
161136
/**
162137
* Maps additional metadata
163138
*

tests/Gedmo/Blameable/Fixture/Entity/Article.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Article implements Blameable
4848
* @ORM\OneToMany(targetEntity="Gedmo\Tests\Blameable\Fixture\Entity\Comment", mappedBy="article")
4949
*/
5050
#[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'article')]
51-
private Collection $comments;
51+
private $comments;
5252

5353
/**
5454
* @Gedmo\Blameable(on="create")

tests/Gedmo/SoftDeleteable/Fixture/Entity/Article.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,4 @@ public function addComment(Comment $comment): void
9292
{
9393
$this->comments[] = $comment;
9494
}
95-
96-
/**
97-
* @return Collection<int, Comment>
98-
*/
99-
public function getComments(): Collection
100-
{
101-
return $this->comments;
102-
}
10395
}

tests/Gedmo/SoftDeleteable/SoftDeleteableEntityTest.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -522,42 +522,6 @@ public function testShouldFilterBeQueryCachedCorrectlyWhenToggledForEntity(): vo
522522
static::assertCount(0, $data);
523523
}
524524

525-
public function testSoftDeletedObjectIsRemovedPostFlush(): void
526-
{
527-
$repo = $this->em->getRepository(Article::class);
528-
$commentRepo = $this->em->getRepository(Comment::class);
529-
530-
$comment = new Comment();
531-
$commentValue = 'Comment 1';
532-
$comment->setComment($commentValue);
533-
534-
$art0 = new Article();
535-
$field = 'title';
536-
$value = 'Title 1';
537-
$art0->setTitle($value);
538-
$art0->addComment($comment);
539-
540-
$this->em->persist($art0);
541-
$this->em->flush();
542-
543-
$art = $repo->findOneBy([$field => $value]);
544-
545-
static::assertNull($art->getDeletedAt());
546-
static::assertNull($comment->getDeletedAt());
547-
static::assertCount(1, $art->getComments());
548-
549-
$this->em->remove($comment);
550-
551-
// The Comment has been marked for removal, but not yet flushed. This means the
552-
// Comment should still be available.
553-
static::assertInstanceOf(Comment::class, $commentRepo->find($comment->getId()));
554-
555-
$this->em->flush();
556-
557-
// Now that we've flushed, the Comment should no longer be available and should return null.
558-
static::assertNull($commentRepo->find($comment->getId()));
559-
}
560-
561525
public function testPostSoftDeleteEventIsDispatched(): void
562526
{
563527
$this->em->getEventManager()->addEventSubscriber(new WithPreAndPostSoftDeleteEventArgsTypeListener());

0 commit comments

Comments
 (0)