From c171ba3a45dc9a12ece0e7f8a5bf238a9f86ac54 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Dec 2021 16:07:33 +0100 Subject: [PATCH 1/7] Fix regression in cron jobs --- htdocs/core/class/conf.class.php | 5 +++-- htdocs/cron/class/cronjob.class.php | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 8776060b60f..581de47178c 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -167,15 +167,16 @@ class Conf * Load setup values into conf object (read llx_const) for a specified entity * Note that this->db->xxx, this->file->xxx and this->multicompany have been already loaded when setValues is called. * + * @param DoliDB $db Database handler * @param int $entity Entity to get * @return int < 0 if KO, >= 0 if OK */ - public function setEntityValues($entity) + public function setEntityValues($db, $entity) { if ($this->entity != $entity) { // If we ask to reload setup for a new entity $this->entity = $entity; - return $this->setValues($this->db); + return $this->setValues($db); } return 0; diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 34fe7b6cd58..44564e1b0ab 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -1081,7 +1081,7 @@ class Cronjob extends CommonObject dol_syslog("We try to run a job in entity ".$this->entity." when we are in entity ".$conf->entity, LOG_WARNING); } $savcurrententity = $conf->entity; - $conf->setEntityValues($this->entity); + $conf->setEntityValues($this->db, $this->entity); dol_syslog(get_class($this)."::run_jobs entity for running job is ".$conf->entity); require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; @@ -1090,13 +1090,13 @@ class Cronjob extends CommonObject if ($result < 0) { $this->error = "User Error:".$user->error; dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); - $conf->setEntityValues($savcurrententity); + $conf->setEntityValues($this->db, $savcurrententity); return -1; } else { if (empty($user->id)) { $this->error = " User user login:".$userlogin." do not exists"; dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); - $conf->setEntityValues($savcurrententity); + $conf->setEntityValues($this->db, $savcurrententity); return -1; } } @@ -1126,7 +1126,7 @@ class Cronjob extends CommonObject $result = $this->update($user); // This include begin/commit if ($result < 0) { dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); - $conf->setEntityValues($savcurrententity); + $conf->setEntityValues($this->db, $savcurrententity); return -1; } @@ -1241,7 +1241,7 @@ class Cronjob extends CommonObject if ($ret === false) { $this->error = $langs->trans('CronCannotLoadLib').': '.$libpath; dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); - $conf->setEntityValues($savcurrententity); + $conf->setEntityValues($this->db, $savcurrententity); return -1; } @@ -1250,7 +1250,7 @@ class Cronjob extends CommonObject $result = $langs->load($this->module_name.'@'.$this->module_name); // If this->module_name was an existing language file, this will make nothing if ($result < 0) { // If technical error dol_syslog(get_class($this)."::run_jobs Cannot load module langs".$langs->error, LOG_ERR); - $conf->setEntityValues($savcurrententity); + $conf->setEntityValues($this->db, $savcurrententity); return -1; } @@ -1316,11 +1316,11 @@ class Cronjob extends CommonObject $result = $this->update($user); // This include begin/commit if ($result < 0) { dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); - $conf->setEntityValues($savcurrententity); + $conf->setEntityValues($this->db, $savcurrententity); return -1; } - $conf->setEntityValues($savcurrententity); + $conf->setEntityValues($this->db, $savcurrententity); return $error ?-1 : 1; } From 39ad96c230a9b5b5db6ede0951680d8897d10ca7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Dec 2021 17:47:03 +0100 Subject: [PATCH 2/7] css --- htdocs/holiday/list.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index 0ecdcb2dd69..207c7c31707 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -890,14 +890,15 @@ if ($resql) { $i++; } + // Add a line for total if there is a total to show if (!empty($arrayfields['duration']['checked'])) { - print ''; + print ''; foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) { if ($key == 'duration') { print ''.$totalduration.' '.$langs->trans('DurationDays').''; } else { - print ''; + print ''; } } } From 9c083071b8e3eda104c14b0b32f716d072d18406 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Dec 2021 20:39:53 +0100 Subject: [PATCH 3/7] Better test --- htdocs/public/test/test_exec.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/public/test/test_exec.php b/htdocs/public/test/test_exec.php index a25e860021c..f805cc19b5c 100644 --- a/htdocs/public/test/test_exec.php +++ b/htdocs/public/test/test_exec.php @@ -66,7 +66,7 @@ echo "Test
\n"; $out=''; $ret=0; -$file = '/tmp/aaa'; +$file = '/tmp/test.txt'; $f=fopen($file, 'r'); if ($f) { $s=fread($f, 4096); @@ -76,10 +76,14 @@ if ($f) { print "Failed to open file ".$file."
\n"; } -exec('cat /aaa; ls /dev/std*; sleep 1;', $out, $ret); +print '

'."\n"; + +exec('cat /test.txt; ls /dev/std*; sleep 1;', $out, $ret); print $ret."
\n"; print_r($out); +print '

'."\n"; + $ret = 0; $out = null; exec('/usr/bin/clamdscan --fdpass filethatdoesnotexists.php', $out, $ret); From 2300f1710188dc467e1e4f73c58b389f5fc414cb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Dec 2021 20:40:41 +0100 Subject: [PATCH 4/7] test --- htdocs/public/test/test_exec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/test/test_exec.php b/htdocs/public/test/test_exec.php index f805cc19b5c..3fd66b40635 100644 --- a/htdocs/public/test/test_exec.php +++ b/htdocs/public/test/test_exec.php @@ -78,7 +78,7 @@ if ($f) { print '

'."\n"; -exec('cat /test.txt; ls /dev/std*; sleep 1;', $out, $ret); +exec('cat /test.txt; ls /dev/std*; id; sleep 1;', $out, $ret); print $ret."
\n"; print_r($out); From ac17378972b2168501a0e901f2a8604c3a481937 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Dec 2021 20:41:13 +0100 Subject: [PATCH 5/7] revert --- htdocs/public/test/test_exec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/test/test_exec.php b/htdocs/public/test/test_exec.php index 3fd66b40635..f805cc19b5c 100644 --- a/htdocs/public/test/test_exec.php +++ b/htdocs/public/test/test_exec.php @@ -78,7 +78,7 @@ if ($f) { print '

'."\n"; -exec('cat /test.txt; ls /dev/std*; id; sleep 1;', $out, $ret); +exec('cat /test.txt; ls /dev/std*; sleep 1;', $out, $ret); print $ret."
\n"; print_r($out); From d9aa4713709d3082d40795cddc4a18353efc581a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Dec 2021 01:39:16 +0100 Subject: [PATCH 6/7] Fix color status --- htdocs/hrm/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/hrm/index.php b/htdocs/hrm/index.php index 6bd777401f7..ef231b48eff 100644 --- a/htdocs/hrm/index.php +++ b/htdocs/hrm/index.php @@ -223,6 +223,7 @@ if (!empty($conf->holiday->enabled) && $user->rights->holiday->read) { $holidaystatic->id = $obj->rowid; $holidaystatic->ref = $obj->ref; $holidaystatic->statut = $obj->status; + $holidaystatic->date_debut = $db->jdate($obj->date_start); $userstatic->id = $obj->uid; $userstatic->lastname = $obj->lastname; @@ -243,7 +244,7 @@ if (!empty($conf->holiday->enabled) && $user->rights->holiday->read) { print ''.dol_print_date($db->jdate($obj->date_start), 'day').' '.$langs->trans($listhalfday[$starthalfday]).''; print ''.dol_print_date($db->jdate($obj->date_end), 'day').' '.$langs->trans($listhalfday[$endhalfday]).''; print ''.dol_print_date($db->jdate($obj->dm), 'day').''; - print ''.$holidaystatic->LibStatut($obj->status, 3).''; + print ''.$holidaystatic->LibStatut($obj->status, 3, $holidaystatic->date_debut).''; print ''; $i++; From 1db52532ff34924a60757c9ec873c4c253bf3d66 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Dec 2021 01:50:17 +0100 Subject: [PATCH 7/7] FIX: do not update holiday for closed users --- htdocs/holiday/class/holiday.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 89760c4d1ac..9a45a735716 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -1470,11 +1470,11 @@ class Holiday extends CommonObject $monthLastUpdate = $lastUpdate[4].$lastUpdate[5]; //print 'month: '.$month.' lastUpdate:'.$lastUpdate.' monthLastUpdate:'.$monthLastUpdate;exit; - // Si la date du mois n'est pas la même que celle sauvegardée, on met à jour le timestamp + // If month date is not same than the one of last update (the one we saved in database), then we update the timestamp and balance of each open user. if ($month != $monthLastUpdate) { $this->db->begin(); - $users = $this->fetchUsers(false, false); + $users = $this->fetchUsers(false, false, ' AND u.statut > 0'); $nbUser = count($users); $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET"; @@ -1675,7 +1675,7 @@ class Holiday extends CommonObject * * @param boolean $stringlist If true return a string list of id. If false, return an array with detail. * @param boolean $type If true, read Dolibarr user list, if false, return vacation balance list. - * @param string $filters Filters + * @param string $filters Filters. Warning: This must not contains data from user input. * @return array|string|int Return an array */ public function fetchUsers($stringlist = true, $type = true, $filters = '') @@ -1776,7 +1776,7 @@ class Holiday extends CommonObject // Si faux donc return array // List for Dolibarr users if ($type) { - // If user of Dolibarr + // If we need users of Dolibarr $sql = "SELECT"; if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { $sql .= " DISTINCT";