Skip to content

Commit 51f4bea

Browse files
author
NatePage
committed
Remove detachOnDelete option and always detach soft-deleted object from entity manager.
1 parent 50e170d commit 51f4bea

File tree

7 files changed

+7
-121
lines changed

7 files changed

+7
-121
lines changed

lib/Gedmo/Mapping/Annotation/SoftDeleteable.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,4 @@ final class SoftDeleteable extends Annotation
2323

2424
/** @var bool */
2525
public $hardDelete = true;
26-
27-
/** @var bool */
28-
public $detachOnDelete = false;
2926
}

lib/Gedmo/SoftDeleteable/Mapping/Driver/Annotation.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ public function readExtendedMetadata($meta, array &$config)
5252
}
5353
$config['hardDelete'] = $annot->hardDelete;
5454
}
55-
56-
$config['detachOnDelete'] = false;
57-
if (isset($annot->detachOnDelete)) {
58-
if (!is_bool($annot->detachOnDelete)) {
59-
throw new InvalidMappingException("detachOnDelete must be boolean. ".gettype($annot->detachOnDelete)." provided.");
60-
}
61-
$config['detachOnDelete'] = $annot->detachOnDelete;
62-
}
6355
}
6456

6557
$this->validateFullMetadata($meta, $config);

lib/Gedmo/SoftDeleteable/Mapping/Driver/Xml.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ public function readExtendedMetadata($meta, array &$config)
5353
if ($this->_isAttributeSet($xml->{'soft-deleteable'}, 'hard-delete')) {
5454
$config['hardDelete'] = $this->_getBooleanAttribute($xml->{'soft-deleteable'}, 'hard-delete');
5555
}
56-
57-
$config['detachOnDelete'] = false;
58-
if ($this->_isAttributeSet($xml->{'soft-deleteable'}, 'detach-on-delete')) {
59-
$config['detachOnDelete'] = $this->_getBooleanAttribute($xml->{'soft-deleteable'}, 'detach-on-delete');
60-
}
6156
}
6257
}
6358
}

lib/Gedmo/SoftDeleteable/Mapping/Driver/Yaml.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ public function readExtendedMetadata($meta, array &$config)
6262
}
6363
$config['hardDelete'] = $classMapping['soft_deleteable']['hard_delete'];
6464
}
65-
66-
$config['detachOnDelete'] = false;
67-
if (isset($classMapping['soft_deleteable']['detach_on_delete'])) {
68-
if (!is_bool($classMapping['soft_deleteable']['detach_on_delete'])) {
69-
throw new InvalidMappingException("detachOnDelete must be boolean. ".gettype($classMapping['soft_deleteable']['detach_on_delete'])." provided.");
70-
}
71-
$config['detachOnDelete'] = $classMapping['soft_deleteable']['detach_on_delete'];
72-
}
7365
}
7466
}
7567
}

lib/Gedmo/SoftDeleteable/SoftDeleteableListener.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ public function onFlush(EventArgs $args)
9999
$ea->createLifecycleEventArgsInstance($object, $om)
100100
);
101101

102-
if (isset($config['detachOnDelete']) && $config['detachOnDelete']) {
103-
$this->softDeletedObjects[] = $object;
104-
}
102+
$this->softDeletedObjects[] = $object;
105103
}
106104
}
107105
}
@@ -112,20 +110,16 @@ public function onFlush(EventArgs $args)
112110
* @param \Doctrine\Common\EventArgs $args
113111
*
114112
* @return void
113+
*
114+
* @throws \Gedmo\Exception\InvalidArgumentException
115115
*/
116116
public function postFlush(EventArgs $args)
117117
{
118118
$ea = $this->getEventAdapter($args);
119119
$om = $ea->getObjectManager();
120120

121121
foreach ($this->softDeletedObjects as $index => $object) {
122-
$meta = $om->getClassMetadata(get_class($object));
123-
$config = $this->getConfiguration($om, $meta->name);
124-
125-
if (isset($config['detachOnDelete']) && $config['detachOnDelete']) {
126-
$om->detach($object);
127-
}
128-
122+
$om->detach($object);
129123
unset($this->softDeletedObjects[$index]);
130124
}
131125
}

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

Lines changed: 0 additions & 54 deletions
This file was deleted.

tests/Gedmo/SoftDeleteable/SoftDeleteableEntityTest.php

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Gedmo\SoftDeleteable;
44

5-
use SoftDeleteable\Fixture\Entity\UserDetachOnDelete;
65
use SoftDeleteable\Fixture\Entity\UserNoHardDelete;
76
use Tool\BaseTestCaseORM;
87
use Doctrine\Common\EventManager;
@@ -38,7 +37,6 @@ class SoftDeleteableEntityTest extends BaseTestCaseORM
3837
const MAPPED_SUPERCLASS_CHILD_CLASS = 'SoftDeleteable\Fixture\Entity\Child';
3938
const SOFT_DELETEABLE_FILTER_NAME = 'soft-deleteable';
4039
const USER_NO_HARD_DELETE_CLASS = 'SoftDeleteable\Fixture\Entity\UserNoHardDelete';
41-
const USER_DETACH_ON_DELETE = 'SoftDeleteable\Fixture\Entity\UserDetachOnDelete';
4240

4341
private $softDeleteableListener;
4442

@@ -81,39 +79,12 @@ public function shouldBeAbleToHardDeleteSoftdeletedItems()
8179
/**
8280
* @test
8381
*/
84-
public function shouldNeedToClearEntityManagerNotToFetchSoftDeletedItemById()
82+
public function shouldNotFetchSoftDeletedItemByIdIfDetachOnDeleteEnabled()
8583
{
8684
$repo = $this->em->getRepository(self::USER_CLASS);
8785

8886
$newUser = new User();
89-
$newUser->setUsername($username = 'test_user');
90-
91-
$this->em->persist($newUser);
92-
$this->em->flush();
93-
94-
$userId = $newUser->getId();
95-
96-
$this->em->remove($newUser);
97-
$this->em->flush();
98-
99-
$user = $repo->find($userId);
100-
$this->assertInstanceOf(self::USER_CLASS, $user);
101-
102-
$this->em->clear();
103-
104-
$user = $repo->find($userId);
105-
$this->assertNull($user);
106-
}
107-
108-
/**
109-
* @test
110-
*/
111-
public function shouldNotFetchSoftDeletedItemByIdIfDetachOnDeleteEnabled()
112-
{
113-
$repo = $this->em->getRepository(self::USER_DETACH_ON_DELETE);
114-
115-
$newUser = new UserDetachOnDelete();
116-
$newUser->setUsername($username = 'test_user');
87+
$newUser->setUsername('test_user');
11788

11889
$this->em->persist($newUser);
11990
$this->em->flush();
@@ -471,8 +442,7 @@ protected function getUsedEntityFixtures()
471442
self::OTHER_ARTICLE_CLASS,
472443
self::OTHER_COMMENT_CLASS,
473444
self::MAPPED_SUPERCLASS_CHILD_CLASS,
474-
self::USER_NO_HARD_DELETE_CLASS,
475-
self::USER_DETACH_ON_DELETE
445+
self::USER_NO_HARD_DELETE_CLASS
476446
);
477447
}
478448
}

0 commit comments

Comments
 (0)