Merge remote-tracking branch 'origin/support/2.7' into support/3.0

# Conflicts:
#	tests/php-unit-tests/post-build-integration-tests/SetupCssIntegrityChecklistTest.php
#	tests/php-unit-tests/unitary-tests/core/CMDBSource/CMDBSourceTest.php
This commit is contained in:
Pierre Goiffon
2024-01-03 10:41:12 +01:00
6 changed files with 128 additions and 57 deletions

View File

@@ -304,9 +304,8 @@ class DBBackup
// Store the results in a temporary file
$sTmpFileName = self::EscapeShellArg($sBackupFileName);
$sPortOption = self::GetMysqliCliSingleOption('port', $this->iDBPort);
$sPortAndTransportOptions = self::GetMysqlCliPortAndTransportOptions($this->sDBHost, $this->iDBPort);
$sTlsOptions = self::GetMysqlCliTlsOptions($this->oConfig);
$sProtocolOption = self::GetMysqlCliTransportOption($this->sDBHost);
$sMysqlVersion = CMDBSource::GetDBVersion();
$bIsMysqlSupportUtf8mb4 = (version_compare($sMysqlVersion, self::MYSQL_VERSION_WITH_UTF8MB4_IN_PROGRAMS) === -1);
@@ -325,10 +324,10 @@ EOF;
chmod($sMySQLDumpCnfFile, 0600);
file_put_contents($sMySQLDumpCnfFile, $sMySQLDumpCnf, LOCK_EX);
// Note: opt implicitely sets lock-tables... which cancels the benefit of single-transaction!
// Note: opt implicitly sets lock-tables... which cancels the benefit of single-transaction!
// skip-lock-tables compensates and allows for writes during a backup
$sCommand = "$sMySQLDump --defaults-extra-file=\"$sMySQLDumpCnfFile\" --opt --skip-lock-tables --default-character-set=".$sMysqldumpCharset." --add-drop-database --single-transaction --host=$sHost $sPortOption $sProtocolOption --user=$sUser $sTlsOptions --result-file=$sTmpFileName $sDBName $sTables 2>&1";
$sCommandDisplay = "$sMySQLDump --defaults-extra-file=\"$sMySQLDumpCnfFile\" --opt --skip-lock-tables --default-character-set=".$sMysqldumpCharset." --add-drop-database --single-transaction --host=$sHost $sPortOption $sProtocolOption --user=xxxxx $sTlsOptions --result-file=$sTmpFileName $sDBName $sTables";
$sCommand = "$sMySQLDump --defaults-extra-file=\"$sMySQLDumpCnfFile\" --opt --skip-lock-tables --default-character-set=" . $sMysqldumpCharset . " --add-drop-database --single-transaction --host=$sHost $sPortAndTransportOptions --user=$sUser $sTlsOptions --result-file=$sTmpFileName $sDBName $sTables 2>&1";
$sCommandDisplay = "$sMySQLDump --defaults-extra-file=\"$sMySQLDumpCnfFile\" --opt --skip-lock-tables --default-character-set=" . $sMysqldumpCharset . " --add-drop-database --single-transaction --host=$sHost $sPortAndTransportOptions --user=xxxxx $sTlsOptions --result-file=$sTmpFileName $sDBName $sTables";
// Now run the command for real
$this->LogInfo("backup: generate data file with command: $sCommandDisplay");
@@ -522,25 +521,37 @@ EOF;
}
/**
* Define if we should force a transport option
*
* @param string $sHost
* @return string CLI options for port and protocol
*
* @return string .
* @since 2.7.9 3.0.4 3.1.1 N°6123
* @since 2.7.9 3.0.4 3.1.1 N°6123 method creation
* @since 2.7.10 3.0.4 3.1.2 3.2.0 N°6889 rename method to return both port and transport options. Keep default socket connexion if we are on localhost with no port
*
* @link https://bugs.mysql.com/bug.php?id=55796 MySQL CLI tools will ignore `--port` option on localhost
* @link https://jira.mariadb.org/browse/MDEV-14974 Since 10.6.1 the MariaDB CLI tools will use the `--port` option on host=localhost
*/
public static function GetMysqlCliTransportOption(string $sHost)
private static function GetMysqlCliPortAndTransportOptions(string $sHost, ?int $iPort): string
{
$sTransportOptions = '';
/** N°6123 As we're using a --port option, if we use localhost as host,
* MariaDB > 10.6 will implicitly change its protocol from socket to tcp and throw a warning **/
if($sHost === 'localhost'){
$sTransportOptions = '--protocol=tcp';
if (strtolower($sHost) === 'localhost') {
/**
* Since MariaDB 10.6.1 if we have host=localhost, and only the --port option we will get a warning
* To avoid this warning if we want to set --port option we must set --protocol=tcp
**/
if (is_null($iPort)) {
// no port specified => no option to return, this will mean using socket protocol (unix socket)
return '';
}
$sPortOption = self::GetMysqliCliSingleOption('port', $iPort);
$sTransportOptions = ' --protocol=tcp';
return $sPortOption . $sTransportOptions;
}
return $sTransportOptions;
if (is_null($iPort)) {
$iPort = CMDBSource::MYSQL_DEFAULT_PORT;
}
$sPortOption = self::GetMysqliCliSingleOption('port', $iPort);
return $sPortOption;
}
/**