Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fall back to "dumb" numeric sorting for older SQLite versions #1765

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Storage/Directive/OrderDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down