DDC-17: Ability to skip the operation from a pre-operation event handler #2347

doctrinebot opened this Issue Sep 20, 2009 · 1 comment

1 participant


Jira issue originally created by user itoijala:

In Doctrine 1.1 it is possible to skip the operation in the event handlers in DoctrineRecord_Listener using DoctrineEvent::skipOperation.

This no longer seems to be possible in Doctrine 2.0 Alpha 1, for example when handling a preRemove event to implement soft-delete behaviour. Perhaps a method could be added to \Doctrine\Common\EventArgs\LifecycleEventArgs to skip the operation, at least before the operation.

Without this implementing soft-delete would require the user to update deletedat and deletedby himself and then save the record. It could no longer be done automatically when removing a record because the record is then removed.


Comment created by romanb:

The problem is, full support for soft-delete throughout the system is not feasible and very fragile. Simple soft-delete through skipping the delete operation is the easiest part. Then you will probably want to modify all DQL queries so that they adhere to it automatically and then there will always be still queries that do NOT go through DQL, like even internal lazy-load queries or native queries or others, which would need to be modified also.

To sum it up, implementing soft-delete "inside" doctrine is absolutely not worth the effort and imho a bad idea and I'm certainly not willing to make lots of adjustments to the core that have a negative impact on performance just to make this soft-delete possible.

I really recommend handling "soft" deletes yourself, the normal way, by simply abstracting entity retrieval and persistence through a DAO/repository layer. As a nice side-effect you get less magic and it still works when you swap out doctrine for another persistence provider.

I am willing to add support for skipping deletes and maybe some other operations through events but I'm not willing to go any further, as explained above.

@doctrinebot doctrinebot added this to the 2.x milestone Dec 6, 2015
@Yunyun548 Yunyun548 referenced this issue in javiereguiluz/EasyAdminBundle Apr 26, 2016

Disable delete admin user #1104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment