Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix importing database dumps on Alpine Linux #27

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.12.6
### Bugfixes:
- Fix importing database dumps on Alpine Linux

## v0.12.5
### Changes:
- Remove unnecessary `doctrine/annotations` from test suite
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ parameters:
count: 1
path: src/Database/DatabaseResetter.php

-
message: "#^Method Neusta\\\\Pimcore\\\\TestingFramework\\\\Database\\\\PimcoreInstaller\\:\\:getDataFiles\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Database/PimcoreInstaller.php

-
message: "#^Method Neusta\\\\Pimcore\\\\TestingFramework\\\\Database\\\\PimcoreInstaller\\:\\:getDataFiles\\(\\) should return array but returns array\\<int, string\\>\\|false\\.$#"
count: 1
path: src/Database/PimcoreInstaller.php

-
message: "#^Parameter \\#1 \\$sql of method Doctrine\\\\DBAL\\\\Connection\\:\\:executeStatement\\(\\) expects string, string\\|false given\\.$#"
count: 1
Expand Down
23 changes: 15 additions & 8 deletions src/Database/PimcoreInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
class PimcoreInstaller extends Installer
{
private const SQL_FILE_EXTENSION = '.sql';
private const GZIP_FILE_EXTENSION = '.sql.gz';
private const DUMP_FILE_EXTENSIONS = [
self::SQL_FILE_EXTENSION,
self::GZIP_FILE_EXTENSION,
];
private const SQL_GZIP_FILE_EXTENSION = '.sql.gz';

private ?string $dumpLocation = null;

Expand All @@ -48,6 +44,8 @@ public function setDumpLocation(string $dumpLocation): void
}

/**
* Todo: remove when support for Pimcore <11.3.3 is dropped.
*
* @param Connection $db
* @param string $file
*
Expand All @@ -61,7 +59,8 @@ public function insertDatabaseDump($db, $file = ''): void
$db = Db::get();
}

if (str_ends_with($file, self::GZIP_FILE_EXTENSION)) {
// Todo: remove when support for Pimcore <11.3 is dropped
if (str_ends_with($file, self::SQL_GZIP_FILE_EXTENSION)) {
$file = 'compress.zlib://' . $file;
}

Expand Down Expand Up @@ -94,14 +93,22 @@ public function insertDatabaseDump($db, $file = ''): void
$db->update('users', ['id' => 0], ['name' => 'system']);
}

/**
* @return array<string>
*/
protected function getDataFiles(): array
{
if (!$this->dumpLocation) {
return [];
}

$pattern = \sprintf('%s/*{%s}', $this->dumpLocation, implode(',', self::DUMP_FILE_EXTENSIONS));
$files = [
...glob($this->dumpLocation . '/*' . self::SQL_FILE_EXTENSION, \GLOB_NOSORT) ?: [],
...glob($this->dumpLocation . '/*' . self::SQL_GZIP_FILE_EXTENSION, \GLOB_NOSORT) ?: [],
];

natsort($files);

return glob($pattern, \GLOB_BRACE);
return $files;
}
}
Loading