From af7c1d8da17661a9a525521745d986f8f5c10e87 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 27 Mar 2018 18:39:18 +0200 Subject: [PATCH 01/13] fix error log --- htdocs/core/class/commonobject.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8d08b828fd1..7fc131fbd82 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4787,6 +4787,7 @@ abstract class CommonObject if (! $resql) { $this->error=$this->db->lasterror(); + dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); $this->db->rollback(); return -1; } @@ -5804,7 +5805,7 @@ abstract class CommonObject { $labeltoshow = ''.$labeltoshow.''; } - + if (empty($onetrtd)) $out .= ''; else $out .= ''; From a89983ef5c9cef908b5c4085463983a28fed4a45 Mon Sep 17 00:00:00 2001 From: atm-ph Date: Wed, 28 Mar 2018 15:41:10 +0200 Subject: [PATCH 02/13] Fix error on creating company with external module in 'custom' folder with a file to generate accountancy code --- htdocs/societe/class/societe.class.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 9a43c5b3cfa..fd6f062b609 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2515,17 +2515,12 @@ class Societe extends CommonObject $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); foreach ($dirsociete as $dirroot) { - if (file_exists(DOL_DOCUMENT_ROOT.'/'.$dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.".php")) - { - $file=$dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.".php"; - break; - } + $res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php'); + if ($res) break; } - if (! empty($file)) + if ($res) { - dol_include_once($file); - $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON; $mod = new $classname; From 3dd9d47089271e26a20f9cb0a69375e37df4e64f Mon Sep 17 00:00:00 2001 From: Sean Wang Date: Thu, 29 Mar 2018 14:49:06 +0800 Subject: [PATCH 03/13] Fix wrong approve time in expense report The approve time showed was 8 hours more than the real time. Checking database turned out that it had the wrong data(+8 hours). After checking every timezone related settings were correct, I found that it do twice idate() in setApproved(). Since we have idate() in $sql, we don't need the idate() at the line 1249. --- htdocs/expensereport/class/expensereport.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 9f51b04a1f1..c2eacf4aa76 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1246,7 +1246,7 @@ class ExpenseReport extends CommonObject $error = 0; // date approval - $this->date_approve = $this->db->idate($now); + $this->date_approve = $now; if ($this->fk_statut != 5) { $this->db->begin(); From 78812ef82687fa5ee9a0529ffb560879f896c50f Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Thu, 29 Mar 2018 09:35:47 +0200 Subject: [PATCH 04/13] better error management --- htdocs/core/class/commonobject.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 7fc131fbd82..44218f12dfd 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2307,11 +2307,13 @@ abstract class CommonObject if (! $this->table_element) { + $this->error='update_note was called on objet with property table_element not defined'; dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); return -1; } if (! in_array($suffix,array('','_public','_private'))) { + $this->error='update_note Parameter suffix must be empty, \'_private\' or \'_public\''; dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); return -2; } From 0e986b8f97c7e6d0af571d56e1168bab712e3d25 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 29 Mar 2018 13:48:09 +0200 Subject: [PATCH 05/13] Update societe.class.php --- htdocs/societe/class/societe.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index fd6f062b609..729995a81d0 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2511,7 +2511,7 @@ class Societe extends CommonObject if (! empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) { - $file=''; + $res=false; $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); foreach ($dirsociete as $dirroot) { From fdfcb96176d17f38a34ca5076eebfb610c332abe Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 29 Mar 2018 15:31:21 +0200 Subject: [PATCH 06/13] Fix length of combobox --- htdocs/expensereport/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 82c3461848b..2c63101b6fd 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2088,7 +2088,7 @@ else if (! empty($conf->projet->enabled)) { print ''; - $formproject->select_projects(-1, $line->fk_projet,'fk_projet', 0, 0, 1, 1); + $formproject->select_projects(-1, $line->fk_projet,'fk_projet', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth300'); print ''; } From 84bb4c6ad7b7321a9b1b1315cfc1f6365fc94b5f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Mar 2018 19:51:53 +0200 Subject: [PATCH 07/13] FIX With x extrafields, request for multicompany label was done x times --- htdocs/core/class/extrafields.class.php | 40 +++++++++++++------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 3d934baaf75..4c3fb340264 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -733,11 +733,26 @@ class ExtraFields // To avoid conflicts with external modules. TODO Remove this. if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label; + // Set array of label of entity + // TODO Remove completely loading of label. This should be done by presentation. + $labelmulticompany=array(); + if (!empty($conf->multicompany->enabled)) + { + $sql_entity_name='SELECT rowid, label FROM '.MAIN_DB_PREFIX.'entity WHERE rowid in (0,'.$conf->entity.')'; + $resql_entity_name=$this->db->query($sql_entity_name); + if ($resql_entity_name) + { + while ($obj = $this->db->fetch_object($resql_entity_name)) + { + $labelmulticompany[$obj->rowid]=$obj->label; + } + } + } + // We should not have several time this log. If we have, there is some optimization to do by calling a simple $object->fetch_optionals() that include cache management. dol_syslog("fetch_name_optionals_label elementtype=".$elementtype); - $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,fielddefault,fieldcomputed"; - $sql .= ",entity"; + $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,fielddefault,fieldcomputed,entity"; $sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; $sql.= " WHERE entity IN (0,".$conf->entity.")"; if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; @@ -772,6 +787,7 @@ class ExtraFields $this->attribute_langfile[$tab->name]=$tab->langs; $this->attribute_list[$tab->name]=$tab->list; $this->attribute_entityid[$tab->name]=$tab->entity; + $this->attribute_entitylabel[$tab->name]=(empty($labelmulticompany[$tab->entity])?'Entity'.$tab->entity:$labelmulticompany[$tab->entity]); // New usage $this->attributes[$tab->elementtype]['type'][$tab->name]=$tab->type; @@ -789,26 +805,12 @@ class ExtraFields $this->attributes[$tab->elementtype]['langfile'][$tab->name]=$tab->langs; $this->attributes[$tab->elementtype]['list'][$tab->name]=$tab->list; $this->attributes[$tab->elementtype]['entityid'][$tab->name]=$tab->entity; + $this->attributes[$tab->elementtype]['entitylabel'][$tab->name]=(empty($labelmulticompany[$tab->entity])?'Entity'.$tab->entity:$labelmulticompany[$tab->entity]); - if (!empty($conf->multicompany->enabled)) - { - $sql_entity_name='SELECT label FROM '.MAIN_DB_PREFIX.'entity WHERE rowid='.$tab->entity; - $resql_entity_name=$this->db->query($sql_entity_name); - if ($resql_entity_name) - { - if ($this->db->num_rows($resql_entity_name)) - { - if ($obj = $this->db->fetch_object($resql_entity_name)) - { - $this->attribute_entitylabel[$tab->name]=$obj->label; - $this->attributes[$tab->elementtype]['entitylabel'][$tab->name]=$obj->label; - } - } - } - } + $this->attributes[$tab->elementtype]['loaded']=1; } } - if ($elementtype) $this->attributes[$elementtype]['loaded']=1; + if ($elementtype) $this->attributes[$elementtype]['loaded']=1; // If nothing found, we also save tag 'loaded' } else { From fba40575f789e8cefbbafd15d0c557b03ed613cd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 Apr 2018 16:39:48 +0200 Subject: [PATCH 08/13] Remove dead code --- htdocs/admin/payment.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/htdocs/admin/payment.php b/htdocs/admin/payment.php index fdf0e9f9bee..339b4fef566 100644 --- a/htdocs/admin/payment.php +++ b/htdocs/admin/payment.php @@ -257,17 +257,6 @@ print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$con print ''; print "\n"; -// Add js auto fill amount on paiement form -/* always on now -$var=! $var; -print ''; -print $langs->trans("JSOnPaimentBill"); -print ''; -print $form->selectyesno("INVOICE_AUTO_FILLJS",$conf->global->INVOICE_AUTO_FILLJS,1); -print ''; -print "\n"; -*/ - print ''; print '
'; From 8595d7621bd7d5a3801b8fa03522f6e5bc723f96 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 Apr 2018 23:30:23 +0200 Subject: [PATCH 09/13] Fix POST mut use method POST no GET --- htdocs/admin/modules.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 00c8d14219e..68764be5fc5 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -79,9 +79,9 @@ $familyinfo=array( $param=''; if ($search_keyword) $param.='&search_keyword='.urlencode($search_keyword); -if ($search_status > -1) $param.='&search_status='.urlencode($search_status); -if ($search_nature > -1) $param.='&search_nature='.urlencode($search_nature); -if ($search_version > -1) $param.='&search_version='.urlencode($search_version); +if ($search_status && $search_status != '-1') $param.='&search_status='.urlencode($search_status); +if ($search_nature && $search_nature != '-1') $param.='&search_nature='.urlencode($search_nature); +if ($search_version && $search_version != '-1') $param.='&search_version='.urlencode($search_version); $dirins=DOL_DOCUMENT_ROOT.'/custom'; $urldolibarrmodules='https://www.dolistore.com/'; @@ -466,7 +466,7 @@ if ($mode == 'common') { dol_set_focus('#search_keyword'); - print '
'; + print ''; if ($optioncss != '') print ''; print ''; print ''; From 88b3e08b22f5349b26fcc808b8e15254d51f4e51 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 5 Apr 2018 11:34:26 +0200 Subject: [PATCH 10/13] FIX filter/sorting on extrafield on contact list from contact tab --- htdocs/core/lib/company.lib.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index c7b75521a59..663821db0c2 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -772,6 +772,7 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='') $form = new Form($db); + $optioncss = GETPOST('optioncss', 'alpha'); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST('page','int'); @@ -823,7 +824,7 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='') { if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha'); } - + $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); // Purge search criteria if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers @@ -870,9 +871,12 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='') print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print "\n".''."\n"; - $param="socid=".$object->id; - if ($search_status != '') $param.='&search_status='.$search_status; - if ($search_name != '') $param.='&search_name='.urlencode($search_name); + $param="socid=".urlencode($object->id); + if ($search_status != '') $param.='&search_status='.urlencode($search_status); + if ($search_name != '') $param.='&search_name='.urlencode($search_name); + if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); + // Add $param from extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; $sql = "SELECT t.rowid, t.lastname, t.firstname, t.fk_pays as country_id, t.civility, t.poste, t.phone as phone_pro, t.phone_mobile, t.phone_perso, t.fax, t.email, t.skype, t.statut, t.photo,"; $sql .= " t.civility as civility_id, t.address, t.zip, t.town"; @@ -880,7 +884,9 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)"; $sql .= " WHERE t.fk_soc = ".$object->id; if ($search_status!='' && $search_status != '-1') $sql .= " AND t.statut = ".$db->escape($search_status); - if ($search_name) $sql .= " AND (t.lastname LIKE '%".$db->escape($search_name)."%' OR t.firstname LIKE '%".$db->escape($search_name)."%')"; + if ($search_name) $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name); + // Add where from extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; if ($sortfield == "t.name") $sql.=" ORDER BY t.lastname $sortorder, t.firstname $sortorder"; else $sql.= " ORDER BY $sortfield $sortorder"; @@ -1044,7 +1050,7 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='') // Edit if ($user->rights->societe->contact->creer) { - print ''; + print ''; print img_edit(); print ''; } From 0223d54107f4e57e2b88e71fb4c6f401f2a3bbb1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 5 Apr 2018 12:28:52 +0200 Subject: [PATCH 11/13] FIX Support or multicompany for sheduled jobs FIX Use priority to define order of sheduled jobs Conflicts: htdocs/cron/list.php --- htdocs/core/modules/DolibarrModules.class.php | 5 ++- htdocs/core/modules/modCron.class.php | 6 +-- htdocs/cron/card.php | 16 ++++++++ htdocs/cron/class/cronjob.class.php | 39 +++++++++++++------ htdocs/cron/list.php | 2 +- scripts/cron/cron_run_jobs.php | 10 ++--- 6 files changed, 55 insertions(+), 23 deletions(-) diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index eaf674d5eea..ef129a421ce 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -1313,6 +1313,7 @@ class DolibarrModules // Can not be abstract, because we need to insta { foreach ($this->cronjobs as $key => $value) { + $entity = isset($this->cronjobs[$key]['entity'])?$this->cronjobs[$key]['entity']:$conf->entity; $label = isset($this->cronjobs[$key]['label'])?$this->cronjobs[$key]['label']:''; $jobtype = isset($this->cronjobs[$key]['jobtype'])?$this->cronjobs[$key]['jobtype']:''; $class = isset($this->cronjobs[$key]['class'])?$this->cronjobs[$key]['class']:''; @@ -1334,7 +1335,7 @@ class DolibarrModules // Can not be abstract, because we need to insta if ($objectname) $sql.= " AND objectname = '".$this->db->escape($objectname)."'"; if ($method) $sql.= " AND methodename = '".$this->db->escape($method)."'"; if ($command) $sql.= " AND command = '".$this->db->escape($command)."'"; - $sql.= " AND entity = ".$conf->entity; + $sql.= " AND entity = ".$entity; // Must be exact entity $now=dol_now(); @@ -1371,7 +1372,7 @@ class DolibarrModules // Can not be abstract, because we need to insta if(is_int($unitfrequency)){ $sql.= "'".$this->db->escape($unitfrequency)."', "; } if(is_int($priority)) {$sql.= "'".$this->db->escape($priority)."', ";} if(is_int($status)){ $sql.= "'".$this->db->escape($status)."', "; } - $sql.= $conf->entity.","; + $sql.= $entity.","; $sql.= "'".$this->db->escape($test)."'"; $sql.= ")"; diff --git a/htdocs/core/modules/modCron.class.php b/htdocs/core/modules/modCron.class.php index 8afcc26c80f..621b887ca3b 100644 --- a/htdocs/core/modules/modCron.class.php +++ b/htdocs/core/modules/modCron.class.php @@ -97,9 +97,9 @@ class modCron extends DolibarrModules // Cronjobs $this->cronjobs = array( - 0=>array('label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>2, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>50, 'status'=>1, 'test'=>true), - 1=>array('label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none,auto,1,auto,10', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>90, 'status'=>0, 'test'=>in_array($db->type, array('mysql', 'mysqli'))), - // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24) + 0=>array('entity'=>0, 'label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>2, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>50, 'status'=>1, 'test'=>true), + 1=>array('entity'=>0, 'label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none,auto,1,auto,10', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>90, 'status'=>0, 'test'=>in_array($db->type, array('mysql', 'mysqli'))), + // 1=>array('entity'=>0, 'label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24) ); // Permissions diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index 8c97bc4e2c8..707b75b95fe 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -614,6 +614,22 @@ else print $langs->trans($object->note); print ""; + if (! empty($conf->multicompany->enabled)) + { + print '"; + } + print '
'; + print $langs->trans('Entity').""; + if (! $object->entity) + { + print $langs->trans("AllEntities"); + } + else + { + $mc->getInfo($obj->entity); + print $mc->label; + } + print "
'; print '
'; diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 46ad08f849b..f890391431b 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -34,6 +34,7 @@ class Cronjob extends CommonObject public $table_element='cronjob'; //!< Name of table without prefix where object is stored public $picto = 'cron'; + public $entity; public $jobtype; public $tms=''; public $datec=''; @@ -153,7 +154,7 @@ class Cronjob extends CommonObject // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob("; - + $sql.= "entity,"; $sql.= "datec,"; $sql.= "jobtype,"; $sql.= "label,"; @@ -183,6 +184,7 @@ class Cronjob extends CommonObject $sql.= "libname,"; $sql.= "test"; $sql.= ") VALUES ("; + $sql.= " ".(! isset($this->entity)?$conf->entity:$this->db->escape($this->entity)).","; $sql.= " '".$this->db->idate($now)."',"; $sql.= " ".(! isset($this->jobtype)?'NULL':"'".$this->db->escape($this->jobtype)."'").","; $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").","; @@ -265,8 +267,8 @@ class Cronjob extends CommonObject function fetch($id) { $sql = "SELECT"; - $sql.= " t.rowid,"; - + $sql.= " t.rowid,"; + $sql.= " t.entity,"; $sql.= " t.tms,"; $sql.= " t.datec,"; $sql.= " t.jobtype,"; @@ -310,7 +312,7 @@ class Cronjob extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->rowid; - + $this->entity = $obj->entity; $this->tms = $this->db->jdate($obj->tms); $this->datec = $this->db->jdate($obj->datec); $this->label = $obj->label; @@ -417,7 +419,7 @@ class Cronjob extends CommonObject } } - $sql.= " ORDER BY $sortfield $sortorder "; + $sql.= $this->db->order($sortfield,$sortorder); if (!empty($limit) && !empty($offset)) { $sql.= $this->db->plimit($limit + 1,$offset); } @@ -445,7 +447,6 @@ class Cronjob extends CommonObject $line->id = $obj->rowid; $line->ref = $obj->rowid; - $line->entity = $obj->entity; $line->tms = $this->db->jdate($obj->tms); $line->datec = $this->db->jdate($obj->datec); @@ -575,7 +576,7 @@ class Cronjob extends CommonObject // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET"; - + $sql.= " entity=".(isset($this->entity)?$this->db->escape($this->entity):$conf->entity).","; $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").","; $sql.= " jobtype=".(isset($this->jobtype)?"'".$this->db->escape($this->jobtype)."'":"null").","; $sql.= " command=".(isset($this->command)?"'".$this->db->escape($this->command)."'":"null").","; @@ -773,7 +774,7 @@ class Cronjob extends CommonObject { $this->id=0; $this->ref=0; - + $this->entity=0; $this->tms=''; $this->datec=''; $this->label=''; @@ -930,6 +931,16 @@ class Cronjob extends CommonObject return -1; } + // Force the environment of running to the environment declared for job, so jobs launched from command line will run into correct environment + // When job is ran from GUI, the environment should already be same, except if job has entity 0 (visible into all environments) + if ($conf->entity != $this->entity && $this->entity > 0) + { + 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->entity = $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'; $user=new User($this->db); $result=$user->fetch('',$userlogin); @@ -937,6 +948,7 @@ class Cronjob extends CommonObject { $this->error="User Error:".$user->error; dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); + $conf->entity = $savcurrententity; return -1; } else @@ -945,6 +957,7 @@ class Cronjob extends CommonObject { $this->error=" User user login:".$userlogin." do not exists"; dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); + $conf->entity = $savcurrententity; return -1; } } @@ -976,6 +989,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->entity = $savcurrententity; return -1; } @@ -1073,6 +1087,7 @@ class Cronjob extends CommonObject { $this->error = $langs->trans('CronCannotLoadLib') . ': ' . $libpath; dol_syslog(get_class($this) . "::run_jobs " . $this->error, LOG_ERR); + $conf->entity = $savcurrententity; return -1; } // Load langs @@ -1080,6 +1095,7 @@ class Cronjob extends CommonObject if ($result<0) { 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); @@ -1142,13 +1158,12 @@ class Cronjob extends CommonObject if ($result < 0) { dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); + $conf->entity = $savcurrententity; return -1; } - else - { - return $error?-1:1; - } + $conf->entity = $savcurrententity; + return $error?-1:1; } diff --git a/htdocs/cron/list.php b/htdocs/cron/list.php index ba28d019958..6f4d469cc0a 100644 --- a/htdocs/cron/list.php +++ b/htdocs/cron/list.php @@ -187,7 +187,7 @@ $sql.= " t.nbrun,"; $sql.= " t.libname,"; $sql.= " t.test"; $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t"; -$sql.= " WHERE 1 = 1"; +$sql.= " WHERE entity IN (0,".$conf->entity.")"; if ($status >= 0 && $status < 2) $sql.= " AND t.status = ".(empty($status)?'0':'1'); if ($status == 2) $sql.= " AND t.status = 2"; //Manage filter diff --git a/scripts/cron/cron_run_jobs.php b/scripts/cron/cron_run_jobs.php index 42f7a736b91..246fd3d75b4 100755 --- a/scripts/cron/cron_run_jobs.php +++ b/scripts/cron/cron_run_jobs.php @@ -85,7 +85,7 @@ if ($key != $conf->global->CRON_KEY) // If param userlogin is reserved word 'firstadmin' if ($userlogin == 'firstadmin') { - $sql='SELECT login from '.MAIN_DB_PREFIX.'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1'; + $sql='SELECT login, entity from '.MAIN_DB_PREFIX.'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1'; $resql=$db->query($sql); if ($resql) { @@ -93,7 +93,7 @@ if ($userlogin == 'firstadmin') if ($obj) { $userlogin = $obj->login; - echo "First admin user found is login '".$userlogin."'\n"; + echo "First admin user found is login '".$userlogin."', entity ".$obj->entity."\n"; } } else dol_print_error($db); @@ -132,7 +132,7 @@ if (! empty($id)) { $filter['t.rowid']=$id; } -$result = $object->fetch_all('DESC','t.rowid', 0, 0, 1, $filter, 0); +$result = $object->fetch_all('ASC,ASC,ASC','t.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0); if ($result<0) { echo "Error: ".$object->error; @@ -159,8 +159,8 @@ if(is_array($qualifiedjobs) && (count($qualifiedjobs)>0)) // Loop over job foreach($qualifiedjobs as $line) { - dol_syslog("cron_run_jobs.php cronjobid: ".$line->id, LOG_DEBUG); - echo "cron_run_jobs.php cronjobid: ".$line->id."\n"; + dol_syslog("cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label, LOG_DEBUG); + echo "cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label."\n"; //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)) From 156d26ddb9e1820fad684abc3e70fa03385faff4 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 29 Mar 2018 18:30:31 +0200 Subject: [PATCH 12/13] Fix: backward compatibility --- htdocs/core/class/commonobject.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1387c72adf0..9f252cf63a6 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1358,19 +1358,22 @@ abstract class CommonObject if (empty($format)) $format='text'; if (empty($id_field)) $id_field='rowid'; + $fk_user_field = 'fk_user_modif'; + $error=0; $this->db->begin(); // Special case if ($table == 'product' && $field == 'note_private') $field='note'; + if ($table == 'adherent') $fk_user_field = 'fk_user_mod'; $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); - if (! empty($fuser) && is_object($fuser)) $sql.=", fk_user_modif = ".$fuser->id; - elseif (empty($fuser) || $fuser != 'none') $sql.=", fk_user_modif = ".$user->id; + if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; + elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; $sql.= " WHERE ".$id_field." = ".$id; dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); From 5914bfdf18c44798adbb21484fd933f36b8a9bc2 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 29 Mar 2018 18:36:51 +0200 Subject: [PATCH 13/13] Fix: more complete --- htdocs/core/class/commonobject.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 9f252cf63a6..3d4720147d9 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1366,7 +1366,9 @@ abstract class CommonObject // Special case if ($table == 'product' && $field == 'note_private') $field='note'; - if ($table == 'adherent') $fk_user_field = 'fk_user_mod'; + if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) { + $fk_user_field = 'fk_user_mod'; + } $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'";