Make filters work on default MySQL servers to by removing the ONLY_FULL_GROUP_BY sql mode

This commit is contained in:
Jan Böhmer 2022-09-11 23:41:31 +02:00
parent ffa804404c
commit 467687fd0f
2 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,24 @@
<?php
namespace App\Doctrine\SetSQLMode;
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
/**
* This command sets the initial command parameter for MySQL connections, so we can set the SQL mode
* We use this to disable the ONLY_FULL_GROUP_BY mode, which is enabled by default in MySQL 5.7.5 and higher and causes problems with our filters
*/
class SetSQLModeMiddlewareDriver extends AbstractDriverMiddleware
{
public function connect(array $params): \Doctrine\DBAL\Driver\Connection
{
//Only set this on MySQL connections, as other databases don't support this parameter
if($this->getDatabasePlatform() instanceof AbstractMySQLPlatform) {
//1002 is \PDO::MYSQL_ATTR_INIT_COMMAND constant value
$params['driverOptions'][1002] = 'SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode, \'ONLY_FULL_GROUP_BY\', \'\'))';
}
return parent::connect($params);
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace App\Doctrine\SetSQLMode;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Middleware;
/**
* This class wraps the Doctrine DBAL driver and wraps it into an Midleware driver so we can change the SQL mode
*/
class SetSQLModeMiddlewareWrapper implements Middleware
{
public function wrap(Driver $driver): Driver
{
return new SetSQLModeMiddlewareDriver($driver);
}
}