From 2a3516d59334e76f4b7531214c033d8c3e613163 Mon Sep 17 00:00:00 2001 From: Timothee Date: Wed, 19 Jun 2024 09:47:48 +0200 Subject: [PATCH] Reapply "Merge remote-tracking branch 'origin/support/3.1' into support/3.2" This reverts commit 3233b9776f96689881caf8b9328dd42684e0322b. --- core/cmdbsource.class.inc.php | 112 +++++++++++++++++- .../portal/templates/layout.html.twig | 4 +- setup/setuputils.class.inc.php | 8 ++ 3 files changed, 119 insertions(+), 5 deletions(-) diff --git a/core/cmdbsource.class.inc.php b/core/cmdbsource.class.inc.php index 3ef37ae9b..376b47664 100644 --- a/core/cmdbsource.class.inc.php +++ b/core/cmdbsource.class.inc.php @@ -29,6 +29,100 @@ use Combodo\iTop\Core\DbConnectionWrapper; require_once('MyHelpers.class.inc.php'); require_once(APPROOT.'core/kpi.class.inc.php'); +class MySQLException extends CoreException +{ + /** + * MySQLException constructor. + * + * @param string $sIssue + * @param array $aContext + * @param \Exception $oException + * @param \mysqli $oMysqli to use when working with a custom mysqli instance + */ + public function __construct($sIssue, $aContext, $oException = null, $oMysqli = null) + { + + if ($oException != null) + { + $aContext['mysql_errno'] = $oException->getCode(); + $this->code = $oException->getCode(); + $aContext['mysql_error'] = $oException->getMessage(); + } + else if ($oMysqli != null) + { + $aContext['mysql_errno'] = $oMysqli->errno; + $this->code = $oMysqli->errno; + $aContext['mysql_error'] = $oMysqli->error; + } + else + { + $aContext['mysql_errno'] = CMDBSource::GetErrNo(); + $this->code = CMDBSource::GetErrNo(); + $aContext['mysql_error'] = CMDBSource::GetError(); + } + parent::__construct($sIssue, $aContext); + //if is connection error, don't log the default message with password in + if (mysqli_connect_errno()) { + error_log($this->message); + error_reporting(0); + } + } +} + +/** + * Class MySQLQueryHasNoResultException + * + * @since 2.5.0 + */ +class MySQLQueryHasNoResultException extends MySQLException +{ + +} + +/** + * Class MySQLHasGoneAwayException + * + * @since 2.5.0 + * @see itop bug 1195 + * @see https://dev.mysql.com/doc/refman/5.7/en/gone-away.html + */ +class MySQLHasGoneAwayException extends MySQLException +{ + /** + * can not be a constant before PHP 5.6 (http://php.net/manual/fr/language.oop5.constants.php) + * + * @return int[] + */ + public static function getErrorCodes() + { + return array( + 2006, + 2013, + ); + } + + public function __construct($sIssue, $aContext) + { + parent::__construct($sIssue, $aContext, null); + } +} + +/** + * @since 2.7.0 N°679 + */ +class MySQLNoTransactionException extends MySQLException +{ + +} + +/** + * @since 2.7.8 3.0.3 3.1.0 N°5538 + */ +class MySQLTransactionNotClosedException extends MySQLException +{ + +} + /** * CMDBSource @@ -1169,8 +1263,8 @@ class CMDBSource */ public static function IsSameFieldTypes($sItopGeneratedFieldType, $sDbFieldType) { - list($sItopFieldDataType, $sItopFieldTypeOptions, $sItopFieldOtherOptions) = static::GetFieldDataTypeAndOptions($sItopGeneratedFieldType); - list($sDbFieldDataType, $sDbFieldTypeOptions, $sDbFieldOtherOptions) = static::GetFieldDataTypeAndOptions($sDbFieldType); + [$sItopFieldDataType, $sItopFieldTypeOptions, $sItopFieldOtherOptions] = static::GetFieldDataTypeAndOptions($sItopGeneratedFieldType); + [$sDbFieldDataType, $sDbFieldTypeOptions, $sDbFieldOtherOptions] = static::GetFieldDataTypeAndOptions($sDbFieldType); if (strcasecmp($sItopFieldDataType, $sDbFieldDataType) !== 0) { @@ -1603,7 +1697,19 @@ class CMDBSource return false; } - /** + public static function GetClusterNb() + { + $result = 0; + $sSql = "SHOW STATUS LIKE 'wsrep_cluster_size';"; + $aRows = self::QueryToArray($sSql); + if (count($aRows) > 0) + { + $result = $aRows[0]['Value']; + } + return intval($result); + } + + /** * @see https://dev.mysql.com/doc/refman/5.7/en/charset-database.html * @return string query to upgrade database charset and collation if needed, null if not * @throws \MySQLException diff --git a/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig b/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig index 11fc6de0c..2b1780082 100644 --- a/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig +++ b/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig @@ -473,8 +473,8 @@ sBody = '{{ 'Error:XHR:Fail'|dict_format(constant('ITOP_APPLICATION_SHORT'))|escape('js') }}'; } var oModalElem = $('#modal-for-alert'); - oModalElem.find('.modal-content .modal-header .modal-title').html(sTitle); - oModalElem.find('.modal-content .modal-body .alert').addClass('alert-danger').html(sBody); + oModalElem.find('.modal-content .modal-header .modal-title').text(sTitle); + oModalElem.find('.modal-content .modal-body .alert').addClass('alert-danger').text(sBody); oModalElem.modal('show'); }; {% endblock %} diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index 9bca214ce..f86a04a99 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -1297,6 +1297,12 @@ EOF $aResult['checks'][] = new CheckResult(CheckResult::INFO, "MySQL server's max_connections is set to $iMaxConnections."); } + $iClusters = $oDBSource->GetClusterNb(); + if ($iClusters > 0) { + SetupLog::Warning('Warning - Galera can lead to malfunctions and data corruption. Combodo does not support this type of infrastructure.'); + $aResult['checks'][] = new CheckResult(CheckResult::WARNING, 'Galera can lead to malfunctions and data corruption. Combodo does not support this type of infrastructure.'); + } + try { $aResult['databases'] = $oDBSource->ListDB(); } @@ -1412,6 +1418,8 @@ EOF public static function AsyncCheckDB($oPage, $aParameters) { + SetupPage::log('Info - CheckDB'); + $sDBServer = $aParameters['db_server']; $sDBUser = $aParameters['db_user']; $sDBPwd = $aParameters['db_pwd'];