feat(dump): locate mysqldump/mariadb-dump binary
This commit is contained in:
Regular → Executable
+5
@@ -16,6 +16,11 @@
|
|||||||
<label>How many Days the dumps kept in the Storage. 0 Means unlimited</label>
|
<label>How many Days the dumps kept in the Storage. 0 Means unlimited</label>
|
||||||
<defaultValue>0</defaultValue>
|
<defaultValue>0</defaultValue>
|
||||||
</input-field>
|
</input-field>
|
||||||
|
<input-field type="text">
|
||||||
|
<name>dumpBinaryName</name>
|
||||||
|
<label>Name of the mysqldump/mariadb-dump binary to look up on PATH (e.g. if your distro renamed it). Leave empty to auto-detect.</label>
|
||||||
|
<defaultValue>""</defaultValue>
|
||||||
|
</input-field>
|
||||||
</card>
|
</card>
|
||||||
|
|
||||||
</config>
|
</config>
|
||||||
|
|||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace AeonDumpManager\Service\Exception;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
class DumpBinaryNotFoundException extends RuntimeException
|
||||||
|
{
|
||||||
|
public static function create(array $searched): self
|
||||||
|
{
|
||||||
|
return new self(sprintf(
|
||||||
|
'Could not find a dump binary. Searched for: %s. Configure "dumpBinaryPath" in the plugin settings to point at one explicitly.',
|
||||||
|
implode(', ', $searched)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user