1

Im using SonataAdminBundle - more specificly the SonataORMAdminBundle with Doctrine - to do some of my administration. So far this turned out to be a really useful Bundle, however a senseful deletion of entities is somewhat tricky.

Consider a Tour entity has a Truck and a Trailer entity, but when a Truck is being discarded it should no longer appear in the overall Admin Application. Nevertheless, there might still exists legacy Tour entities with a relation to this Truck.

So it is unclear how to tackle this problem when a user might edit such a legacy Tour in the admin, is the entity selection gone?

I've taken a look at the SoftDelete Extension Bundles, but it seems to come with a lot of work for adjusting all the specific cases.

Is there a simple approach at the Bundle Level or in Doctrine in General tackle those kind of problems?

worenga
  • 5,776
  • 2
  • 28
  • 50
  • Don't know about Sonata but I got soft delete to work quite well in EF - including the navigation properties. http://stackoverflow.com/a/18985828/150342 – Colin Nov 19 '13 at 04:39
  • @Colin EF (.NET) is totally unrelated to Doctrine (PHP) – sroes Nov 21 '13 at 10:24
  • I think the [SoftDeleteable behavior](https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/softdeleteable.md) is the simplest/best approach – sroes Nov 21 '13 at 10:27
  • @sroes Yeah, I did wonder why it was tagged entity framework – Colin Nov 21 '13 at 10:31

1 Answers1

3

The way this behavior is implemented when needed in the Sonata suite is through a new boolean field in the entity: 'enabled'. We then add a filter on it to display it or not, and never actually delete the object in the usage. Soft-deletion being a client-specific operation (you might have dedicated business rules along with it), we didn't implement it natively in the Sonata suite. Your implementation should depend on your needs in this case.

We however integrated the EntityAuditBundle from Simplethings (https://github.com/simplethings/EntityAudit) in the SonataDoctrineORMAdminBundle: each entity which has an Admin class is audited automatically. This allows to track each edit done on the audited entities. (Not necessarily what you're looking for but might be interesting nonetheless).

Finally, as you mentioned, SoftDelete might do the trick for you. But you might rather have your own event listeners (using preRemove for instance) and implement your solution your own way.

If you think your solution might be worth integration in the SonataDoctrineORMAdminBundle, feel free to create an issue on github, and we'll discuss it.

Hugo Briand
  • 1,683
  • 20
  • 27