diff --git a/dev/setup/phpunit/setup_conf.sh b/dev/setup/phpunit/setup_conf.sh index c174c7e8d31..95fc8d10a60 100755 --- a/dev/setup/phpunit/setup_conf.sh +++ b/dev/setup/phpunit/setup_conf.sh @@ -129,6 +129,14 @@ if [ "$DB" = 'mysql' ] || [ "$DB" = 'mariadb' ] || [ "$DB" = 'postgresql' ]; the ${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e 'FLUSH PRIVILEGES;' sum=$(find "${TRAVIS_BUILD_DIR}/htdocs/install" -type f -exec md5sum {} + | LC_ALL=C sort | md5sum) + cnt=$(find "${TRAVIS_BUILD_DIR}/htdocs/install" -type f -exec md5sum {} + | wc) + echo "OLDSUM $sum COUNT:$cnt" + + # shellcheck disable=2046 + sum=$(md5sum $(find "${TRAVIS_BUILD_DIR}/htdocs/install" -type f) | LC_ALL=C sort | md5sum) + # shellcheck disable=2046 + cnt=$(md5sum $(find "${TRAVIS_BUILD_DIR}/htdocs/install" -type f) | wc) + echo "NEWSUM $sum COUNT:$cnt" load_cache=0 if [ -r "$DB_CACHE_FILE".md5 ] && [ -r "$DB_CACHE_FILE" ] && [ -x "$(which "${MYSQLDUMP}")" ] ; then cache_sum="$(<"$DB_CACHE_FILE".md5)" diff --git a/htdocs/core/class/ldap.class.php b/htdocs/core/class/ldap.class.php index 53c04e833e1..9a0efe83e37 100644 --- a/htdocs/core/class/ldap.class.php +++ b/htdocs/core/class/ldap.class.php @@ -540,6 +540,7 @@ class Ldap } } else { if (is_resource($this->connection)) { + // @phan-suppress-next-line PhanTypeMismatchArgumentInternalReal $this->result = @ldap_unbind($this->connection); } } diff --git a/htdocs/core/login/functions_ldap.php b/htdocs/core/login/functions_ldap.php index a3769f9fff6..0e190d1a31e 100644 --- a/htdocs/core/login/functions_ldap.php +++ b/htdocs/core/login/functions_ldap.php @@ -255,7 +255,7 @@ function check_user_password_ldap($usertotest, $passwordtotest, $entitytotest) $ldap->ldapErrorText = ldap_error($ldap->connection); dol_syslog("functions_ldap::check_user_password_ldap ".$ldap->ldapErrorCode." ".$ldap->ldapErrorText); } catch (Throwable $exception) { - $ldap->ldapErrorCode = ''; + $ldap->ldapErrorCode = 0; $ldap->ldapErrorText = ''; dol_syslog('functions_ldap::check_user_password_ldap '.$exception, LOG_WARNING); } diff --git a/htdocs/core/modules/syslog/mod_syslog_file.php b/htdocs/core/modules/syslog/mod_syslog_file.php index df3ceedcfd5..d60fbb6ea1e 100644 --- a/htdocs/core/modules/syslog/mod_syslog_file.php +++ b/htdocs/core/modules/syslog/mod_syslog_file.php @@ -10,7 +10,13 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/syslog/logHandler.php'; */ class mod_syslog_file extends LogHandler { + /** + * @var string + */ public $code = 'file'; + /** + * @var float|int Last log time, used to compute delay + */ public $lastTime = 0; /** @@ -50,7 +56,7 @@ class mod_syslog_file extends LogHandler /** * Is the logger active ? * - * @return int 1 if logger enabled + * @return int<0,1> If logger enabled */ public function isActive() { @@ -60,7 +66,7 @@ class mod_syslog_file extends LogHandler /** * Return array of configuration data * - * @return array Return array of configuration data + * @return array Return array of configuration data */ public function configure() { @@ -128,10 +134,23 @@ class mod_syslog_file extends LogHandler return $suffixinfilename ? preg_replace('/\.log$/i', $suffixinfilename.'.log', $tmp) : $tmp; } + + // @phan-suppress-next-line PhanPluginDuplicateArrayKey + const DOL_LOG_LEVELS = array( + LOG_EMERG => 'EMERG', + LOG_ALERT => 'ALERT', + LOG_CRIT => 'CRIT', + LOG_ERR => 'ERR', + LOG_WARNING => 'WARNING', + LOG_NOTICE => 'NOTICE', + LOG_INFO => 'INFO', + LOG_DEBUG => 'DEBUG' + ); + /** * Export the message * - * @param array $content Array containing the info about the message + * @param array{level:int,ip:string,ospid:string,osuser:string,message:string} $content Array containing the info about the message * @param string $suffixinfilename When output is a file, append this suffix into default log filename. * @return void * @phan-suppress PhanPluginDuplicateArrayKey @@ -142,50 +161,44 @@ class mod_syslog_file extends LogHandler return; // Global option to disable output of this handler } + + // Prepare log message + + $delay = ""; + if (getDolGlobalString('MAIN_SYSLOG_SHOW_DELAY')) { + $now = microtime(true); + $delay = " ".sprintf("%05.3f", $this->lastTime != 0 ? $now - $this->lastTime : 0); + $this->lastTime = $now; + } + $message = dol_print_date(dol_now('gmt'), 'standard', 'gmt').$delay." ".sprintf("%-7s", self::DOL_LOG_LEVELS[$content['level']])." ".sprintf("%-15s", $content['ip']); + $message .= " ".sprintf("%7s", dol_trunc($content['ospid'], 7, 'right', 'UTF-8', 1)); + $message .= " ".sprintf("%6s", dol_trunc($content['osuser'], 6, 'right', 'UTF-8', 1)); + // @phan-suppress-next-line PhanParamSuspiciousOrder + $message .= " ".($this->ident > 0 ? str_pad('', ((int) $this->ident), ' ') : '').$content['message']; + $message .= "\n"; + + + // Write log message + $logfile = $this->getFilename($suffixinfilename); - // Test constant SYSLOG_FILE_NO_ERROR (should stay a constant defined with define('SYSLOG_FILE_NO_ERROR',1); + $result = false; if (defined('SYSLOG_FILE_NO_ERROR')) { - $filefd = @fopen($logfile, 'a+'); + $filefd = @fopen($logfile, "a"); } else { - $filefd = fopen($logfile, 'a+'); + $filefd = fopen($logfile, "a"); } - if (!$filefd) { - if (!defined('SYSLOG_FILE_NO_ERROR') || !constant('SYSLOG_FILE_NO_ERROR')) { - global $dolibarr_main_prod; - // Do not break dolibarr usage if log fails - //throw new Exception('Failed to open log file '.basename($logfile)); - print 'Failed to open log file '.($dolibarr_main_prod ? basename($logfile) : $logfile); - } - } else { - // @phan-suppress-next-line PhanPluginDuplicateArrayKey - $logLevels = array( - LOG_EMERG => 'EMERG', - LOG_ALERT => 'ALERT', - LOG_CRIT => 'CRIT', - LOG_ERR => 'ERR', - LOG_WARNING => 'WARNING', - LOG_NOTICE => 'NOTICE', - LOG_INFO => 'INFO', - LOG_DEBUG => 'DEBUG' - ); - - $delay = ""; - if (getDolGlobalString('MAIN_SYSLOG_SHOW_DELAY')) { - $now = microtime(true); - $delay = " ".sprintf("%05.3f", $this->lastTime != 0 ? $now - $this->lastTime : 0); - $this->lastTime = $now; - } - - // @phan-suppress-next-line PhanParamSuspiciousOrder - $message = dol_print_date(dol_now('gmt'), 'standard', 'gmt').$delay." ".sprintf("%-7s", $logLevels[$content['level']])." ".sprintf("%-15s", $content['ip']); - $message .= " ".sprintf("%7s", dol_trunc($content['ospid'], 7, 'right', 'UTF-8', 1)); - $message .= " ".sprintf("%6s", dol_trunc($content['osuser'], 6, 'right', 'UTF-8', 1)); - $message .= " ".($this->ident > 0 ? str_pad(((string) ''), ((int) $this->ident), ((string) ' ')) : '').$content['message']; - fwrite($filefd, $message."\n"); + if ($filefd !== false) { + $result = fwrite($filefd, $message); fclose($filefd); dolChmod($logfile); } + if ($result === false && (!defined('SYSLOG_FILE_NO_ERROR') || !constant('SYSLOG_FILE_NO_ERROR'))) { + global $dolibarr_main_prod; + // Do not break dolibarr usage if log fails + //throw new Exception('Failed to open log file '.basename($logfile)); + print 'Failed to write to log file '.($dolibarr_main_prod ? basename($logfile) : $logfile); + } } } diff --git a/htdocs/website/class/websitepage.class.php b/htdocs/website/class/websitepage.class.php index 6797af1bbbe..bc79fe87d7c 100644 --- a/htdocs/website/class/websitepage.class.php +++ b/htdocs/website/class/websitepage.class.php @@ -707,7 +707,7 @@ class WebsitePage extends CommonObject if ($istranslation) { if (is_null($website)) { - $website = new Website($db); + $website = new Website($this->db); } $website->fetch($object->fk_website);