Skip to content

Commit

Permalink
Merge pull request #1917 from Atlantic18/revert-1868-remove-soft-dele…
Browse files Browse the repository at this point in the history
…ted-objects-from-cache

Revert "[SoftDeleteable] Detach soft-deleted objects from entity manager after flush"
  • Loading branch information
l3pp4rd authored May 8, 2018
2 parents f61d144 + 1150926 commit 1e400fb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 53 deletions.
30 changes: 0 additions & 30 deletions lib/Gedmo/SoftDeleteable/SoftDeleteableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ class SoftDeleteableListener extends MappedEventSubscriber
*/
const POST_SOFT_DELETE = "postSoftDelete";

/**
* Objects soft-deleted on flush.
*
* @var array
*/
private $softDeletedObjects = array();

/**
* {@inheritdoc}
*/
Expand All @@ -44,7 +37,6 @@ public function getSubscribedEvents()
return array(
'loadClassMetadata',
'onFlush',
'postFlush'
);
}

Expand Down Expand Up @@ -100,32 +92,10 @@ public function onFlush(EventArgs $args)
self::POST_SOFT_DELETE,
$ea->createLifecycleEventArgsInstance($object, $om)
);

$this->softDeletedObjects[] = $object;
}
}
}

/**
* Detach soft-deleted objects from object manager.
*
* @param \Doctrine\Common\EventArgs $args
*
* @return void
*
* @throws \Gedmo\Exception\InvalidArgumentException
*/
public function postFlush(EventArgs $args)
{
$ea = $this->getEventAdapter($args);
$om = $ea->getObjectManager();

foreach ($this->softDeletedObjects as $index => $object) {
$om->detach($object);
unset($this->softDeletedObjects[$index]);
}
}

/**
* Maps additional metadata
*
Expand Down
24 changes: 1 addition & 23 deletions tests/Gedmo/SoftDeleteable/SoftDeleteableEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,6 @@ public function shouldBeAbleToHardDeleteSoftdeletedItems()
$this->assertNull($user);
}

/**
* @test
*/
public function shouldNotFetchSoftDeletedItemByIdIfDetachOnDeleteEnabled()
{
$repo = $this->em->getRepository(self::USER_CLASS);

$newUser = new User();
$newUser->setUsername('test_user');

$this->em->persist($newUser);
$this->em->flush();

$userId = $newUser->getId();

$this->em->remove($newUser);
$this->em->flush();

$user = $repo->find($userId);
$this->assertNull($user);
}

/**
* @test
*/
Expand Down Expand Up @@ -598,7 +576,7 @@ protected function getUsedEntityFixtures()
self::OTHER_ARTICLE_CLASS,
self::OTHER_COMMENT_CLASS,
self::MAPPED_SUPERCLASS_CHILD_CLASS,
self::USER_NO_HARD_DELETE_CLASS
self::USER_NO_HARD_DELETE_CLASS,
);
}
}

0 comments on commit 1e400fb

Please sign in to comment.