FIX: Properties updated if update successfull.

This commit is contained in:
Laurent Destailleur 2018-02-26 20:12:29 +01:00
parent 7e48db2869
commit 941a8e5e2b

View File

@ -262,9 +262,10 @@ class Contrat extends CommonObject
* @param User $user Object User making action * @param User $user Object User making action
* @param int|string $date_start Date start (now if empty) * @param int|string $date_start Date start (now if empty)
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @param string $comment Comment
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function activateAll($user, $date_start='', $notrigger=0) function activateAll($user, $date_start='', $notrigger=0, $comment='')
{ {
if (empty($date_start)) $date_start = dol_now(); if (empty($date_start)) $date_start = dol_now();
@ -282,7 +283,7 @@ class Contrat extends CommonObject
{ {
$contratline->context = $this->context; $contratline->context = $this->context;
$result = $contratline->active_line($user, $date_start, -1); $result = $contratline->active_line($user, $date_start, -1, $comment);
if ($result < 0) if ($result < 0)
{ {
$error++; $error++;
@ -1468,49 +1469,39 @@ class Contrat extends CommonObject
{ {
$contractlineid = $this->db->last_insert_id(MAIN_DB_PREFIX."contratdet"); $contractlineid = $this->db->last_insert_id(MAIN_DB_PREFIX."contratdet");
$result=$this->update_statut($user); if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
if ($result > 0)
{ {
$contractline = new ContratLigne($this->db);
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used $contractline->array_options=$array_options;
$contractline->id=$contractlineid;
$result=$contractline->insertExtraFields();
if ($result < 0)
{ {
$contractline = new ContratLigne($this->db); $this->error[]=$contractline->error;
$contractline->array_options=$array_options; $error++;
$contractline->id=$contractlineid;
$result=$contractline->insertExtraFields();
if ($result < 0)
{
$this->error[]=$contractline->error;
$error++;
}
}
if (empty($error)) {
// Call trigger
$result=$this->call_trigger('LINECONTRACT_INSERT',$user);
if ($result < 0)
{
$error++;
}
// End call triggers
}
if ($error)
{
$this->db->rollback();
return -1;
}
else
{
$this->db->commit();
return $contractlineid;
} }
} }
else
if (empty($error)) {
// Call trigger
$result=$this->call_trigger('LINECONTRACT_INSERT',$user);
if ($result < 0)
{
$error++;
}
// End call triggers
}
if ($error)
{ {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
else
{
$this->db->commit();
return $contractlineid;
}
} }
else else
{ {
@ -3095,13 +3086,6 @@ class ContratLigne extends CommonObjectLine
{ {
global $langs, $conf; global $langs, $conf;
// Update object
$this->date_ouverture = $date;
$this->date_fin_validite = $date_end;
$this->fk_user_ouverture = $user->id;
$this->date_cloture = null;
$this->commentaire = $comment;
$error = 0; $error = 0;
$this->db->begin(); $this->db->begin();
@ -3119,15 +3103,26 @@ class ContratLigne extends CommonObjectLine
if ($resql) { if ($resql) {
// Call trigger // Call trigger
$result = $this->call_trigger('LINECONTRACT_ACTIVATE', $user); $result = $this->call_trigger('LINECONTRACT_ACTIVATE', $user);
if ($result < 0) { if ($result < 0) $error++;
$error++; // End call triggers
if (! $error)
{
$this->statut = 4;
$this->date_ouverture = $date;
$this->date_fin_validite = $date_end;
$this->fk_user_ouverture = $user->id;
$this->date_cloture = null;
$this->commentaire = $comment;
$this->db->commit();
return 1;
}
else
{
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
// End call triggers
$this->db->commit();
return 1;
} else { } else {
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
$this->db->rollback(); $this->db->rollback();