Skip to content

Commit cbfc556

Browse files
authored
Add support for Pimcore 11.2 (#14)
1 parent b8fd504 commit cbfc556

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"doctrine/annotations": "^1.5",
2424
"doctrine/persistence": "^2.1 || ^3.0",
2525
"phpunit/phpunit": "^9.6.0",
26-
"pimcore/pimcore": "^10.5 || ~11.0.0 || ~11.1.0",
26+
"pimcore/pimcore": "^10.5 || ~11.0.0 || ~11.1.0 || ~11.2.2",
2727
"psr/log": "^1.0 || ^2.0 || ^3.0",
2828
"symfony/console": "^5.4 || ^6.2",
2929
"symfony/filesystem": "^5.4 || ^6.2",

phpstan-baseline.neon

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ parameters:
1616
path: src/Database/PimcoreInstaller.php
1717

1818
-
19-
message: "#^PHPDoc tag @throws with type Doctrine\\\\DBAL\\\\DBALException is not subtype of Throwable$#"
20-
count: 1
21-
path: src/Database/PimcoreInstaller.php
22-
23-
-
24-
message: "#^Parameter \\#1 \\$sql of method Doctrine\\\\DBAL\\\\Connection\\:\\:exec\\(\\) expects string, string\\|false given\\.$#"
19+
message: "#^Parameter \\#1 \\$sql of method Doctrine\\\\DBAL\\\\Connection\\:\\:executeStatement\\(\\) expects string, string\\|false given\\.$#"
2520
count: 1
2621
path: src/Database/PimcoreInstaller.php
2722

src/Database/PimcoreDatabaseResetter.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Neusta\Pimcore\TestingFramework\Database;
66

77
use Doctrine\Persistence\ManagerRegistry;
8+
use Pimcore\Db;
89
use Symfony\Bundle\FrameworkBundle\Console\Application;
910

1011
/**
@@ -79,7 +80,15 @@ private function createSchema(): void
7980
$installer->setDumpLocation($_SERVER['DATABASE_DUMP_LOCATION']);
8081
}
8182

82-
if ([] !== $errors = $installer->setupDatabase([])) {
83+
// Todo: remove when support for Pimcore <11.2.2 is dropped
84+
if (2 === (new \ReflectionMethod($installer, 'setupDatabase'))->getNumberOfParameters()) {
85+
// @phpstan-ignore-next-line
86+
$errors = $installer->setupDatabase([]);
87+
} else {
88+
$errors = $installer->setupDatabase(Db::get(), []);
89+
}
90+
91+
if ([] !== $errors) {
8392
throw new \RuntimeException(sprintf(
8493
'Error setting up Pimcore\'s database: "%s"',
8594
implode('", "', $errors),

src/Database/PimcoreInstaller.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
namespace Neusta\Pimcore\TestingFramework\Database;
66

7+
use Doctrine\DBAL\Connection;
8+
use Doctrine\DBAL\Exception;
79
use Pimcore\Bundle\InstallBundle\Installer;
10+
use Pimcore\Db;
811
use Psr\Log\NullLogger;
912
use Symfony\Component\EventDispatcher\EventDispatcher;
1013
use Symfony\Component\Filesystem\Filesystem;
@@ -45,21 +48,27 @@ public function setDumpLocation(string $dumpLocation): void
4548
}
4649

4750
/**
48-
* @param string $file
51+
* @param Connection $db
52+
* @param string $file
4953
*
50-
* @throws \Doctrine\DBAL\DBALException
54+
* @throws Exception
5155
*/
52-
public function insertDatabaseDump($file): void
56+
public function insertDatabaseDump($db, $file = ''): void
5357
{
58+
// Todo: remove when support for Pimcore <11.2.2 is dropped
59+
if (1 === \func_num_args()) {
60+
$file = func_get_arg(0);
61+
$db = Db::get();
62+
}
63+
5464
if (str_ends_with($file, self::GZIP_FILE_EXTENSION)) {
5565
$file = 'compress.zlib://' . $file;
5666
}
5767

5868
$dumpFile = file_get_contents($file);
59-
$db = \Pimcore\Db::get();
6069

6170
if (str_contains($file, 'atomic')) {
62-
$db->exec($dumpFile);
71+
$db->executeStatement($dumpFile);
6372
} else {
6473
// get every command as single part - ; at end of line
6574
$singleQueries = explode(";\n", $dumpFile);
@@ -73,12 +82,12 @@ public function insertDatabaseDump($file): void
7382
}
7483

7584
if (\count($batchQueries) > 500) {
76-
$db->exec(implode("\n", $batchQueries));
85+
$db->executeStatement(implode("\n", $batchQueries));
7786
$batchQueries = [];
7887
}
7988
}
8089

81-
$db->exec(implode("\n", $batchQueries));
90+
$db->executeStatement(implode("\n", $batchQueries));
8291
}
8392

8493
// set the id of the system user to 0

0 commit comments

Comments
 (0)