From f0ab6e60ec53d61a0b5abe52ea5c9a5dec754456 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 26 Nov 2018 13:31:05 +0100 Subject: [PATCH] FIX Loading translation of cron tasks --- htdocs/core/class/translate.class.php | 27 ++++++++-------- htdocs/cron/card.php | 1 + htdocs/cron/class/cronjob.class.php | 44 ++++++++++++++++----------- scripts/cron/cron_run_jobs.php | 6 +++- 4 files changed, 44 insertions(+), 34 deletions(-) diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 599bf25d33d..a8d22b61257 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -189,7 +189,7 @@ class Translate // Load $this->tab_translate[] from database - if (empty($loadfromfileonly) && count($this->tab_translate) == 0) $this->loadFromDatabase($db); // Nothing was loaded yet, so we load database. + if (empty($loadfromfileonly) && count($this->tab_translate) == 0) $this->loadFromDatabase($db); // No translation was never loaded yet, so we load database. $newdomain = $domain; @@ -231,7 +231,8 @@ class Translate $filelangexists=is_file($file_lang_osencoded); - //dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' newdomain='.$domain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists); + //dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' domain='.$domain.' newdomain='.$newdomain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists); + //print 'Try to read for alt='.$alt.' langofdir='.$langofdir.' domain='.$domain.' newdomain='.$newdomain.' modulename='.$modulename.' this->_tab_loaded[newdomain]='.$this->_tab_loaded[$newdomain].' file_lang='.$file_lang." => filelangexists=".$filelangexists."\n"; if ($filelangexists) { @@ -354,12 +355,12 @@ class Translate $this->load($domain,$alt+1,$stopafterdirection,$langofdir); } - // We already are the reference file. No more files to scan to complete. + // We are in the pass of the reference file. No more files to scan to complete. if ($alt == 2) { - if ($fileread) $this->_tab_loaded[$newdomain]=1; // Set domain file as loaded + if ($fileread) $this->_tab_loaded[$newdomain]=1; // Set domain file as found so loaded - if (empty($this->_tab_loaded[$newdomain])) $this->_tab_loaded[$newdomain]=2; // Set this file as found + if (empty($this->_tab_loaded[$newdomain])) $this->_tab_loaded[$newdomain]=2; // Set this file as not found } // This part is deprecated and replaced with table llx_overwrite_trans @@ -410,22 +411,18 @@ class Translate //dol_syslog("Translate::Load Start domain=".$domain." alt=".$alt." forcelangdir=".$forcelangdir." this->defaultlang=".$this->defaultlang); $newdomain = $domain; - $modulename = ''; - // Check cache - if (! empty($this->_tab_loaded[$newdomain])) // File already loaded for this domain + // Check cache + if (! empty($this->_tab_loaded[$newdomain])) // File already loaded for this domain 'database' { //dol_syslog("Translate::Load already loaded for newdomain=".$newdomain); return 0; } - $this->_tab_loaded[$newdomain] = 1; // We want to be sure this function is called once only. + $this->_tab_loaded[$newdomain] = 1; // We want to be sure this function is called once only for domain 'database' $fileread=0; - $langofdir=(empty($forcelangdir)?$this->defaultlang:$forcelangdir); - - // Redefine alt - $alt=2; + $langofdir=$this->defaultlang; if (empty($langofdir)) // This may occurs when load is called without setting the language and without providing a value for forcelangdir { @@ -434,14 +431,14 @@ class Translate } // TODO Move cache read out of loop on dirs or at least filelangexists - $found=false; + $found=false; // Enable caching of lang file in memory (not by default) $usecachekey=''; // Using a memcached server if (! empty($conf->memcached->enabled) && ! empty($conf->global->MEMCACHED_SERVER)) { - $usecachekey=$newdomain.'_'.$langofdir.'_'.md5($file_lang); // Should not contains special chars + $usecachekey=$newdomain.'_'.$langofdir; // Should not contains special chars } // Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file) else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index 152657e216a..d3c0e8d7992 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -227,6 +227,7 @@ if ($action=='activate') if ($action=='inactive') { $object->status=0; + $object->processing=0; // Add cron task $result = $object->update($user); diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index a71088f3286..df640576d9a 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -1068,8 +1068,9 @@ class Cronjob extends CommonObject // Load langs if (! $error) { - $result=$langs->load($this->module_name.'@'.$this->module_name); - if ($result < 0) + $result=$langs->load($this->module_name); + $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 lang file - ".$langs->error, LOG_ERR); $this->error = $langs->error; @@ -1138,14 +1139,17 @@ class Cronjob extends CommonObject $conf->entity = $savcurrententity; return -1; } + // Load langs - $result=$langs->load($this->module_name . '@' . $this->module_name); - if ($result<0) + $result=$langs->load($this->module_name); + $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->entity = $savcurrententity; return -1; } + dol_syslog(get_class($this) . "::run_jobs " . $this->libname . "::" . $this->methodename."(" . $this->params . ");", LOG_DEBUG); $params_arr = explode(", ", $this->params); if (!is_array($params_arr)) @@ -1301,7 +1305,7 @@ class Cronjob extends CommonObject */ function getLibStatut($mode=0) { - return $this->LibStatut($this->status,$mode); + return $this->LibStatut($this->status, $mode, $this->processing); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps @@ -1310,43 +1314,47 @@ class Cronjob extends CommonObject * * @param int $status Id statut * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @param int $processing 0=Not running, 1=Running * @return string Label of status */ - function LibStatut($status,$mode=0) + function LibStatut($status, $mode=0, $processing=0) { // phpcs:enable global $langs; $langs->load('users'); + $moretext = ''; + if ($processing) $moretext=' ('.$langs->trans("Running").')'; + if ($mode == 0) { - if ($status == 1) return $langs->trans('Enabled'); - elseif ($status == 0) return $langs->trans('Disabled'); + if ($status == 1) return $langs->trans('Enabled').$moretext; + elseif ($status == 0) return $langs->trans('Disabled').$moretext; } elseif ($mode == 1) { - if ($status == 1) return $langs->trans('Enabled'); - elseif ($status == 0) return $langs->trans('Disabled'); + if ($status == 1) return $langs->trans('Enabled').$moretext; + elseif ($status == 0) return $langs->trans('Disabled').$moretext; } elseif ($mode == 2) { - if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"').' '.$langs->trans('Enabled'); - elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled'); + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"').' '.$langs->trans('Enabled').$moretext; + elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled').$moretext; } elseif ($mode == 3) { - if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"'); - elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"'); + if ($status == 1) return img_picto($langs->trans('Enabled').$moretext,'statut4','class="pictostatus"'); + elseif ($status == 0) return img_picto($langs->trans('Disabled').$moretext,'statut5','class="pictostatus"'); } elseif ($mode == 4) { - if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"').' '.$langs->trans('Enabled'); - elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled'); + if ($status == 1) return img_picto($langs->trans('Enabled').$moretext,'statut4','class="pictostatus"').' '.$langs->trans('Enabled').$moretext; + elseif ($status == 0) return img_picto($langs->trans('Disabled').$moretext,'statut5','class="pictostatus"').' '.$langs->trans('Disabled').$moretext; } elseif ($mode == 5) { - if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"'); - elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"'); + if ($status == 1) return $langs->trans('Enabled').$moretext.' '.img_picto($langs->trans('Enabled').$moretext,'statut4','class="pictostatus"'); + elseif ($status == 0) return $langs->trans('Disabled').$moretext.' '.img_picto($langs->trans('Disabled').$moretext,'statut5','class="pictostatus"'); } } } diff --git a/scripts/cron/cron_run_jobs.php b/scripts/cron/cron_run_jobs.php index 861e0e3b2dd..873fc0ae9fb 100755 --- a/scripts/cron/cron_run_jobs.php +++ b/scripts/cron/cron_run_jobs.php @@ -186,7 +186,7 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0)) //If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now)) { - echo " - qualified\n"; + echo " - qualified"; dol_syslog("cron_run_jobs.php line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc')); @@ -214,6 +214,8 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0)) $nbofjobslaunchedok++; } + echo " - result of run_jobs = ".$result; + // we re-program the next execution and stores the last execution time for this job $result=$cronjob->reprogram_jobs($userlogin, $now); if ($result<0) @@ -223,6 +225,8 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0)) dol_syslog("cron_run_jobs.php::reprogram_jobs Error ".$cronjob->error, LOG_ERR); exit(-1); } + + echo " - reprogrammed\n"; } else {