From 9b164b907c1a9e9b641ff7bd9d4c308e9e36ba83 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 16 Jan 2023 19:25:54 +0100 Subject: [PATCH] Add warehouse modify and create triggers. Clean and remove deprecated vars. --- htdocs/product/stock/class/entrepot.class.php | 52 ++++++++++++------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 065883e7a2c..ce5bef9c939 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -182,16 +182,17 @@ class Entrepot extends CommonObject /** * Creation d'un entrepot en base * - * @param User $user Object user that create the warehouse + * @param User $user Object user that create the warehouse + * @param bool $notrigger false=launch triggers after, true=disable triggers * @return int >0 if OK, =<0 if KO */ - public function create($user) + public function create($user, $notrigger = false) { global $conf; $error = 0; - $this->label = trim(!empty($this->label) ? $this->label : $this->libelle); + $this->label = trim($this->label); // Error if label not defined if ($this->label == '') { @@ -222,14 +223,21 @@ class Entrepot extends CommonObject // Actions on extra fields if (!$error) { - if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; } } + if (!$error && !$notrigger) { + // Call triggers + $result = $this->call_trigger('WAREHOUSE_CREATE', $user); + if ($result < 0) { + $error++; + } + // End call triggers + } + if (!$error) { $this->db->commit(); return $id; @@ -254,11 +262,12 @@ class Entrepot extends CommonObject /** * Update properties of a warehouse * - * @param int $id id of warehouse to modify - * @param User $user User object + * @param int $id id of warehouse to modify + * @param User $user User object + * @param bool $notrigger false=launch triggers after, true=disable trigge * @return int >0 if OK, <0 if KO */ - public function update($id, $user) + public function update($id, $user, $notrigger = false) { global $conf; @@ -267,9 +276,6 @@ class Entrepot extends CommonObject if (empty($id)) { $id = $this->id; } - if (empty($this->label)) { - $this->label = $this->libelle; // For backward compatibility - } // Check if new parent is already a child of current warehouse if (!empty($this->fk_parent)) { @@ -281,7 +287,7 @@ class Entrepot extends CommonObject } } - $this->label = trim(!empty($this->label) ? $this->label : $this->libelle); + $this->label = trim($this->label); $this->description = trim($this->description); @@ -324,6 +330,15 @@ class Entrepot extends CommonObject } } + if (!$error && !$notrigger) { + // Call triggers + $result = $this->call_trigger('WAREHOUSE_MODIFY', $user); + if ($result < 0) { + $error++; + } + // End call triggers + } + if (!$error) { $this->db->commit(); return 1; @@ -461,7 +476,6 @@ class Entrepot extends CommonObject $this->fk_project = $obj->fk_project; $this->ref = $obj->label; $this->label = $obj->label; - $this->libelle = $obj->label; // deprecated $this->description = $obj->description; $this->statut = $obj->statut; $this->lieu = $obj->lieu; @@ -705,7 +719,7 @@ class Entrepot extends CommonObject if (isset($this->statut)) { $label .= ' '.$this->getLibStatut(5); } - $label .= '
'.$langs->trans('Ref').': '.(empty($this->ref) ? (empty($this->label) ? $this->libelle : $this->label) : $this->ref); + $label .= '
'.$langs->trans('Ref').': '.(empty($this->ref) ? $this->label : $this->ref); if (!empty($this->lieu)) { $label .= '
'.$langs->trans('LocationSummary').': '.$this->lieu; } @@ -742,7 +756,7 @@ class Entrepot extends CommonObject $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); } if ($withpicto != 2) { - $result .= (($showfullpath || !empty($conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO)) ? $this->get_full_arbo() : (empty($this->label) ? $this->libelle : $this->label)); + $result .= (($showfullpath || !empty($conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO)) ? $this->get_full_arbo() : $this->label); } $result .= $linkend; @@ -798,7 +812,7 @@ class Entrepot extends CommonObject // phpcs:enable global $user, $langs, $conf; - $TArbo = array(empty($this->label) ? $this->libelle : $this->label); + $TArbo = array($this->label); $protection = 100; // We limit depth of warehouses to 100