Merge pull request #4604 from nabbi/mariadb-deprecated-legacy-names

feat: detect MariaDB-native command names with fallback
This commit is contained in:
Isaac Connor
2026-02-08 14:59:51 -05:00
committed by GitHub
3 changed files with 35 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ our @ISA = qw(Exporter ZoneMinder::Base);
our %EXPORT_TAGS = (
functions => [ qw(
executeShellCommand
findDbCommand
getCmdFormat
runCommand
setFileOwner
@@ -71,6 +72,34 @@ sub executeShellCommand {
return $status;
}
# Map legacy MySQL command names to MariaDB-native equivalents.
# MariaDB is deprecating the mysql-prefixed names in favour of its own.
my %DB_COMMAND_MAP = (
'mysql' => 'mariadb',
'mysqldump' => 'mariadb-dump',
);
my %_db_command_cache;
sub findDbCommand {
my $legacy_name = shift;
return $_db_command_cache{$legacy_name} if exists $_db_command_cache{$legacy_name};
my $maria_name = $DB_COMMAND_MAP{$legacy_name};
if ($maria_name) {
my $path = qx(command -v $maria_name 2>/dev/null);
chomp($path);
if ($path) {
Debug("Using '$maria_name' for database command '$legacy_name'");
$_db_command_cache{$legacy_name} = $maria_name;
return $maria_name;
}
}
Debug("Using legacy '$legacy_name' for database command");
$_db_command_cache{$legacy_name} = $legacy_name;
return $legacy_name;
}
sub getCmdFormat {
Debug('Testing valid shell syntax');
@@ -663,6 +692,7 @@ of the ZoneMinder scripts
functions => [ qw(
executeShellCommand
findDbCommand
getCmdFormat
runCommand
setFileOwner
@@ -674,7 +704,7 @@ of the ZoneMinder scripts
packageControl
daemonControl
systemStatus
parseNameEqualsValueToHash
parseNameEqualsValueToHash
hash_diff
) ]

View File

@@ -64,6 +64,7 @@ use bytes;
@EXTRA_PERL_LIB@
use ZoneMinder::Config qw(:all);
use ZoneMinder::Logger qw(:all);
use ZoneMinder::General qw(:all);
use ZoneMinder::Database qw(:all);
use DBI;
use Getopt::Long;
@@ -344,7 +345,7 @@ sub importsql {
sub exportsql {
my ( $host, $port ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
my $command = 'mysqldump -t --skip-opt --compact -h'.$host;
my $command = findDbCommand('mysqldump').' -t --skip-opt --compact -h'.$host;
$command .= ' -P'.$port if defined($port);
if ( $dbUser ) {
$command .= ' -u\''.$dbUser.'\'';

View File

@@ -416,7 +416,7 @@ if ( $version ) {
if ( $response =~ /^[yY]$/ ) {
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
my $command = 'mysqldump';
my $command = findDbCommand('mysqldump');
if ($super) {
$command .= ' --defaults-file=/etc/mysql/debian.cnf';
} elsif ($dbUser) {
@@ -1007,7 +1007,7 @@ sub patchDB {
my $version = shift;
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ) if $Config{ZM_DB_HOST};
my $command = 'mysql';
my $command = findDbCommand('mysql');
if ($super) {
$command .= ' --defaults-file=/etc/mysql/debian.cnf';
} elsif ($dbUser) {