From 55b86350ae474b8c4afbbf7cb60e35361c90389a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Thu, 21 Mar 2024 18:35:12 +0100 Subject: [PATCH 1/6] fix phpstan --- htdocs/core/boxes/box_members_by_tags.php | 7 +++---- htdocs/core/boxes/box_members_by_type.php | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/htdocs/core/boxes/box_members_by_tags.php b/htdocs/core/boxes/box_members_by_tags.php index 99c71e59063..e9f4d1c0c6a 100644 --- a/htdocs/core/boxes/box_members_by_tags.php +++ b/htdocs/core/boxes/box_members_by_tags.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2007 Rodolphe Quiedeville * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2015-2023 Frédéric France + * Copyright (C) 2015-2024 Frédéric France * Copyright (C) 2021-2023 Waël Almoman * * This program is free software; you can redistribute it and/or modify @@ -140,12 +140,11 @@ class box_members_by_tags extends ModeleBoxes $line++; $AdherentTag = array(); foreach ($sumMembers as $key => $data) { - $adhtag = new Categorie($this->db); - $adhtag->id = $key; - if ($key == 'total') { break; } + $adhtag = new Categorie($this->db); + $adhtag->id = (int) $key; $adhtag->label = $data['label']; $AdherentTag[$key] = $adhtag; diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index 05f886e2858..d3b065cc7ec 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2007 Rodolphe Quiedeville * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2015-2023 Frederic France + * Copyright (C) 2015-2024 Frédéric France * Copyright (C) 2021-2023 Waël Almoman * * This program is free software; you can redistribute it and/or modify @@ -140,12 +140,11 @@ class box_members_by_type extends ModeleBoxes $line++; $AdherentType = array(); foreach ($sumMembers as $key => $data) { - $adhtype = new AdherentType($this->db); - $adhtype->id = $key; - if ($key == 'total') { break; } + $adhtype = new AdherentType($this->db); + $adhtype->id = (int) $key; $adhtype->label = $data['label']; $AdherentType[$key] = $adhtype; From 34028bac6efc0042cb89029b7bb37cb224fbe292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Thu, 21 Mar 2024 18:39:30 +0100 Subject: [PATCH 2/6] fix phpstan --- htdocs/core/boxes/box_members_by_tags.php | 10 +++++----- htdocs/core/boxes/box_members_by_type.php | 10 +++++----- htdocs/core/boxes/box_members_last_modified.php | 4 ++-- htdocs/core/boxes/box_members_last_subscriptions.php | 10 +++++----- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/htdocs/core/boxes/box_members_by_tags.php b/htdocs/core/boxes/box_members_by_tags.php index e9f4d1c0c6a..20ef8187840 100644 --- a/htdocs/core/boxes/box_members_by_tags.php +++ b/htdocs/core/boxes/box_members_by_tags.php @@ -1,9 +1,9 @@ - * Copyright (C) 2004-2017 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2015-2024 Frédéric France - * Copyright (C) 2021-2023 Waël Almoman +/* Copyright (C) 2003-2007 Rodolphe Quiedeville + * Copyright (C) 2004-2017 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2015-2024 Frédéric France + * Copyright (C) 2021-2023 Waël Almoman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index d3b065cc7ec..63479a55212 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -1,9 +1,9 @@ - * Copyright (C) 2004-2017 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2015-2024 Frédéric France - * Copyright (C) 2021-2023 Waël Almoman +/* Copyright (C) 2003-2007 Rodolphe Quiedeville + * Copyright (C) 2004-2017 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2015-2024 Frédéric France + * Copyright (C) 2021-2023 Waël Almoman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/core/boxes/box_members_last_modified.php b/htdocs/core/boxes/box_members_last_modified.php index 2ef36c822dd..a33b2b7577c 100644 --- a/htdocs/core/boxes/box_members_last_modified.php +++ b/htdocs/core/boxes/box_members_last_modified.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2007 Rodolphe Quiedeville * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2015-2020 Frederic France + * Copyright (C) 2015-2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -110,7 +110,7 @@ class box_members_last_modified extends ModeleBoxes $memberstatic->email = $objp->email; $memberstatic->morphy = $objp->morphy; $memberstatic->company = $objp->company; - $memberstatic->statut = $objp->status; + $memberstatic->status = $objp->status; $memberstatic->date_creation = $datec; $memberstatic->date_modification = $datem; $memberstatic->need_subscription = $objp->subscription; diff --git a/htdocs/core/boxes/box_members_last_subscriptions.php b/htdocs/core/boxes/box_members_last_subscriptions.php index 92d0413c5e7..8dbb96df25f 100644 --- a/htdocs/core/boxes/box_members_last_subscriptions.php +++ b/htdocs/core/boxes/box_members_last_subscriptions.php @@ -1,8 +1,8 @@ - * Copyright (C) 2004-2017 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2015-2020 Frederic France +/* Copyright (C) 2003-2007 Rodolphe Quiedeville + * Copyright (C) 2004-2017 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2015-2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -110,7 +110,7 @@ class box_members_last_subscriptions extends ModeleBoxes $staticmember->email = $obj->email; $staticmember->photo = $obj->photo; $staticmember->morphy = $obj->morphy; - $staticmember->statut = $obj->status; + $staticmember->status = $obj->status; $staticmember->need_subscription = $obj->need_subscription; $staticmember->datefin = $this->db->jdate($obj->date_end_subscription); if (!empty($obj->fk_soc)) { From 2c1e8ff7c359236bd219405a09b40fda49cfd0f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Thu, 21 Mar 2024 19:10:42 +0100 Subject: [PATCH 3/6] fix phpstan --- htdocs/core/boxes/box_graph_invoices_permonth.php | 3 ++- htdocs/core/boxes/box_graph_invoices_peryear.php | 3 ++- htdocs/core/boxes/box_graph_invoices_supplier_permonth.php | 3 ++- htdocs/core/boxes/box_graph_orders_permonth.php | 3 ++- htdocs/core/boxes/box_graph_orders_supplier_permonth.php | 3 ++- htdocs/core/boxes/box_graph_propales_permonth.php | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/htdocs/core/boxes/box_graph_invoices_permonth.php b/htdocs/core/boxes/box_graph_invoices_permonth.php index 74b31a3daaf..f38604467e4 100644 --- a/htdocs/core/boxes/box_graph_invoices_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_permonth.php @@ -1,5 +1,6 @@ + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,7 +69,7 @@ class box_graph_invoices_permonth extends ModeleBoxes //include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; //$facturestatic=new Facture($this->db); - $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1; + $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); if (!getDolGlobalString('GRAPH_USE_FISCAL_YEAR')) { $startmonth = 1; } diff --git a/htdocs/core/boxes/box_graph_invoices_peryear.php b/htdocs/core/boxes/box_graph_invoices_peryear.php index f6decd57660..be20f7ff3c0 100644 --- a/htdocs/core/boxes/box_graph_invoices_peryear.php +++ b/htdocs/core/boxes/box_graph_invoices_peryear.php @@ -1,5 +1,6 @@ + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -65,7 +66,7 @@ class box_graph_invoices_peryear extends ModeleBoxes //include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; //$facturestatic=new Facture($this->db); - $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1; + $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); if (!getDolGlobalString('GRAPH_USE_FISCAL_YEAR')) { $startmonth = 1; } diff --git a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php index 818398324c8..30cc4616d59 100644 --- a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php @@ -1,5 +1,6 @@ + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -66,7 +67,7 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; - $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1; + $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); if (!getDolGlobalString('GRAPH_USE_FISCAL_YEAR')) { $startmonth = 1; } diff --git a/htdocs/core/boxes/box_graph_orders_permonth.php b/htdocs/core/boxes/box_graph_orders_permonth.php index ce11fe9e93d..182b2f5fb72 100644 --- a/htdocs/core/boxes/box_graph_orders_permonth.php +++ b/htdocs/core/boxes/box_graph_orders_permonth.php @@ -1,5 +1,6 @@ + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -67,7 +68,7 @@ class box_graph_orders_permonth extends ModeleBoxes //include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; //$commandestatic=new Commande($this->db); - $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1; + $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); if (!getDolGlobalString('GRAPH_USE_FISCAL_YEAR')) { $startmonth = 1; } diff --git a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php index 9b7e40ab20f..6924bb9d9e8 100644 --- a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php +++ b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php @@ -1,5 +1,6 @@ + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -66,7 +67,7 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; - $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1; + $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); if (!getDolGlobalString('GRAPH_USE_FISCAL_YEAR')) { $startmonth = 1; } diff --git a/htdocs/core/boxes/box_graph_propales_permonth.php b/htdocs/core/boxes/box_graph_propales_permonth.php index 0192ecf2b12..5699d71e678 100644 --- a/htdocs/core/boxes/box_graph_propales_permonth.php +++ b/htdocs/core/boxes/box_graph_propales_permonth.php @@ -1,5 +1,6 @@ + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -67,7 +68,7 @@ class box_graph_propales_permonth extends ModeleBoxes //include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; //$propalstatic=new Propal($this->db); - $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1; + $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); if (!getDolGlobalString('GRAPH_USE_FISCAL_YEAR')) { $startmonth = 1; } From a2974f7778edf443d1ce67ccdc74649f32a96f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Thu, 21 Mar 2024 19:13:33 +0100 Subject: [PATCH 4/6] fix phpstan --- htdocs/core/boxes/box_task.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/boxes/box_task.php b/htdocs/core/boxes/box_task.php index 170dd59e4b1..89f09bf5389 100644 --- a/htdocs/core/boxes/box_task.php +++ b/htdocs/core/boxes/box_task.php @@ -1,6 +1,6 @@ - * Copyright (C) 2015-2021 Frederic France + * Copyright (C) 2015-2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -174,7 +174,7 @@ class box_task extends ModeleBoxes $taskstatic->ref = $objp->ref; $taskstatic->label = $objp->label; $taskstatic->progress = $objp->progress; - $taskstatic->fk_statut = $objp->fk_statut; + $taskstatic->status = $objp->fk_statut; $taskstatic->date_end = $this->db->jdate($objp->datee); $taskstatic->planned_workload = $objp->planned_workload; $taskstatic->duration_effective = $objp->duration_effective; From ce38158c356655af531122636ec21f1bceed86b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Thu, 21 Mar 2024 21:50:42 +0100 Subject: [PATCH 5/6] fix warnings with syslog checkconfiguration --- htdocs/admin/syslog.php | 12 +++++++++--- htdocs/core/modules/syslog/logHandler.php | 7 +++++++ htdocs/core/modules/syslog/mod_syslog_file.php | 11 +++++------ htdocs/core/modules/syslog/mod_syslog_syslog.php | 13 +++++++------ 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/htdocs/admin/syslog.php b/htdocs/admin/syslog.php index 71dc5df45f6..5475e20d0d1 100644 --- a/htdocs/admin/syslog.php +++ b/htdocs/admin/syslog.php @@ -3,6 +3,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2007 Rodolphe Quiedeville * Copyright (C) 2013 Juanjo Menent + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -112,11 +113,16 @@ if ($action == 'set') { dolibarr_del_const($db, 'SYSLOG_HANDLERS', -1); // To be sure there is not a setup into another entity dolibarr_set_const($db, 'SYSLOG_HANDLERS', json_encode($activeModules), 'chaine', 0, '', 0); - + $error = 0; + $errors = []; // Check configuration foreach ($activeModules as $modulename) { $module = new $modulename(); - $error = $module->checkConfiguration(); + $res = $module->checkConfiguration(); + if (!$res) { + $error++; + $errors = array_merge($errors, $module->errors); + } } @@ -125,7 +131,7 @@ if ($action == 'set') { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { $db->rollback(); - setEventMessages($error, $errors, 'errors'); + setEventMessages('', $errors, 'errors'); } } diff --git a/htdocs/core/modules/syslog/logHandler.php b/htdocs/core/modules/syslog/logHandler.php index 0af3f304331..1672a683cb1 100644 --- a/htdocs/core/modules/syslog/logHandler.php +++ b/htdocs/core/modules/syslog/logHandler.php @@ -1,4 +1,6 @@ + */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +26,11 @@ class LogHandler { protected $ident = 0; + /** + * @var string[] Array of errors messages + */ + public $errors = []; + /** * Content of the info tooltip. diff --git a/htdocs/core/modules/syslog/mod_syslog_file.php b/htdocs/core/modules/syslog/mod_syslog_file.php index 3442877dca3..5468923120e 100644 --- a/htdocs/core/modules/syslog/mod_syslog_file.php +++ b/htdocs/core/modules/syslog/mod_syslog_file.php @@ -1,5 +1,6 @@ + * Copyright (C) 2024 Frédéric France */ require_once DOL_DOCUMENT_ROOT.'/core/modules/syslog/logHandler.php'; @@ -78,23 +79,21 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface /** * Return if configuration is valid * - * @return array Array of errors. Empty array if ok. + * @return bool true if ok */ public function checkConfiguration() { global $langs; - $errors = array(); - $filename = $this->getFilename(); if (file_exists($filename) && is_writable($filename)) { dol_syslog('admin/syslog: file '.$filename); + return true; } else { - $errors[] = $langs->trans("ErrorFailedToOpenFile", $filename); + $this->errors[] = $langs->trans("ErrorFailedToOpenFile", $filename); + return false; } - - return $errors; } /** diff --git a/htdocs/core/modules/syslog/mod_syslog_syslog.php b/htdocs/core/modules/syslog/mod_syslog_syslog.php index d3931cf09eb..b2ccf4f997e 100644 --- a/htdocs/core/modules/syslog/mod_syslog_syslog.php +++ b/htdocs/core/modules/syslog/mod_syslog_syslog.php @@ -1,4 +1,6 @@ + */ require_once DOL_DOCUMENT_ROOT.'/core/modules/syslog/logHandler.php'; @@ -77,15 +79,14 @@ class mod_syslog_syslog extends LogHandler implements LogHandlerInterface /** * Return if configuration is valid * - * @return array Array of errors. Empty array if ok. + * @return bool True if ok. */ public function checkConfiguration() { global $conf, $langs; - $errors = array(); + $facility = constant(getDolGlobalString('SYSLOG_FACILITY')); - $facility = constant($conf->global->SYSLOG_FACILITY); if ($facility) { // Only LOG_USER supported on Windows if (!empty($_SERVER["WINDIR"])) { @@ -93,11 +94,11 @@ class mod_syslog_syslog extends LogHandler implements LogHandlerInterface } dol_syslog("admin/syslog: facility ".$facility); + return true; } else { - $errors[] = $langs->trans("ErrorUnknownSyslogConstant", $facility); + $this->errors[] = $langs->trans("ErrorUnknownSyslogConstant", $facility); + return false; } - - return $errors; } /** From c76ab41c91926ee168fd27a3e33a84e11ef03e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Thu, 21 Mar 2024 21:52:02 +0100 Subject: [PATCH 6/6] fix warnings with syslog checkconfiguration --- htdocs/core/modules/syslog/logHandler.php | 4 ++-- htdocs/core/modules/syslog/logHandlerInterface.php | 4 +++- htdocs/core/modules/syslog/mod_syslog_syslog.php | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/syslog/logHandler.php b/htdocs/core/modules/syslog/logHandler.php index 1672a683cb1..e7ec4dbc567 100644 --- a/htdocs/core/modules/syslog/logHandler.php +++ b/htdocs/core/modules/syslog/logHandler.php @@ -87,11 +87,11 @@ class LogHandler * It will be called after setting the configuration. * The function returns an array with error messages * - * @return array + * @return bool */ public function checkConfiguration() { - return array(); + return true; } /** diff --git a/htdocs/core/modules/syslog/logHandlerInterface.php b/htdocs/core/modules/syslog/logHandlerInterface.php index 15ab436f4fa..2613d50f755 100644 --- a/htdocs/core/modules/syslog/logHandlerInterface.php +++ b/htdocs/core/modules/syslog/logHandlerInterface.php @@ -1,4 +1,6 @@ + */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -79,7 +81,7 @@ interface LogHandlerInterface /** * Output log content * - * @param string $content Content to log + * @param array $content Content to log * @return void */ public function export($content); diff --git a/htdocs/core/modules/syslog/mod_syslog_syslog.php b/htdocs/core/modules/syslog/mod_syslog_syslog.php index b2ccf4f997e..8d1457fa2ec 100644 --- a/htdocs/core/modules/syslog/mod_syslog_syslog.php +++ b/htdocs/core/modules/syslog/mod_syslog_syslog.php @@ -83,7 +83,7 @@ class mod_syslog_syslog extends LogHandler implements LogHandlerInterface */ public function checkConfiguration() { - global $conf, $langs; + global $langs; $facility = constant(getDolGlobalString('SYSLOG_FACILITY'));