Merge pull request #1709 from KreizIT/review_trig2

Review trig2
This commit is contained in:
Laurent Destailleur 2014-07-11 12:27:43 +02:00
commit 5c81074483
12 changed files with 317 additions and 262 deletions

View File

@ -26,6 +26,14 @@ For users:
- Fix: [ bug #1494 ] CATEGORY_CREATE and CATEGORY_MODIFY triggers do not intercept trigger action - Fix: [ bug #1494 ] CATEGORY_CREATE and CATEGORY_MODIFY triggers do not intercept trigger action
- Fix: [ bug #1502 ] DON_CREATE trigger does not intercept trigger action - Fix: [ bug #1502 ] DON_CREATE trigger does not intercept trigger action
- Fix: [ bug #1505, #1504] Project trigger problem - Fix: [ bug #1505, #1504] Project trigger problem
- Fix: [ bug #1463, #1464 ] Proposal triggers problem
- Fix: [ bug #1498, #1499 ] Shipment/Delivery triggers problem
- Fix: [ bug #1465, #1466 ] Product triggers problem
- Fix: [ bug #1508 ] STOCK_MOVEMENT does not show trigger error message
- Fix: [ bug #1501 ] DEPLACEMENT_CREATE trigger do not intercept trigger action
- Fix: [ bug #1506, #1507 ] ECM trigger error problem
- Fix: [ bug #1469 ] Triggers CONTACT_MODIFY and CONTACT_DELETE duplicates error message
For translators: For translators:
- Update language files. - Update language files.

View File

@ -856,24 +856,22 @@ class Propal extends CommonObject
if (! $notrigger) if (! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PROPAL_CREATE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PROPAL_CREATE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
} }
else else
{ {
$this->error=$this->db->error();
$error++; $error++;
} }
} }
} }
else else
{ {
$this->error=$this->db->error();
$error++; $error++;
} }
@ -885,7 +883,6 @@ class Propal extends CommonObject
} }
else else
{ {
$this->error=$this->db->error();
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
@ -1006,14 +1003,10 @@ class Propal extends CommonObject
if ($reshook < 0) $error++; if ($reshook < 0) $error++;
} }
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PROPAL_CLONE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PROPAL_CLONE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
// End // End
@ -1326,14 +1319,10 @@ class Propal extends CommonObject
{ {
if (! $notrigger) if (! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PROPAL_VALIDATE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PROPAL_VALIDATE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
if (! $error) if (! $error)
@ -1668,25 +1657,24 @@ class Propal extends CommonObject
{ {
if (! $notrigger) if (! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PROPAL_REOPEN',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PROPAL_REOPEN',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error)
{
if (!empty($this->errors))
{ {
foreach($this->errors as $errmsg) foreach($this->errors as $errmsg)
{ {
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg); $this->error.=($this->error?', '.$errmsg:$errmsg);
} }
}
$this->db->rollback(); $this->db->rollback();
return -1*$error; return -1*$error;
} }
@ -1751,14 +1739,10 @@ class Propal extends CommonObject
propale_pdf_create($this->db, $this, $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL?$conf->global->PROPALE_ADDON_PDF_ODT_TOBILL:$this->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); propale_pdf_create($this->db, $this, $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL?$conf->global->PROPALE_ADDON_PDF_ODT_TOBILL:$this->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
} }
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PROPAL_CLOSE_SIGNED',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PROPAL_CLOSE_SIGNED',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
else else
{ {
@ -1777,20 +1761,23 @@ class Propal extends CommonObject
propale_pdf_create($this->db, $this, $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED?$conf->global->PROPALE_ADDON_PDF_ODT_CLOSED:$this->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); propale_pdf_create($this->db, $this, $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED?$conf->global->PROPALE_ADDON_PDF_ODT_CLOSED:$this->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
} }
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PROPAL_CLOSE_REFUSED',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PROPAL_CLOSE_REFUSED',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
} }
// Fin appel triggers if ( ! $error )
} {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{
$this->db->rollback();
return -1;
}
}
else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
$this->db->rollback(); $this->db->rollback();
@ -2039,15 +2026,11 @@ class Propal extends CommonObject
$this->db->begin(); $this->db->begin();
if (! $error && ! $notrigger) if (! $notrigger)
{ {
// Call triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PROPAL_DELETE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PROPAL_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// End call triggers // End call triggers
} }
@ -2145,7 +2128,6 @@ class Propal extends CommonObject
} }
else else
{ {
$this->error=$this->db->lasterror();
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
@ -2931,14 +2913,14 @@ class PropaleLigne extends CommonObject
if (! $notrigger) if (! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('LINEPROPAL_INSERT',$user);
$interface=new Interfaces($this->db); if ($result < 0)
$result = $interface->run_triggers('LINEPROPAL_INSERT',$this,$user,$langs,$conf); {
if ($result < 0) { $this->db->rollback();
$error++; $this->errors=$interface->errors; return -1;
} }
// Fin appel triggers // End call triggers
} }
$this->db->commit(); $this->db->commit();
@ -2981,14 +2963,14 @@ class PropaleLigne extends CommonObject
} }
} }
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('LINEPROPAL_DELETE',$user);
$interface=new Interfaces($this->db); if ($result < 0)
$result = $interface->run_triggers('LINEPROPAL_DELETE',$this,$user,$langs,$conf); {
if ($result < 0) { $this->db->rollback();
$error++; $this->errors=$interface->errors; return -1;
} }
// Fin appel triggers // End call triggers
$this->db->commit(); $this->db->commit();
@ -3091,14 +3073,14 @@ class PropaleLigne extends CommonObject
if (! $notrigger) if (! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('LINEPROPAL_UPDATE',$user);
$interface=new Interfaces($this->db); if ($result < 0)
$result = $interface->run_triggers('LINEPROPAL_UPDATE',$this,$user,$langs,$conf); {
if ($result < 0) { $this->db->rollback();
$error++; $this->errors=$interface->errors; return -1;
} }
// Fin appel triggers // End call triggers
} }
$this->db->commit(); $this->db->commit();

View File

@ -126,14 +126,14 @@ class Deplacement extends CommonObject
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."deplacement"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."deplacement");
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('DEPLACEMENT_CREATE',$user);
$interface=new Interfaces($this->db); if ($result < 0)
$result=$interface->run_triggers('DEPLACEMENT_CREATE',$this,$user,$langs,$conf); {
if ($result < 0) { $this->db->rollback();
$error++; $this->errors=$interface->errors; return -2;
} }
// Fin appel triggers // End call triggers
$result=$this->update($user); $result=$this->update($user);
if ($result > 0) if ($result > 0)

View File

@ -183,12 +183,10 @@ class Contact extends CommonObject
if (! $error) if (! $error)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('CONTACT_CREATE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('CONTACT_CREATE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
} }
if (! $error) if (! $error)
@ -304,12 +302,10 @@ class Contact extends CommonObject
if (! $error && ! $notrigger) if (! $error && ! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('CONTACT_MODIFY',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('CONTACT_MODIFY',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
} }
if (! $error) if (! $error)
@ -319,7 +315,6 @@ class Contact extends CommonObject
} }
else else
{ {
$this->error=join(',',$this->errors);
dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR); dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
$this->db->rollback(); $this->db->rollback();
return -$error; return -$error;
@ -777,14 +772,10 @@ class Contact extends CommonObject
if (! $error && ! $notrigger) if (! $error && ! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('CONTACT_DELETE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('CONTACT_DELETE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
if ($error) $this->error=join(',',$this->errors);
} }
if (! $error) if (! $error)
@ -1067,12 +1058,10 @@ class Contact extends CommonObject
dol_syslog(get_class($this)."::setstatus", LOG_DEBUG); dol_syslog(get_class($this)."::setstatus", LOG_DEBUG);
if ($result) if ($result)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('CONTACT_ENABLEDISABLE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('CONTACT_ENABLEDISABLE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
} }
if ($error) if ($error)

View File

@ -138,19 +138,30 @@ if (empty($reshook))
if ($action == 'disable') if ($action == 'disable')
{ {
$object->fetch($id); $object->fetch($id);
$object->setstatus(0); if ($object->setstatus(0)<0)
{
setEventMessage($object->error,'errors');
}
else
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit; exit;
} }
}
// Confirmation activation // Confirmation activation
if ($action == 'enable') if ($action == 'enable')
{ {
$object->fetch($id); $object->fetch($id);
$object->setstatus(1); if ($object->setstatus(1)<0)
{
setEventMessage($object->error,'errors');
}
else
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit; exit;
}
} }
// Add contact // Add contact
@ -235,7 +246,8 @@ if (empty($reshook))
} }
else else
{ {
$error=$object->error; $errors=$object->errors; setEventMessage($object->error,'errors');
setEventMessage($object->errors,'errors');
} }
} }
@ -295,7 +307,8 @@ if (empty($reshook))
} }
else else
{ {
$error=$object->error; $errors=$object->errors; setEventMessage($object->error,'errors');
setEventMessage($object->errors,'errors');
$action = 'edit'; $action = 'edit';
} }
} }
@ -367,6 +380,8 @@ else
$title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses")); $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
dol_fiche_head($head, 'card', $title, 0, 'contact'); dol_fiche_head($head, 'card', $title, 0, 'contact');
dol_htmloutput_events();
} }
if ($user->rights->societe->contact->creer) if ($user->rights->societe->contact->creer)

View File

@ -211,6 +211,10 @@ class InterfaceDemo
{ {
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
} }
elseif ($action == 'CONTACT_ENABLEDISABLE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Products // Products
elseif ($action == 'PRODUCT_CREATE') elseif ($action == 'PRODUCT_CREATE')
@ -222,6 +226,30 @@ class InterfaceDemo
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
} }
elseif ($action == 'PRODUCT_DELETE') elseif ($action == 'PRODUCT_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PRODUCT_PRICE_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
//Stock mouvement
elseif ($action == 'STOCK_MOVEMENT')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
//MYECMDIR
elseif ($action == 'MYECMDIR_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'MYECMDIR_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'MYECMDIR_MODIFY')
{ {
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
} }

View File

@ -152,12 +152,10 @@ class EcmDirectory // extends CommonObject
$result=dol_mkdir($dir); $result=dol_mkdir($dir);
if ($result < 0) { $error++; $this->error="ErrorFailedToCreateDir"; } if ($result < 0) { $error++; $this->error="ErrorFailedToCreateDir"; }
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('MYECMDIR_CREATE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('MYECMDIR_CREATE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
if (! $error) if (! $error)
{ {
@ -219,12 +217,10 @@ class EcmDirectory // extends CommonObject
if (! $error && ! $notrigger) if (! $error && ! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('MYECMDIR_MODIFY',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('MYECMDIR_MODIFY',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
} }
if (! $error) if (! $error)
@ -352,6 +348,17 @@ class EcmDirectory // extends CommonObject
$this->error="Error ".$this->db->lasterror(); $this->error="Error ".$this->db->lasterror();
return -2; return -2;
} }
else
{
// Call trigger
$result=$this->call_trigger('MYECMDIR_DELETE',$user);
if ($result < 0)
{
$this->db->rollback();
return -2;
}
// End call triggers
}
if ($mode != 'databaseonly') if ($mode != 'databaseonly')
{ {
@ -371,16 +378,6 @@ class EcmDirectory // extends CommonObject
$error++; $error++;
} }
if (! $error)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('MYECMDIR_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
if (! $error) return 1; if (! $error) return 1;
else return -1; else return -1;
} }
@ -697,4 +694,37 @@ class EcmDirectory // extends CommonObject
} }
} }
/**
* Call trigger based on this instance
*
* NB: Error from trigger are stacked in errors
* NB2: if trigger fail, action should be canceled.
* NB3: Should be deleted if EcmDirectory extend CommonObject
*
* @param string $trigger_name trigger's name to execute
* @param User $user Object user
* @return int Result of run_triggers
*/
function call_trigger($trigger_name, $user)
{
global $langs,$conf;
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf);
if ($result < 0) {
if (!empty($this->errors))
{
$this->errors=array_merge($this->errors,$interface->errors);
}
else
{
$this->errors=$interface->errors;
}
}
return $result;
}
} }

View File

@ -275,12 +275,10 @@ class Expedition extends CommonObject
if (! $error) if (! $error)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; $result=$this->call_trigger('SHIPPING_CREATE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('SHIPPING_CREATE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
if (! $error) if (! $error)
{ {
@ -656,12 +654,10 @@ class Expedition extends CommonObject
if (! $error) if (! $error)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; $result=$this->call_trigger('SHIPPING_VALIDATE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('SHIPPING_VALIDATE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
} }
if (! $error) if (! $error)
@ -867,11 +863,9 @@ class Expedition extends CommonObject
{ {
if (! $notrigger) if (! $notrigger)
{ {
// Call triggers // Call trigger
include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; $result=$this->call_trigger('SHIPPING_MODIFY',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('SHIPPING_MODIFY',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// End call triggers // End call triggers
} }
} }
@ -982,11 +976,9 @@ class Expedition extends CommonObject
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
// Call triggers // Call trigger
include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; $result=$this->call_trigger('SHIPPING_DELETE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('SHIPPING_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// End call triggers // End call triggers
if (! $error) if (! $error)

View File

@ -242,6 +242,13 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->exped
$result = $object->valid($user); $result = $object->valid($user);
if ($result < 0)
{
$langs->load("errors");
setEventMessage($langs->trans($object->error),'errors');
}
else
{
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;
$newlang=''; $newlang='';
@ -263,6 +270,7 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->exped
exit; exit;
} }
} }
}
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer) else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer)
{ {

View File

@ -446,15 +446,12 @@ class Livraison extends CommonObject
return -1; return -1;
} }
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; $result=$this->call_trigger('DELIVERY_VALIDATE',$user);
$interface = new Interfaces($this->db); // End call triggers
$result = $interface->run_triggers('DELIVERY_VALIDATE', $this, $user, $langs, $conf);
// Fin appel triggers
if ($result < 0) if ($result < 0)
{ {
$this->db->rollback(); $this->db->rollback();
$this->error = $interface->errors;
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
return -1; return -1;
} }
@ -604,12 +601,12 @@ class Livraison extends CommonObject
} }
} }
// Call triggers // Call trigger
include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; $result=$this->call_trigger('DELIVERY_DELETE',$user);
$interface=new Interfaces($this->db); if ($result < 0)
$result=$interface->run_triggers('DELIVERY_DELETE',$this,$user,$langs,$conf); {
if ($result < 0) { $this->db->rollback();
$error++; $this->errors=$interface->errors; return -4;
} }
// End call triggers // End call triggers

View File

@ -427,12 +427,10 @@ class Product extends CommonObject
if (! $error && ! $notrigger) if (! $error && ! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PRODUCT_CREATE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
} }
if (! $error) if (! $error)
@ -665,12 +663,10 @@ class Product extends CommonObject
if (! $error && ! $notrigger) if (! $error && ! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PRODUCT_MODIFY',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PRODUCT_MODIFY',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
} }
if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref))
@ -763,17 +759,15 @@ class Product extends CommonObject
if (! $error) if (! $error)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PRODUCT_DELETE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PRODUCT_DELETE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
// Delete all child tables // Delete all child tables
if (! $error)
{
$elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock'); $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock');
foreach($elements as $table) foreach($elements as $table)
{ {
@ -790,6 +784,7 @@ class Product extends CommonObject
} }
} }
} }
}
// Delete product // Delete product
if (! $error) if (! $error)
@ -1228,6 +1223,8 @@ class Product extends CommonObject
if (empty($localtax1)) $localtax1=0; // If = '' then = 0 if (empty($localtax1)) $localtax1=0; // If = '' then = 0
if (empty($localtax2)) $localtax2=0; // If = '' then = 0 if (empty($localtax2)) $localtax2=0; // If = '' then = 0
$this->db->begin();
// Ne pas mettre de quote sur les numeriques decimaux. // Ne pas mettre de quote sur les numeriques decimaux.
// Ceci provoque des stockages avec arrondis en base au lieu des valeurs exactes. // Ceci provoque des stockages avec arrondis en base au lieu des valeurs exactes.
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
@ -1264,18 +1261,20 @@ class Product extends CommonObject
$this->level = $level; // Store level of price edited for trigger $this->level = $level; // Store level of price edited for trigger
// Appel des triggers // Call trigger
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $result=$this->call_trigger('PRODUCT_PRICE_MODIFY',$user);
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('PRODUCT_PRICE_MODIFY',$this,$user,$langs,$conf);
if ($result < 0) if ($result < 0)
{ {
$error++; $this->errors=$interface->errors; $this->db->rollback();
return -1;
} }
// Fin appel triggers // End call triggers
$this->db->commit();
} }
else else
{ {
$this->db->rollback();
dol_print_error($this->db); dol_print_error($this->db);
} }
} }
@ -2876,7 +2875,7 @@ class Product extends CommonObject
} }
else else
{ {
dol_print_error($this->db); $this->error=$movementstock->error;
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
@ -3473,7 +3472,7 @@ class Product extends CommonObject
} }
else else
{ {
dol_print_error($this->db); $this->error=$movementstock->error;
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }

View File

@ -154,6 +154,11 @@ if ($action == "correct_stock" && ! $cancel)
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$product->id); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$product->id);
exit; exit;
} }
else
{
setEventMessage($product->error,'errors');
$action='correction';
}
} }
} }
} }
@ -254,6 +259,8 @@ if ($id > 0 || $ref)
$picto=($product->type==1?'service':'product'); $picto=($product->type==1?'service':'product');
dol_fiche_head($head, 'stock', $titre, 0, $picto); dol_fiche_head($head, 'stock', $titre, 0, $picto);
dol_htmloutput_events();
$form = new Form($db); $form = new Form($db);
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';