Closed
Description
I would like to hard-delete a record by disabling the filter but it doesn't work because listeners are already active on my entity.
I find a solution but it's not perfect:
$manager->getFilters()->disable('softdeleteable');
foreach ($manager->getEventManager()->getListeners() as $eventName => $listeners) {
foreach ($listeners as $listener) {
if ($listener instanceof \Gedmo\SoftDeleteable\SoftDeleteableListener) {
$manager->getEventManager()->removeEventListener($eventName, $listener);
}
}
}
Do you have another solution ?
Thank's
Activity
[-]Disable softdeleteable filter doesn't disabled Listener[/-][+]Disable softdeleteable filter doesn't disabled Listeners[/+]gitomato commentedon Dec 10, 2014
Hello, it may be a typo.
Can you try with :
https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/softdeleteable.md#setup-and-autoloading
Garfield-fr commentedon Dec 23, 2014
and in my function
The record is not deleted from my db, it's marked deleted with date and time. Disabled filter don't deactivated softdeletable listener.
Any solution ?
Thank's
appeltaert commentedon Oct 19, 2015
same, doesnt seem fixed 1 year later? theres no way to disable them now. @Garfield-fr did you find a solution?
max-kovpak commentedon Oct 20, 2015
You can create your own event listener something like this:
in your config:
keksa commentedon Jun 6, 2016
For anyone still wondering about this. It is possible to hard delete softdeleteable entity with provided listener by setting the
deletedAt
field to DateTime object.So for example this would hard delete user entity:
This code in Gedmo listener provides that:
cadavre commentedon Nov 3, 2017
Wait a second...
Doesn't it mean that if you call
$em->remove($entity)
for a second time (on already soft-deleted entity) it will remove it from DB?Deveosys commentedon Jan 29, 2018
Exactly, it's up to you not to make the deletion actions available on soft deleted objects
l3pp4rd commentedon Jan 29, 2018
there is an option now to prevent hard deletion on second call and any other, see the doc for softdelete
github-actions commentedon Nov 25, 2021
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
sdev-maxime commentedon Feb 23, 2022
Update:
in SoftDeleteableListener.php
So, configuration in entity file can be
Then, there is some new behaviors.
How delete without removing twice ? just add new \DateTime() to deleted at field.
Hope this will help =)