Skip to content

Commit

Permalink
FIX: Contract's trigger problem
Browse files Browse the repository at this point in the history
  • Loading branch information
KreizIT committed Jul 3, 2014
1 parent 685b7b2 commit f0323e5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 49 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -13,6 +13,7 @@ For users:
- Fix: [ bug #1470, #1472, #1473] User trigger problem
- Fix: [ bug #1489, #1491 ] Intervention trigger problem
- Fix: [ bug #1492, #1493 ] Member trigger problem
- Fix: [ bug #1474, #1475 ] Contract trigger problem

For translators:
- Update language files.
Expand Down
89 changes: 40 additions & 49 deletions htdocs/contrat/class/contrat.class.php
Expand Up @@ -158,12 +158,10 @@ function active_line($user, $line_id, $date, $date_end='', $comment='')
$resql = $this->db->query($sql);
if ($resql)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('CONTRACT_SERVICE_ACTIVATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('CONTRACT_SERVICE_ACTIVATE',$user);
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
// End call triggers

$this->db->commit();
return 1;
Expand Down Expand Up @@ -206,12 +204,10 @@ function close_line($user, $line_id, $date_end, $comment='')
$resql = $this->db->query($sql);
if ($resql)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('CONTRACT_SERVICE_CLOSE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('CONTRACT_SERVICE_CLOSE',$user);
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
// End call triggers

$this->db->commit();
return 1;
Expand Down Expand Up @@ -322,6 +318,7 @@ function validate($user, $force_number='')
dol_syslog(get_class($this)."::validate Echec update - 10 - sql=".$sql, LOG_ERR);
dol_print_error($this->db);
$error++;
$this->error=$this->db->lasterror();
}

if (! $error)
Expand Down Expand Up @@ -365,12 +362,10 @@ function validate($user, $force_number='')
// Trigger calls
if (! $error)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('CONTRACT_VALIDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('CONTRACT_VALIDATE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
}
else
Expand All @@ -386,7 +381,6 @@ function validate($user, $force_number='')
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
return -1;
}

Expand Down Expand Up @@ -756,12 +750,10 @@ function create($user)

if (! $error)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('CONTRACT_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('CONTRACT_CREATE',$user);
if ($result < 0) { $error++; }
// End call triggers

if (! $error)
{
Expand All @@ -776,7 +768,6 @@ function create($user)
}
else
{
$this->error=$interface->error;
dol_syslog(get_class($this)."::create - 30 - ".$this->error, LOG_ERR);

$this->db->rollback();
Expand Down Expand Up @@ -903,14 +894,10 @@ function delete($user)

if (! $error)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('CONTRACT_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('CONTRACT_DELETE',$user);
if ($result < 0) { $error++; }
// End call triggers
}

if (! $error)
Expand Down Expand Up @@ -938,8 +925,7 @@ function delete($user)
return 1;
}
else
{
$this->error=$this->db->error();
{
dol_syslog(get_class($this)."::delete ERROR ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
Expand Down Expand Up @@ -1255,6 +1241,9 @@ function deleteline($idline,$user)

if ($this->statut >= 0)
{

$this->db->begin();

$sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet";
$sql.= " WHERE rowid=".$idline;

Expand All @@ -1264,16 +1253,16 @@ function deleteline($idline,$user)
{
$this->error="Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}

// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('LINECONTRACT_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('LINECONTRACT_DELETE',$user);
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
// End call triggers

$this->db->commit();
return 1;
}
else
Expand Down Expand Up @@ -2064,6 +2053,8 @@ function update($user, $notrigger=0)
$this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
}

$this->db->begin();

// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET";
$sql.= " fk_contrat='".$this->fk_contrat."',";
Expand Down Expand Up @@ -2111,19 +2102,19 @@ function update($user, $notrigger=0)
{
$this->error="Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}

if (! $notrigger)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('LINECONTRACT_UPDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('LINECONTRACT_UPDATE',$user);
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
// End call triggers
}


$this->db->commit();
return 1;
}

Expand Down

0 comments on commit f0323e5

Please sign in to comment.