feature #2883 Supporting Doctrine Lifecycle Events in batch delete action (fixes #2881) (liarco)
feature #2883 Supporting Doctrine Lifecycle Events in batch delete action (fixes #2881) (liarco)

This PR was merged into the 2.0.x-dev branch.

Discussion
----------

Supporting Doctrine Lifecycle Events in batch delete action (fixes #2881)

This PR is a fix suggested by @lorenx in #2881.

### Bug explanation
At the moment the `AdminControllerTrait::deleteBatchAction()` method uses a custom query builder to delete all entities at once. This works, but custom queries bypass Doctrine's [Lifecycle events](https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/events.html#lifecycle-events) so no event is fired on batch deletion.

The new implementation makes a single `SELECT` query to fetch all objects, but then runs the `remove()` method for each object to fire proper events.

### How to test
On any project with batch actions enabled, update your entity as follows:

```php
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * ...
 * @ORM\HasLifecycleCallbacks
 */
class AnyEntity
{
   // ...

    /** @ORM\PostRemove */
    public function doStuffOnPostRemove()
    {
        dd('PostRemove event!');
    }
}
```

Removing an object should now fail in any circumstance dumping `PostRemove event!`.

Commits
-------

7f7eb6ce Supporting Doctrine Lifecycle Events in batch delete action (fixes #2881)

OskarStark/EasyAdminBundle,OskarStark/EasyAdminBundle,javiereguiluz/EasyAdminBundle,javiereguiluz/EasyAdminBundle,OskarStark/EasyAdminBundle