feat(dump): parse dump filenames and detect MySQL variant
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace AeonDumpManager\Service;
|
||||
|
||||
/**
|
||||
* Dumps are named dump_YYYY-MM-DD_HH-mm-ss.sql.gz — lexicographically sortable,
|
||||
* and the filename is the single source of truth for a dump's datetime (not
|
||||
* filesystem mtime, which can drift across copies/touches).
|
||||
*/
|
||||
class DumpFilenameParser
|
||||
{
|
||||
private const PATTERN = '/^dump_(\d{4}-\d{2}-\d{2})_(\d{2}-\d{2}-\d{2})\.sql\.gz$/';
|
||||
|
||||
public function format(\DateTimeImmutable $dateTime): string
|
||||
{
|
||||
return 'dump_' . $dateTime->format('Y-m-d_H-i-s') . '.sql.gz';
|
||||
}
|
||||
|
||||
public function parse(string $filename): ?\DateTimeImmutable
|
||||
{
|
||||
if (preg_match(self::PATTERN, $filename, $matches) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$dateTime = \DateTimeImmutable::createFromFormat(
|
||||
'Y-m-d_H-i-s',
|
||||
$matches[1] . '_' . $matches[2]
|
||||
);
|
||||
|
||||
return $dateTime ?: null;
|
||||
}
|
||||
|
||||
public function isValid(string $filename): bool
|
||||
{
|
||||
return $this->parse($filename) !== null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace AeonDumpManager\Service;
|
||||
|
||||
/**
|
||||
* Pure version-string check, split out of DumpBinaryLocator so it's
|
||||
* unit-testable without a live Shopware kernel/DB connection. Mirrors
|
||||
* Doctrine DBAL's own AbstractMySQLDriver::createDatabasePlatformForVersion()
|
||||
* check — the stable, version-portable way to tell MariaDB from MySQL.
|
||||
*/
|
||||
class MySqlVariant
|
||||
{
|
||||
public static function isMariaDb(string $serverVersion): bool
|
||||
{
|
||||
return stripos($serverVersion, 'mariadb') !== false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user