feat(dump): locate mysqldump/mariadb-dump binary

This commit is contained in:
2026-09-14 22:00:26 +02:00
parent d0e8ea582f
commit 44e7648e06
3 changed files with 66 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php declare(strict_types=1);
namespace AeonDumpManager\Service;
use AeonDumpManager\Service\Exception\DumpBinaryNotFoundException;
use Doctrine\DBAL\Connection;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Symfony\Component\Process\ExecutableFinder;
/**
* Picks mariadb-dump/mysqldump depending on what the configured DB connection
* actually is, mirroring Doctrine DBAL's own stripos($version, 'mariadb')
* version-string check (no shared platform base class to rely on instead).
*/
class DumpBinaryLocator
{
public function __construct(
private readonly Connection $connection,
private readonly SystemConfigService $systemConfigService,
private readonly ExecutableFinder $executableFinder,
) {
}
public function locate(): string
{
$configuredName = $this->systemConfigService->getString('AeonDumpManager.config.dumpBinaryName');
$binaryNames = $configuredName !== ''
? [$configuredName]
: ($this->isMariaDb() ? ['mariadb-dump', 'mysqldump'] : ['mysqldump']);
foreach ($binaryNames as $binaryName) {
$path = $this->executableFinder->find($binaryName);
if ($path !== null) {
return $path;
}
}
throw DumpBinaryNotFoundException::create($binaryNames);
}
private function isMariaDb(): bool
{
return MySqlVariant::isMariaDb($this->connection->getServerVersion());
}
}