From c30c948556a29d779e846efbbfb1f5ca1ac7ce78 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sun, 14 Jan 2024 18:54:14 +0100 Subject: [PATCH] fix: unknown variable column-statistics=0 with MariaDB 10 --- .../DatabaseBackup/MysqlDatabaseBackup.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Services/DatabaseBackup/MysqlDatabaseBackup.php b/src/Services/DatabaseBackup/MysqlDatabaseBackup.php index b3fe6d6b..96785d72 100644 --- a/src/Services/DatabaseBackup/MysqlDatabaseBackup.php +++ b/src/Services/DatabaseBackup/MysqlDatabaseBackup.php @@ -75,7 +75,24 @@ public function backup(AbstractExecutor $executor): void $executor->getReferenceRepository()->save($this->getBackupFilePath()); self::$metadata = $em->getMetadataFactory()->getLoadedMetadata(); - exec("{$dbPass} mysqldump --host {$dbHost} {$port} --user {$dbUser} --no-create-info --skip-triggers --no-create-db --no-tablespaces --compact --column-statistics=0 {$dbName} > {$this->getBackupFilePath()}"); + $mysqldumpOptions = '--no-create-info --skip-triggers --no-create-db --no-tablespaces --compact'; + $mysqldumpCommand = 'mysqldump --host '.$dbHost.' '.$port.' --user '.$dbUser.' '.$dbName.' '.$mysqldumpOptions; + $columnStatistics0 = '--column-statistics=0'; + + // ignore the E_WARNING if “--column-statistics=0” is not a valid option + $execWithColumnStatistics = @exec( + $dbPass.' '.$mysqldumpCommand.' '.$columnStatistics0.' > '.$this->getBackupFilePath() + ); + + if (false !== $execWithColumnStatistics) { + return; + } + + // when mysqldump is provided by MariaDB 10, “--column-statistics=0” is not a valid option, + // we call mysqldump without this option + exec( + $dbPass.' '.$mysqldumpCommand.' > '.$this->getBackupFilePath() + ); } public function restore(AbstractExecutor $executor, array $excludedTables = []): void