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 int|string $date_start Date start (now if empty)
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @param string $comment Comment
* @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();
@ -282,7 +283,7 @@ class Contrat extends CommonObject
{
$contratline->context = $this->context;
$result = $contratline->active_line($user, $date_start, -1);
$result = $contratline->active_line($user, $date_start, -1, $comment);
if ($result < 0)
{
$error++;
@ -1468,49 +1469,39 @@ class Contrat extends CommonObject
{
$contractlineid = $this->db->last_insert_id(MAIN_DB_PREFIX."contratdet");
$result=$this->update_statut($user);
if ($result > 0)
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
$contractline = new ContratLigne($this->db);
$contractline->array_options=$array_options;
$contractline->id=$contractlineid;
$result=$contractline->insertExtraFields();
if ($result < 0)
{
$contractline = new ContratLigne($this->db);
$contractline->array_options=$array_options;
$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;
$this->error[]=$contractline->error;
$error++;
}
}
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();
return -1;
}
else
{
$this->db->commit();
return $contractlineid;
}
}
else
{
@ -3095,13 +3086,6 @@ class ContratLigne extends CommonObjectLine
{
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;
$this->db->begin();
@ -3119,15 +3103,26 @@ class ContratLigne extends CommonObjectLine
if ($resql) {
// Call trigger
$result = $this->call_trigger('LINECONTRACT_ACTIVATE', $user);
if ($result < 0) {
$error++;
if ($result < 0) $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();
return -1;
}
// End call triggers
$this->db->commit();
return 1;
} else {
$this->error = $this->db->lasterror();
$this->db->rollback();