diff --git a/migrations/Version20240606203053.php b/migrations/Version20240606203053.php index bf382bbb..b23bea9b 100644 --- a/migrations/Version20240606203053.php +++ b/migrations/Version20240606203053.php @@ -199,6 +199,15 @@ final class Version20240606203053 extends AbstractMultiPlatformMigration impleme $this->addSql('ALTER TABLE "users" ADD CONSTRAINT FK_1483A5E938248176 FOREIGN KEY (currency_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE webauthn_keys ADD CONSTRAINT FK_799FD143A76ED395 FOREIGN KEY (user_id) REFERENCES "users" (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + //Create the FIELD() function for PostgreSQL + $this->addSql(<<getJSONPermDataFromPreset(PermissionPresetsHelper::PRESET_ADMIN); diff --git a/src/Doctrine/Helpers/FieldHelper.php b/src/Doctrine/Helpers/FieldHelper.php index 49dc1475..d1c9eee6 100644 --- a/src/Doctrine/Helpers/FieldHelper.php +++ b/src/Doctrine/Helpers/FieldHelper.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace App\Doctrine\Helpers; use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\ORM\QueryBuilder; /** @@ -44,11 +45,11 @@ final class FieldHelper { $db_platform = $qb->getEntityManager()->getConnection()->getDatabasePlatform(); - //If we are on MySQL, we can just use the FIELD function - if ($db_platform instanceof AbstractMySQLPlatform) { + //If we are on MySQL, we can just use the FIELD function, for PostgreSQL we can use our custom defined one + if ($db_platform instanceof AbstractMySQLPlatform || $db_platform instanceof PostgreSQLPlatform) { $param = (is_numeric($bound_param) ? '?' : ":") . (string) $bound_param; $qb->orderBy("FIELD($field_expr, $param)", $order); - } else { + } else { //Use the sqlite/portable version //Retrieve the values from the bound parameter $param = $qb->getParameter($bound_param); if ($param === null) {