Compare commits

...

2 Commits

Author SHA1 Message Date
odain
cc2f7e1592 N°6643: fix deadlock log 2023-10-11 08:15:05 +02:00
odain
a54b88c524 N°6640 - Broken unattended setup with XML backup configuration 2023-10-11 08:10:33 +02:00
3 changed files with 54 additions and 20 deletions

View File

@@ -3,7 +3,7 @@
// //
// This file is part of iTop. // This file is part of iTop.
// //
// iTop is free software; you can redistribute it and/or modify // iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by // it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
@@ -380,7 +380,7 @@ class CMDBSource
public static function GetDBVendor() public static function GetDBVendor()
{ {
$sDBVendor = static::ENUM_DB_VENDOR_MYSQL; $sDBVendor = static::ENUM_DB_VENDOR_MYSQL;
$sVersionComment = static::GetServerVariable('version') . ' - ' . static::GetServerVariable('version_comment'); $sVersionComment = static::GetServerVariable('version') . ' - ' . static::GetServerVariable('version_comment');
if(preg_match('/mariadb/i', $sVersionComment) === 1) if(preg_match('/mariadb/i', $sVersionComment) === 1)
{ {
@@ -390,7 +390,7 @@ class CMDBSource
{ {
$sDBVendor = static::ENUM_DB_VENDOR_PERCONA; $sDBVendor = static::ENUM_DB_VENDOR_PERCONA;
} }
return $sDBVendor; return $sDBVendor;
} }
@@ -664,7 +664,7 @@ class CMDBSource
); );
DeadLockLog::Info($sMessage, $iMySqlErrorNo, $aLogContext); DeadLockLog::Info($sMessage, $iMySqlErrorNo, $aLogContext);
IssueLog::Error($sMessage, LogChannels::DEADLOCK, $e->getMessage()); IssueLog::Error($sMessage, LogChannels::DEADLOCK, [$e->getMessage()]);
} }
/** /**
@@ -923,7 +923,7 @@ class CMDBSource
{ {
throw new MySQLException('Failed to issue SQL query', array('query' => $sSql)); throw new MySQLException('Failed to issue SQL query', array('query' => $sSql));
} }
while ($aRow = $oResult->fetch_array($iMode)) while ($aRow = $oResult->fetch_array($iMode))
{ {
$aData[] = $aRow; $aData[] = $aRow;
@@ -1077,7 +1077,7 @@ class CMDBSource
if (!array_key_exists($iKey, $aTableInfo["Fields"])) return false; if (!array_key_exists($iKey, $aTableInfo["Fields"])) return false;
$aFieldData = $aTableInfo["Fields"][$iKey]; $aFieldData = $aTableInfo["Fields"][$iKey];
if (!array_key_exists("Key", $aFieldData)) return false; if (!array_key_exists("Key", $aFieldData)) return false;
return ($aFieldData["Key"] == "PRI"); return ($aFieldData["Key"] == "PRI");
} }
public static function IsAutoIncrement($sTable, $sField) public static function IsAutoIncrement($sTable, $sField)
@@ -1088,7 +1088,7 @@ class CMDBSource
$aFieldData = $aTableInfo["Fields"][$sField]; $aFieldData = $aTableInfo["Fields"][$sField];
if (!array_key_exists("Extra", $aFieldData)) return false; if (!array_key_exists("Extra", $aFieldData)) return false;
//MyHelpers::debug_breakpoint($aFieldData); //MyHelpers::debug_breakpoint($aFieldData);
return (strstr($aFieldData["Extra"], "auto_increment")); return (strstr($aFieldData["Extra"], "auto_increment"));
} }
public static function IsField($sTable, $sField) public static function IsField($sTable, $sField)
@@ -1355,13 +1355,13 @@ class CMDBSource
public static function GetTableFieldsList($sTable) public static function GetTableFieldsList($sTable)
{ {
assert(!empty($sTable)); assert(!empty($sTable));
$aTableInfo = self::GetTableInfo($sTable); $aTableInfo = self::GetTableInfo($sTable);
if (empty($aTableInfo)) return array(); // #@# or an error ? if (empty($aTableInfo)) return array(); // #@# or an error ?
return array_keys($aTableInfo["Fields"]); return array_keys($aTableInfo["Fields"]);
} }
// Cache the information about existing tables, and their fields // Cache the information about existing tables, and their fields
private static $m_aTablesInfo = array(); private static $m_aTablesInfo = array();
private static function _TablesInfoCacheReset($sTableName = null) private static function _TablesInfoCacheReset($sTableName = null)
@@ -1494,7 +1494,7 @@ class CMDBSource
{ {
throw new MySQLException('Failed to issue SQL query', array('query' => $sSql)); throw new MySQLException('Failed to issue SQL query', array('query' => $sSql));
} }
$aRows = array(); $aRows = array();
while ($aRow = $oResult->fetch_array(MYSQLI_ASSOC)) while ($aRow = $oResult->fetch_array(MYSQLI_ASSOC))
{ {
@@ -1503,7 +1503,7 @@ class CMDBSource
$oResult->free(); $oResult->free();
return $aRows; return $aRows;
} }
/** /**
* Returns the value of the specified server variable * Returns the value of the specified server variable
* @param string $sVarName Name of the server variable * @param string $sVarName Name of the server variable
@@ -1519,7 +1519,7 @@ class CMDBSource
/** /**
* Returns the privileges of the current user * Returns the privileges of the current user
* @return string privileges in a raw format * @return string privileges in a raw format
*/ */
public static function GetRawPrivileges() public static function GetRawPrivileges()
{ {
try try
@@ -1545,8 +1545,8 @@ class CMDBSource
/** /**
* Determine the slave status of the server * Determine the slave status of the server
* @return bool true if the server is slave * @return bool true if the server is slave
*/ */
public static function IsSlaveServer() public static function IsSlaveServer()
{ {
try try

View File

@@ -3,7 +3,7 @@
// //
// This file is part of iTop. // This file is part of iTop.
// //
// iTop is free software; you can redistribute it and/or modify // iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by // it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
@@ -146,18 +146,23 @@ class DBBackup
/** /**
* Create a normalized backup name, depending on the current date/time and Database * Create a normalized backup name, depending on the current date/time and Database
* *
* @param string $sNameSpec Name and path, eventually containing itop placeholders + time formatting following the strftime() format {@link https://www.php.net/manual/fr/function.strftime.php} * @param string|null $sNameSpec Name and path, eventually containing itop placeholders + time formatting following the strftime() format {@link https://www.php.net/manual/fr/function.strftime.php}
* @param \DateTime|null $oDateTime Date time to use for the name * @param \DateTime|null $oDateTime Date time to use for the name
* *
* @return string Name of the backup file WITHOUT the file extension (eg. `.tar.gz`) * @return string Name of the backup file WITHOUT the file extension (eg. `.tar.gz`)
* @since 3.1.0 N°5279 Add $oDateTime parameter * @since 3.1.0 N°5279 Add $oDateTime parameter
*/ */
public function MakeName(string $sNameSpec = "__DB__-%Y-%m-%d", DateTime $oDateTime = null) public function MakeName(?string $sNameSpec = null, ?DateTime $oDateTime = null)
{ {
if ($oDateTime === null) { if ($oDateTime === null) {
$oDateTime = new DateTime(); $oDateTime = new DateTime();
} }
//N°6640
if ($sNameSpec === null) {
$sNameSpec = "__DB__-%Y-%m-%d";
}
$sFileName = $sNameSpec; $sFileName = $sNameSpec;
$sFileName = str_replace('__HOST__', $this->sDBHost, $sFileName); $sFileName = str_replace('__HOST__', $this->sDBHost, $sFileName);
$sFileName = str_replace('__DB__', $this->sDBName, $sFileName); $sFileName = str_replace('__DB__', $this->sDBName, $sFileName);
@@ -222,7 +227,7 @@ class DBBackup
* *
* @param string $sSourceConfigFile * @param string $sSourceConfigFile
* @param string $sTmpFolder * @param string $sTmpFolder
* @param bool $bSkipSQLDumpForTesting * @param bool $bSkipSQLDumpForTesting
* *
* @return array list of files to archive * @return array list of files to archive
* @throws \Exception * @throws \Exception
@@ -273,7 +278,7 @@ class DBBackup
if(!file_exists(APPROOT.'/'.$sExtraFileOrDir)) { if(!file_exists(APPROOT.'/'.$sExtraFileOrDir)) {
continue; // Ignore non-existing files continue; // Ignore non-existing files
} }
$sExtraFullPath = utils::RealPath(APPROOT.'/'.$sExtraFileOrDir, APPROOT); $sExtraFullPath = utils::RealPath(APPROOT.'/'.$sExtraFileOrDir, APPROOT);
if ($sExtraFullPath === false) if ($sExtraFullPath === false)
{ {

View File

@@ -118,7 +118,7 @@ class DBBackupTest extends ItopTestCase
* *
* @return void * @return void
*/ */
public function testMakeName(string $sInputFormat, DateTime $oBackupDateTime, string $sExpectedFilename): void public function testMakeName(?string $sInputFormat, ?DateTime $oBackupDateTime, string $sExpectedFilename): void
{ {
$oConfig = utils::GetConfig(); $oConfig = utils::GetConfig();
@@ -138,6 +138,11 @@ class DBBackupTest extends ItopTestCase
$oBackupDateTime = DateTime::createFromFormat('Y-m-d H:i:s', '1985-07-30 15:30:59'); $oBackupDateTime = DateTime::createFromFormat('Y-m-d H:i:s', '1985-07-30 15:30:59');
return [ return [
'Default format - no params' => [
'__DB__-%Y-%m-%d',
$oBackupDateTime,
static::DUMMY_DB_NAME.'-1985-07-30',
],
'Default format' => [ 'Default format' => [
'__DB__-%Y-%m-%d', '__DB__-%Y-%m-%d',
$oBackupDateTime, $oBackupDateTime,
@@ -160,4 +165,28 @@ class DBBackupTest extends ItopTestCase
], ],
]; ];
} }
/**
* N°6640 - Broken unattended setup with XML backup configuration
*/
public function testMakeNameWithoutParams(): void
{
$oConfig = utils::GetConfig();
// See https://github.com/Combodo/iTop/commit/f7ee21f1d7d1c23910506e9e31b57f33311bd5e0#diff-d693fb790e3463d1aa960c2b8b293532b1bbd12c3b8f885d568d315c404f926aR131
$oConfig->Set('db_host', static::DUMMY_DB_HOST);
$oConfig->Set('db_name', static::DUMMY_DB_NAME);
$oConfig->Set('db_subname', static::DUMMY_DB_SUBNAME);
$oDateTime = new DateTime();
$sExpectedFilename = static::DUMMY_DB_NAME . '-' . $oDateTime->format("Y-m-d");
$oBackup = new DBBackup($oConfig);
$sTestedFilename = $oBackup->MakeName(null);
$this->assertEquals($sExpectedFilename, $sTestedFilename, "Backup filename format doesn't match. Got '$sTestedFilename', expected '$sExpectedFilename'.");
$sTestedFilename = $oBackup->MakeName();
$this->assertEquals($sExpectedFilename, $sTestedFilename, "Backup filename format doesn't match. Got '$sTestedFilename', expected '$sExpectedFilename'.");
}
} }