Finish removal of duplicate hook/trigger

This commit is contained in:
Laurent Destailleur 2020-04-23 12:54:28 +02:00
parent 46716f2259
commit 4475df14b4
3 changed files with 37 additions and 72 deletions

View File

@ -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

View File

@ -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

View File

@ -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