Fix CI: Day/Hour DQL + QueryBuilder::select() for DBAL 4

(cherry picked from commit e20abd232d)
This commit is contained in:
Rafikooo 2026-02-06 13:57:57 +01:00 committed by Grzegorz Sadowski
parent a6972e5ae5
commit f906fcba7f
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
3 changed files with 16 additions and 6 deletions

View file

@ -42,7 +42,7 @@ final class AllTaxons implements AllTaxonsInterface
$queryBuilder = $this->entityManager->getConnection()->createQueryBuilder();
$queryBuilder
->select([
->select(
'taxon.id as id',
'taxon.tree_root as tree_root',
'taxon.parent_id as parent_id',
@ -53,7 +53,7 @@ final class AllTaxons implements AllTaxonsInterface
'taxon.position as position',
'taxon.enabled as enabled',
'COALESCE(current_translation.name, fallback_translation.name) as name',
])
)
->from('sylius_taxon', 'taxon')
->leftJoin(
'taxon',

View file

@ -15,7 +15,6 @@ namespace Sylius\Bundle\CoreBundle\Doctrine\DQL;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Parser;
@ -49,10 +48,16 @@ final class Day extends FunctionNode
return sprintf('EXTRACT(DAY FROM %s)', $sqlWalker->walkArithmeticPrimary($this->date));
}
if (is_a($platform, SqlitePlatform::class, true)) {
if ($this->isSqlitePlatform($platform)) {
return sprintf('CAST(STRFTIME("%%d", %s) AS NUMBER)', $sqlWalker->walkArithmeticPrimary($this->date));
}
throw new \RuntimeException(sprintf('Platform "%s" is not supported!', get_class($platform)));
}
/** Compatibility layer for DBAL 3.x (SqlitePlatform) and 4.x (SQLitePlatform) */
private function isSqlitePlatform(object $platform): bool
{
return str_contains(get_class($platform), 'SqlitePlatform') || str_contains(get_class($platform), 'SQLitePlatform');
}
}

View file

@ -15,7 +15,6 @@ namespace Sylius\Bundle\CoreBundle\Doctrine\DQL;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Parser;
@ -49,10 +48,16 @@ final class Hour extends FunctionNode
return sprintf('EXTRACT(HOUR FROM %s)', $sqlWalker->walkArithmeticPrimary($this->date));
}
if (is_a($platform, SqlitePlatform::class, true)) {
if ($this->isSqlitePlatform($platform)) {
return sprintf('CAST(STRFTIME("%%H", %s) AS NUMBER)', $sqlWalker->walkArithmeticPrimary($this->date));
}
throw new \RuntimeException(sprintf('Platform "%s" is not supported!', get_class($platform)));
}
/** Compatibility layer for DBAL 3.x (SqlitePlatform) and 4.x (SQLitePlatform) */
private function isSqlitePlatform(object $platform): bool
{
return str_contains(get_class($platform), 'SqlitePlatform') || str_contains(get_class($platform), 'SQLitePlatform');
}
}