2
0
forked from Wavyzz/dolibarr

Qual: Fix WARNING messages in syslog - add getCallerInfoString() (#31351)

* Qual: Fix dolIsTms() call with empty string

# Qual: Fix dolIsTms() call with empty string

The dolibarr log indicated that dolIsTms() was called with the
empty string:

- Add code to log the caller in the log;
- Fix the dolIsTms() calls by updating project/element.php

* Fix comparison of ''<0

# Fix comparison of ''<0

As ''<0 is true, non-existing errors were added resulting in
Try to add a message in stack, but value to add is empty message
in the log.
This commit is contained in:
MDW
2024-10-13 17:17:37 +02:00
committed by GitHub
parent a6ff3c6135
commit 611019ec4d
3 changed files with 30 additions and 4 deletions

View File

@@ -546,7 +546,7 @@ class FormProjets extends Form
global $conf, $langs; global $conf, $langs;
if ($table_element == 'projet_task') { if ($table_element == 'projet_task') {
return ''; // Special cas of element we never link to a project (already always done) return ''; // Special case of element we never link to a project (already always done)
} }
$linkedtothirdparty = false; $linkedtothirdparty = false;

View File

@@ -372,7 +372,7 @@ function isModEnabled($module)
function isDolTms($timestamp) function isDolTms($timestamp)
{ {
if ($timestamp === '') { if ($timestamp === '') {
dol_syslog('Using empty string for a timestamp is deprecated, prefer use of null when calling page '.$_SERVER["PHP_SELF"], LOG_NOTICE); dol_syslog('Using empty string for a timestamp is deprecated, prefer use of null when calling page '.$_SERVER["PHP_SELF"] . getCallerInfoString(), LOG_NOTICE);
return false; return false;
} }
if (is_null($timestamp) || !is_numeric($timestamp)) { if (is_null($timestamp) || !is_numeric($timestamp)) {
@@ -2186,6 +2186,25 @@ function dol_ucwords($string, $encoding = "UTF-8")
} }
} }
/**
* Get caller info as a string that can be appended to a log message.
*
* @return string
*/
function getCallerInfoString()
{
$backtrace = debug_backtrace();
$msg = "";
if (count($backtrace) >= 2) {
$trace = $backtrace[1];
if (isset($trace['file'], $trace['line'])) {
$msg = " From {$trace['file']}:{$trace['line']}.";
}
}
return $msg;
}
/** /**
* Write log message into outputs. Possible outputs can be: * Write log message into outputs. Possible outputs can be:
* SYSLOG_HANDLERS = ["mod_syslog_file"] file name is then defined by SYSLOG_FILE * SYSLOG_HANDLERS = ["mod_syslog_file"] file name is then defined by SYSLOG_FILE
@@ -9891,7 +9910,7 @@ function setEventMessage($mesgs, $style = 'mesgs', $noduplicate = 0, $attop = 0)
function setEventMessages($mesg, $mesgs, $style = 'mesgs', $messagekey = '', $noduplicate = 0, $attop = 0) function setEventMessages($mesg, $mesgs, $style = 'mesgs', $messagekey = '', $noduplicate = 0, $attop = 0)
{ {
if (empty($mesg) && empty($mesgs)) { if (empty($mesg) && empty($mesgs)) {
dol_syslog("Try to add a message in stack, but value to add is empty message", LOG_WARNING); dol_syslog("Try to add a message in stack, but value to add is empty message" . getCallerInfoString(), LOG_WARNING);
} else { } else {
if ($messagekey) { if ($messagekey) {
// Complete message with a js link to set a cookie "DOLHIDEMESSAGE".$messagekey; // Complete message with a js link to set a cookie "DOLHIDEMESSAGE".$messagekey;

View File

@@ -172,6 +172,13 @@ if ($id == '' && $ref == '') {
exit(); exit();
} }
if ($dates === '') {
$dates = null;
}
if ($datee === '') {
$datee = null;
}
$mine = GETPOST('mode') == 'mine' ? 1 : 0; $mine = GETPOST('mode') == 'mine' ? 1 : 0;
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
@@ -1099,7 +1106,7 @@ foreach ($listofreferent as $key => $value) {
if (!getDolGlobalString('PROJECT_LINK_ON_OVERWIEW_DISABLED') && $idtofilterthirdparty && !in_array($tablename, $exclude_select_element)) { if (!getDolGlobalString('PROJECT_LINK_ON_OVERWIEW_DISABLED') && $idtofilterthirdparty && !in_array($tablename, $exclude_select_element)) {
$selectList = $formproject->select_element($tablename, $idtofilterthirdparty, 'minwidth300 minwidth75imp', -2, empty($project_field) ? 'fk_projet' : $project_field, $langs->trans("SelectElement")); $selectList = $formproject->select_element($tablename, $idtofilterthirdparty, 'minwidth300 minwidth75imp', -2, empty($project_field) ? 'fk_projet' : $project_field, $langs->trans("SelectElement"));
if ($selectList < 0) { if ((int) $selectList < 0) { // cast to int because ''<0 is true.
setEventMessages($formproject->error, $formproject->errors, 'errors'); setEventMessages($formproject->error, $formproject->errors, 'errors');
} elseif ($selectList) { } elseif ($selectList) {
// Define form with the combo list of elements to link // Define form with the combo list of elements to link