Skip to content

Commit

Permalink
Add support for Pimcore 11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jdreesen committed Mar 28, 2024
1 parent b8fd504 commit 2f20500
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 1 addition & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion src/Database/PimcoreDatabaseResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Neusta\Pimcore\TestingFramework\Database;

use Doctrine\Persistence\ManagerRegistry;
use Pimcore\Db;
use Symfony\Bundle\FrameworkBundle\Console\Application;

/**
Expand Down Expand Up @@ -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),
Expand Down
23 changes: 16 additions & 7 deletions src/Database/PimcoreInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 2f20500

Please sign in to comment.