From 4475df14b4efa0c8e500f1629102bd882138088e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 23 Apr 2020 12:54:28 +0200 Subject: [PATCH] Finish removal of duplicate hook/trigger --- .../fournisseur.commande.dispatch.class.php | 21 ++------ htdocs/reception/card.php | 39 +++++++-------- htdocs/reception/class/reception.class.php | 49 ++++++------------- 3 files changed, 37 insertions(+), 72 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php index 6a7d8a3e8ba..d7b8807bb28 100644 --- a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php +++ b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php @@ -210,22 +210,11 @@ class CommandeFournisseurDispatch extends CommonObject } } - // Actions on extra fields (by external module or standard code) - // TODO le hook fait double emploi avec le trigger !! - $hookmanager->initHooks(array('commandefournisseurdispatchdao')); - $parameters = array('id'=>$this->id); - $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if (empty($reshook)) - { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $result = $this->insertExtraFields(); - - if ($result < 0) - { - $error++; - } - } + // Create extrafields + if (! $error) + { + $result=$this->insertExtraFields(); + if ($result < 0) $error++; } // Commit or rollback diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php index 1269a99d1ea..9c6e8df76f1 100644 --- a/htdocs/reception/card.php +++ b/htdocs/reception/card.php @@ -186,30 +186,25 @@ if (empty($reshook)) if ($action == 'update_extras') { - // Fill array 'array_options' with data from update form - $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute')); - if ($ret < 0) $error++; + $object->oldcopy = dol_clone($object); - if (!$error) - { - // Actions on extra fields (by external module or standard code) - // TODO le hook fait double emploi avec le trigger !! - $hookmanager->initHooks(array('receptiondao')); - $parameters = array('id' => $object->id); - $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks - if (empty($reshook)) { - $result = $object->insertExtraFields(); - if ($result < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } elseif ($reshook < 0) - $error++; - } + // Fill array 'array_options' with data from update form + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); + if ($ret < 0) $error++; - if ($error) - $action = 'edit_extras'; + if (!$error) + { + // Actions on extra fields + $result = $object->insertExtraFields('RECEPTION_MODIFY'); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + } + + if ($error) + $action = 'edit_extras'; } // Create reception diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 1679f186a72..b09a5918def 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -305,24 +305,12 @@ class Reception extends CommonObject } } - // Actions on extra fields (by external module or standard code) - // TODO le hook fait double emploi avec le trigger !! - $action = 'add'; - $hookmanager->initHooks(array('receptiondao')); - $parameters = array('socid'=>$this->id); - $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if (empty($reshook)) + // Create extrafields + if (! $error) { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $result = $this->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } + $result=$this->insertExtraFields(); + if ($result < 0) $error++; } - elseif ($reshook < 0) $error++; if (!$error && !$notrigger) { @@ -330,29 +318,22 @@ class Reception extends CommonObject $result = $this->call_trigger('RECEPTION_CREATE', $user); if ($result < 0) { $error++; } // End call triggers + } - if (!$error) - { - $this->db->commit(); - return $this->id; - } - else - { - foreach ($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); - } - $this->db->rollback(); - return -1 * $error; - } + if (!$error) + { + $this->db->commit(); + return $this->id; } else { - $error++; - $this->error = $this->db->lasterror()." - sql=$sql"; + foreach ($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } $this->db->rollback(); - return -3; + return -1 * $error; } } else