From a5b046ea12a07507afd75dcc6cf22f355018709e Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Thu, 28 Mar 2024 16:39:23 +0100 Subject: [PATCH] Add support for Pimcore 11.2 --- composer.json | 2 +- phpstan-baseline.neon | 7 +------ src/Database/PimcoreDatabaseResetter.php | 11 ++++++++++- src/Database/PimcoreInstaller.php | 23 ++++++++++++++++------- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index ff0dec6..c034d8d 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "doctrine/annotations": "^1.5", "doctrine/persistence": "^2.1 || ^3.0", "phpunit/phpunit": "^9.6.0", - "pimcore/pimcore": "^10.5 || ~11.0.0 || ~11.1.0", + "pimcore/pimcore": "^10.5 || ~11.0.0 || ~11.1.0 || ~11.2.2", "psr/log": "^1.0 || ^2.0 || ^3.0", "symfony/console": "^5.4 || ^6.2", "symfony/filesystem": "^5.4 || ^6.2", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c86c432..ad88690 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -16,12 +16,7 @@ parameters: path: src/Database/PimcoreInstaller.php - - message: "#^PHPDoc tag @throws with type Doctrine\\\\DBAL\\\\DBALException is not subtype of Throwable$#" - count: 1 - path: src/Database/PimcoreInstaller.php - - - - message: "#^Parameter \\#1 \\$sql of method Doctrine\\\\DBAL\\\\Connection\\:\\:exec\\(\\) expects string, string\\|false given\\.$#" + message: "#^Parameter \\#1 \\$sql of method Doctrine\\\\DBAL\\\\Connection\\:\\:executeStatement\\(\\) expects string, string\\|false given\\.$#" count: 1 path: src/Database/PimcoreInstaller.php diff --git a/src/Database/PimcoreDatabaseResetter.php b/src/Database/PimcoreDatabaseResetter.php index c4909b9..5b8c4c8 100644 --- a/src/Database/PimcoreDatabaseResetter.php +++ b/src/Database/PimcoreDatabaseResetter.php @@ -5,6 +5,7 @@ namespace Neusta\Pimcore\TestingFramework\Database; use Doctrine\Persistence\ManagerRegistry; +use Pimcore\Db; use Symfony\Bundle\FrameworkBundle\Console\Application; /** @@ -79,7 +80,15 @@ private function createSchema(): void $installer->setDumpLocation($_SERVER['DATABASE_DUMP_LOCATION']); } - if ([] !== $errors = $installer->setupDatabase([])) { + // Todo: remove when support for Pimcore <11.2.2 is dropped + if (2 === (new \ReflectionMethod($installer, 'setupDatabase'))->getNumberOfParameters()) { + // @phpstan-ignore-next-line + $errors = $installer->setupDatabase([]); + } else { + $errors = $installer->setupDatabase(Db::get(), []); + } + + if ([] !== $errors) { throw new \RuntimeException(sprintf( 'Error setting up Pimcore\'s database: "%s"', implode('", "', $errors), diff --git a/src/Database/PimcoreInstaller.php b/src/Database/PimcoreInstaller.php index 1bc2fae..8f5849a 100644 --- a/src/Database/PimcoreInstaller.php +++ b/src/Database/PimcoreInstaller.php @@ -4,7 +4,10 @@ namespace Neusta\Pimcore\TestingFramework\Database; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Exception; use Pimcore\Bundle\InstallBundle\Installer; +use Pimcore\Db; use Psr\Log\NullLogger; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Filesystem\Filesystem; @@ -45,21 +48,27 @@ public function setDumpLocation(string $dumpLocation): void } /** - * @param string $file + * @param Connection $db + * @param string $file * - * @throws \Doctrine\DBAL\DBALException + * @throws Exception */ - public function insertDatabaseDump($file): void + public function insertDatabaseDump($db, $file = ''): void { + // Todo: remove when support for Pimcore <11.2.2 is dropped + if (1 === \func_num_args()) { + $file = func_get_arg(0); + $db = Db::get(); + } + if (str_ends_with($file, self::GZIP_FILE_EXTENSION)) { $file = 'compress.zlib://' . $file; } $dumpFile = file_get_contents($file); - $db = \Pimcore\Db::get(); if (str_contains($file, 'atomic')) { - $db->exec($dumpFile); + $db->executeStatement($dumpFile); } else { // get every command as single part - ; at end of line $singleQueries = explode(";\n", $dumpFile); @@ -73,12 +82,12 @@ public function insertDatabaseDump($file): void } if (\count($batchQueries) > 500) { - $db->exec(implode("\n", $batchQueries)); + $db->executeStatement(implode("\n", $batchQueries)); $batchQueries = []; } } - $db->exec(implode("\n", $batchQueries)); + $db->executeStatement(implode("\n", $batchQueries)); } // set the id of the system user to 0