Skip to content

Commit

Permalink
Merge 4.x into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Nov 9, 2022
2 parents 1fd8e95 + 67846d4 commit b952739
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# It's auto-generated by sonata-project/dev-kit package.

github: [VincentLanglet, greg0ire, OskarStark, jordisala1991]
github: [VincentLanglet, greg0ire, jordisala1991, OskarStark]
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"twig/twig": "^2.10 || ^3.0"
},
"require-dev": {
"dama/doctrine-test-bundle": "^6.7",
"doctrine/doctrine-fixtures-bundle": "^3.4",
"friendsofphp/php-cs-fixer": "^3.4",
"phpstan/extension-installer": "^1.0",
Expand All @@ -55,8 +56,8 @@
"phpstan/phpstan-strict-rules": "^1.0",
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.17",
"psalm/plugin-symfony": "^3.0",
"psalm/plugin-phpunit": "^0.18",
"psalm/plugin-symfony": "^4.0",
"rector/rector": "^0.14",
"sonata-project/block-bundle": "^4.2",
"sonata-project/entity-audit-bundle": "^1.1",
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ It's auto-generated by sonata-project/dev-kit package.

<extensions>
<extension class="Symfony\Component\Panther\ServerExtension" />
<extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
</extensions>

<php>
Expand Down
17 changes: 13 additions & 4 deletions src/Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,20 @@ public function batchDelete(string $class, BaseProxyQueryInterface $query): void
throw new \TypeError(sprintf('The query MUST implement %s.', ProxyQueryInterface::class));
}

try {
$entityManager = $this->getEntityManager($class);
if ([] !== $query->getQueryBuilder()->getDQLPart('join')) {
$rootAlias = current($query->getQueryBuilder()->getRootAliases());

// Distinct is needed to iterate, even if group by is used
// @see https://github.com/doctrine/orm/issues/5868
$query->getQueryBuilder()->distinct();
$query->getQueryBuilder()->select($rootAlias);
}

$i = 0;
foreach ($query->execute() as $object) {
$entityManager = $this->getEntityManager($class);
$i = 0;

try {
foreach ($query->getDoctrineQuery()->toIterable() as $object) {
$entityManager->remove($object);

if (0 === (++$i % 20)) {
Expand Down
2 changes: 2 additions & 0 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sonata\DoctrineORMAdminBundle\Tests\App;

use DAMA\DoctrineTestBundle\DAMADoctrineTestBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
use Knp\Bundle\MenuBundle\KnpMenuBundle;
Expand Down Expand Up @@ -41,6 +42,7 @@ public function registerBundles(): iterable
{
return [
new DoctrineBundle(),
new DAMADoctrineTestBundle(),
new FrameworkBundle(),
new KnpMenuBundle(),
new SecurityBundle(),
Expand Down
1 change: 1 addition & 0 deletions tests/App/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Book

/**
* @ORM\ManyToOne(targetEntity="Author", inversedBy="books")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id", onDelete="SET NULL")
*/
private ?Author $author;

Expand Down
47 changes: 47 additions & 0 deletions tests/Functional/BatchActionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\DoctrineORMAdminBundle\Tests\Functional;

use Symfony\Component\HttpFoundation\Request;

final class BatchActionsTest extends BaseFunctionalTestCase
{
/**
* @dataProvider provideDeleteBatchActionCases
*/
public function testDeleteBatchAction(string $url): void
{
$this->client->request(Request::METHOD_GET, $url);
$this->client->submitForm('OK', [
'all_elements' => true,
'action' => 'delete',
]);
$this->client->submitForm('Yes, execute');

self::assertSelectorTextContains('div.alert-success', 'Selected items have been successfully deleted.');
self::assertResponseIsSuccessful();
}

/**
* @return iterable<array<string>>
*
* @phpstan-return iterable<array{0: string}>
*/
public static function provideDeleteBatchActionCases(): iterable
{
yield 'Normal delete' => ['/admin/tests/app/book/list'];
yield 'Joined delete' => ['/admin/tests/app/author/list'];
yield 'More than 20 items delete' => ['/admin/tests/app/sub/list'];
}
}

0 comments on commit b952739

Please sign in to comment.