From a3533177466b18e73888ff14689b9286858dff74 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Wed, 20 Oct 2021 17:26:32 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B04289=20Fix=20privUITransactionFile=20gen?= =?UTF-8?q?erating=20error=20if=20MetaModel=20not=20loaded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/transaction.class.inc.php | 29 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/application/transaction.class.inc.php b/application/transaction.class.inc.php index 56307a3574..b83230a61c 100644 --- a/application/transaction.class.inc.php +++ b/application/transaction.class.inc.php @@ -100,7 +100,7 @@ public static function RemoveTransaction($id) * The original mechanism for storing transaction information as an array in the $_SESSION variable * * Warning, since 2.6.0 the session is regenerated on each login (see PR #20) ! - * Also, we saw some problems when using memcached as the PHP session implementation (see N°1835) + * Also, we saw some problems when using memcached as the PHP session implementation (see N°1835) */ class privUITransactionSession { @@ -353,22 +353,35 @@ protected static function Error($sText) { self::Write('Error | '.$sText); } - + + protected static function IsLogEnabled() { + $oConfig = MetaModel::GetConfig(); + if (is_null($oConfig)) { + return false; + } + + $bLogTransactions = $oConfig->Get('log_transactions'); + if (true === $bLogTransactions) { + return true; + } + + return false; + } + protected static function Write($sText) { - $bLogEnabled = MetaModel::GetConfig()->Get('log_transactions'); - if ($bLogEnabled) - { + if (false === static::IsLogEnabled()) { + return; + } + $hLogFile = @fopen(APPROOT.'log/transactions.log', 'a'); - if ($hLogFile !== false) - { + if ($hLogFile !== false) { flock($hLogFile, LOCK_EX); $sDate = date('Y-m-d H:i:s'); fwrite($hLogFile, "$sDate | $sText\n"); fflush($hLogFile); flock($hLogFile, LOCK_UN); fclose($hLogFile); - } } } }