Last active
August 29, 2015 14:24
-
-
Save djaney/65d2dd3a89f115c4e9e8 to your computer and use it in GitHub Desktop.
Symfony2 soft delete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| services: | |
| task.subscriber: | |
| class: Arcanys\TrainingBundle\EventListener\TaskEventListener | |
| tags: | |
| - { name: doctrine.event_subscriber, connection: default } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php namespace Arcanys\TrainingBundle\EventListener; | |
| use Doctrine\Common\EventSubscriber; | |
| use Doctrine\ORM\Event\LifecycleEventArgs; | |
| use Doctrine\ORM\Events; | |
| use Arcanys\TrainingBundle\Entity\Task; | |
| class TaskEventListener implements EventSubscriber{ | |
| public function getSubscribedEvents() | |
| { | |
| return array( | |
| Events::preRemove, | |
| ); | |
| } | |
| public function preRemove(LifecycleEventArgs $args) | |
| { | |
| $entity = $args->getEntity(); | |
| if ($entity instanceof Task) { | |
| $em = $args->getEntityManager(); | |
| $entity->setDeleted(true); | |
| $em->detach($entity); | |
| $entity->setDeleted(true); | |
| $em->merge($entity); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment