From fbcf644b8199b72f9df404081c343183a8b8ffcc Mon Sep 17 00:00:00 2001 From: Niels Keurentjes Date: Thu, 11 Apr 2024 10:22:26 +0200 Subject: [PATCH] Remove PARTIAL syntax in DQL --- CHANGELOG.md | 6 +++++- composer.json | 13 +++++++++---- src/Adapter/Doctrine/FetchJoinORMAdapter.php | 1 - src/Adapter/Doctrine/ORM/AutomaticQueryBuilder.php | 10 ++++------ src/Adapter/Doctrine/ORMAdapter.php | 1 - 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40b3f54..43dcdad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,11 @@ All notable changes to `omines\datatables-bundle` will be documented in this fil This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -Nothing yet. +### Added + - Support Doctrine ORM 3 and DBAL 4 + +### Breaking + - Remove support for partial DQL queries in `AutomaticQueryBuilder` ## [0.8.2] - 2024-03-24 ### Added diff --git a/composer.json b/composer.json index 78e375d..977a572 100644 --- a/composer.json +++ b/composer.json @@ -35,19 +35,19 @@ "ext-zip": "*", "doctrine/common": "^3.4.3", "doctrine/doctrine-bundle": "^2.12.0", - "doctrine/orm": "^2.19.3", + "doctrine/orm": "^2.19.3|^3.1.0", "doctrine/persistence": "^3.3.2", "friendsofphp/php-cs-fixer": "^3.52.1", "mongodb/mongodb": "^1.17.1", "ocramius/package-versions": "^2.8", "openspout/openspout": "^4.23", - "phpoffice/phpspreadsheet": "^1.29.0 || ^2.0", + "phpoffice/phpspreadsheet": "^1.29.0|^2.0", "phpstan/extension-installer": "^1.3.1", "phpstan/phpstan": "^1.10.65", "phpstan/phpstan-doctrine": "^1.3.64", "phpstan/phpstan-phpunit": "^1.3.16", "phpstan/phpstan-symfony": "^1.3.9", - "phpunit/phpunit": "^10.5.10 || ^11.0.8", + "phpunit/phpunit": "^10.5.10|^11.0.8", "ruflin/elastica": "^6.2|^7.3.2", "symfony/browser-kit": "^6.3|^7.0.3", "symfony/css-selector": "^6.3|^7.0.3", @@ -60,6 +60,11 @@ "symfony/var-dumper": "^6.3|^7.0.4", "symfony/yaml": "^6.3|^7.0.3" }, + "conflict": { + "doctrine/dbal": "<3 >=5", + "doctrine/orm": "<2.8 >=4", + "elasticsearch/elasticsearch": ">=9" + }, "suggest": { "doctrine/doctrine-bundle": "For integrated access to Doctrine object managers", "doctrine/orm": "For full automated integration with Doctrine entities", @@ -84,7 +89,7 @@ }, "extra": { "branch-alias": { - "dev-master": "0.8-dev" + "dev-master": "0.9-dev" } } } diff --git a/src/Adapter/Doctrine/FetchJoinORMAdapter.php b/src/Adapter/Doctrine/FetchJoinORMAdapter.php index c2d5b61..887d746 100644 --- a/src/Adapter/Doctrine/FetchJoinORMAdapter.php +++ b/src/Adapter/Doctrine/FetchJoinORMAdapter.php @@ -142,7 +142,6 @@ protected function getSimpleTotalCount(QueryBuilder $queryBuilder): int /** @var Query\Expr\From $from_expr */ $from_expr = $queryBuilder->getDQLPart('from')[0]; - /* @phpstan-ignore-next-line Unable to determine repository type */ return $this->manager->getRepository($from_expr->getFrom())->count([]); } } diff --git a/src/Adapter/Doctrine/ORM/AutomaticQueryBuilder.php b/src/Adapter/Doctrine/ORM/AutomaticQueryBuilder.php index 17e76ee..edfbf51 100644 --- a/src/Adapter/Doctrine/ORM/AutomaticQueryBuilder.php +++ b/src/Adapter/Doctrine/ORM/AutomaticQueryBuilder.php @@ -25,6 +25,8 @@ */ class AutomaticQueryBuilder implements QueryBuilderProcessorInterface { + private const DEFAULT_ALIAS = 'entity'; + private EntityManagerInterface $em; private ClassMetadata $metadata; private string $entityShortName; @@ -44,7 +46,7 @@ public function __construct(EntityManagerInterface $em, ClassMetadata $metadata) $this->metadata = $metadata; $this->entityName = $this->metadata->getName(); - $this->entityShortName = mb_strtolower($this->metadata->getReflectionClass()->getShortName()); + $this->entityShortName = mb_strtolower($this->metadata->getReflectionClass()?->getShortName() ?? self::DEFAULT_ALIAS); } public function process(QueryBuilder $builder, DataTableState $state): void @@ -135,11 +137,7 @@ private function setIdentifierFromAssociation(string $association, string $key, private function setSelectFrom(QueryBuilder $qb): void { foreach ($this->selectColumns as $key => $value) { - if (false === empty($key)) { - $qb->addSelect('partial ' . $key . '.{' . implode(',', $value) . '}'); - } else { - $qb->addSelect($value); - } + $qb->addSelect($key ?: $value); } } diff --git a/src/Adapter/Doctrine/ORMAdapter.php b/src/Adapter/Doctrine/ORMAdapter.php index 6c65f34..3b39e86 100644 --- a/src/Adapter/Doctrine/ORMAdapter.php +++ b/src/Adapter/Doctrine/ORMAdapter.php @@ -130,7 +130,6 @@ protected function getAliases(AdapterQuery $query): array /** @var Query\Expr\From $from */ foreach ($builder->getDQLPart('from') as $from) { - /* @phpstan-ignore-next-line */ $aliases[$from->getAlias()] = [null, $this->manager->getMetadataFactory()->getMetadataFor($from->getFrom())]; }