From 6a294eb02a43ff65c49fbb4c7558b776c2926ed0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 18 Jan 2015 12:29:55 +0100 Subject: [PATCH] Fixed: Better fix for backward compatibility --- htdocs/comm/action/class/actioncomm.class.php | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index dd7819f7dbb..2116b4c2530 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -118,6 +118,13 @@ class ActionComm extends CommonObject $error=0; $now=dol_now(); + // Check parameters + if (empty($this->userownerid)) + { + $this->errors[]='ErrorPropertyUserowneridNotDefined'; + return -1; + } + // Clean parameters $this->label=dol_trunc(trim($this->label),128); $this->location=dol_trunc(trim($this->location),128); @@ -137,12 +144,13 @@ class ActionComm extends CommonObject if ($this->elementtype=='facture') $this->elementtype='invoice'; if ($this->elementtype=='commande') $this->elementtype='order'; if ($this->elementtype=='contrat') $this->elementtype='contract'; - + $userownerid=$this->userownerid; $userdoneid=$this->userdoneid; - // Be sure assigned user array is not empty. - if (count($this->userassigned) == 0) $this->userassigned = array('id'=>$userownerid); + // Be sure assigned user is defined as an array of array('id'=>,'mandatory'=>,...). + if (empty($this->userassigned) || count($this->userassigned) == 0 || ! is_array($this->userassigned)) + $this->userassigned = array($userownerid=>array('id'=>$userownerid)); if (! $this->type_id || ! $this->type_code) { @@ -229,6 +237,12 @@ class ActionComm extends CommonObject { foreach($this->userassigned as $key => $val) { + if (! is_array($val)) // For backward compatibility when val=id + { + $tmpid=$val; + $val=array('id'=>$val); + } + $sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; $sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", ".($val['mandatory']?$val['mandatory']:'0').", ".($val['transparency']?$val['transparency']:'0').", ".($val['answer_status']?$val['answer_status']:'0').")";