You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 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.
if (isset($config['hardDelete']) && $config['hardDelete'] && $oldValueinstanceof \DateTimeInterface && $oldValue <= $date) {
continue; // want to hard delete
}
So, configuration in entity file can be
/** * @ORM\Entity(repositoryClass=MyEntityRepository::class) * @ORM\Table(name="my_table_name") * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true) <==== SET hardDelete to true */class MyEntity { ... }
Then, there is some new behaviors.
The first time you'll remove an entity, the entity fill deleteAt field and store/save in database : classic behavior of softdeleteable.
If you remove a second time the same entity (with configured hardDelete=true in entity file), the entity will be deleted in database, cause it was already soft-deleted and have deleted at field filled: hard delete behavior after soft delete (very cool).
$entity = newEntity();
$this->em->persist($entity);
$this->em->flush();
// create entity in database$this->em->remove($entity);
$this->em->flush();
// Now entity has deletedAt field filled -> is soft-deleted$this->em->remove($entity);
$this->em->flush();
// Now entity is hard deleted, no anymore in database.
How delete without removing twice ? just add new \DateTime() to deleted at field.
$entity = newEntity();
$this->em->persist($entity);
$this->em->flush();
// Here I have a new entity saved in database$entity->setDeletedAt(new \DateTime());
$this->em->remove($entity);
$this->em->flush();
// Now entity is hard deleted, no anymore in database. due to the DateTimeInterface condition on top off the topic.
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 =)