diff --git a/src/Storage/Directive/OrderDirective.php b/src/Storage/Directive/OrderDirective.php index 12a5250e9..952fc85d2 100644 --- a/src/Storage/Directive/OrderDirective.php +++ b/src/Storage/Directive/OrderDirective.php @@ -4,6 +4,7 @@ namespace Bolt\Storage\Directive; +use Bolt\Doctrine\Version; use Bolt\Entity\Field\NumberField; use Bolt\Storage\QueryInterface; use Bolt\Twig\Notifications; @@ -170,6 +171,17 @@ private function getTitleFormat(QueryInterface $query): ?string private function orderByNumericField(QueryInterface $query, string $translationsAlias, string $direction): void { $qb = $query->getQueryBuilder(); + + // For older bundled SQLite in PHP 7.2 that do not have `INSTR` and `CAST` built in, we fall back to the + // "dumb" sorting instead. For this we use the same criteria as to check whether we have JSON. C'est la vie. + $doctrineVersion = new Version($query->getQueryBuilder()->getEntityManager()->getConnection()); + + if (! $doctrineVersion->hasJson()) { + $qb->addOrderBy($translationsAlias . '.value', $direction); + + return; + } + $qb->addSelect('INSTR(' . $translationsAlias . '.value, \'%[0-9]%\') as HIDDEN instr'); $innerSubstring = $qb ->expr()