Skip to content
Snippets Groups Projects
Commit 4f5e8e24 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: missing context before calling trigger.

Clean demo file with list of triggers.
parent 0402a166
Branches
Tags
No related merge requests found
...@@ -222,7 +222,8 @@ Dolibarr better: ...@@ -222,7 +222,8 @@ Dolibarr better:
- Method select_PriceBaseType and load_PriceBaseType were merged into selectPriceBaseType. - Method select_PriceBaseType and load_PriceBaseType were merged into selectPriceBaseType.
- The triggers USER_LOGIN* are deprecated. They are still working but you should prefer use the - The triggers USER_LOGIN* are deprecated. They are still working but you should prefer use the
hook afterLogin or afterLoginFailed instead. hook afterLogin or afterLoginFailed instead.
- The trigger USER_CREATE_FROM_CONTACT has been replace with USER_CREATE and property context is now filled
to make difference between creation from contact or not.
***** ChangeLog for 3.7.2 compared to 3.7.1 ***** ***** ChangeLog for 3.7.2 compared to 3.7.1 *****
......
...@@ -3532,7 +3532,8 @@ abstract class CommonObject ...@@ -3532,7 +3532,8 @@ abstract class CommonObject
/** /**
* Call trigger based on this instance * Call trigger based on this instance.
* Some context information may also be provided into array property this->context.
* NB: Error from trigger are stacked in interface->errors * NB: Error from trigger are stacked in interface->errors
* NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction.
* *
......
...@@ -50,7 +50,7 @@ class Interfaces ...@@ -50,7 +50,7 @@ class Interfaces
* This function call all qualified triggers. * This function call all qualified triggers.
* *
* @param string $action Trigger event code * @param string $action Trigger event code
* @param object $object Objet concern * @param object $object Objet concerned. Some context information may also be provided into array property object->context.
* @param User $user Objet user * @param User $user Objet user
* @param Lang $langs Objet lang * @param Lang $langs Objet lang
* @param Conf $conf Objet conf * @param Conf $conf Objet conf
......
...@@ -48,7 +48,7 @@ class InterfaceDemo extends DolibarrTriggers ...@@ -48,7 +48,7 @@ class InterfaceDemo extends DolibarrTriggers
* All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
* *
* @param string $action Event action code * @param string $action Event action code
* @param Object $object Object * @param Object $object Object concerned. Some context information may also be provided into array property object->context.
* @param User $user Object user * @param User $user Object user
* @param Translate $langs Object langs * @param Translate $langs Object langs
* @param conf $conf Object conf * @param conf $conf Object conf
...@@ -62,24 +62,18 @@ class InterfaceDemo extends DolibarrTriggers ...@@ -62,24 +62,18 @@ class InterfaceDemo extends DolibarrTriggers
switch ($action) { switch ($action) {
// Users // Users
case 'USER_LOGIN':
case 'USER_UPDATE_SESSION':
case 'USER_CREATE':
case 'USER_CREATE_FROM_CONTACT':
case 'USER_LOGIN':
// Warning: To increase performances, this action is triggered only if
// constant MAIN_ACTIVATE_UPDATESESSIONTRIGGER is set to 1.
case 'USER_UPDATE_SESSION':
case 'USER_CREATE': case 'USER_CREATE':
case 'USER_CREATE_FROM_CONTACT':
case 'USER_MODIFY': case 'USER_MODIFY':
case 'USER_NEW_PASSWORD': case 'USER_NEW_PASSWORD':
case 'USER_ENABLEDISABLE': case 'USER_ENABLEDISABLE':
case 'USER_DELETE': case 'USER_DELETE':
case 'USER_LOGOUT':
case 'USER_SETINGROUP': case 'USER_SETINGROUP':
case 'USER_REMOVEFROMGROUP': case 'USER_REMOVEFROMGROUP':
case 'USER_LOGIN':
case 'USER_LOGIN_FAILED':
case 'USER_LOGOUT':
// Actions // Actions
case 'ACTION_MODIFY': case 'ACTION_MODIFY':
case 'ACTION_CREATE': case 'ACTION_CREATE':
...@@ -209,6 +203,10 @@ class InterfaceDemo extends DolibarrTriggers ...@@ -209,6 +203,10 @@ class InterfaceDemo extends DolibarrTriggers
case 'PAYMENT_ADD_TO_BANK': case 'PAYMENT_ADD_TO_BANK':
case 'PAYMENT_DELETE': case 'PAYMENT_DELETE':
// Online
case 'PAYMENT_PAYBOX_OK':
case 'PAYMENT_PAYPAL_OK':
// Donation // Donation
case 'DON_CREATE': case 'DON_CREATE':
case 'DON_UPDATE': case 'DON_UPDATE':
......
...@@ -978,8 +978,10 @@ class User extends CommonObject ...@@ -978,8 +978,10 @@ class User extends CommonObject
dol_syslog(get_class($this)."::create_from_contact", LOG_DEBUG); dol_syslog(get_class($this)."::create_from_contact", LOG_DEBUG);
if ($resql) if ($resql)
{ {
$this->context['createfromcontact']='createfromcontact';
// Call trigger // Call trigger
$result=$this->call_trigger('USER_CREATE_FROM_CONTACT',$user); $result=$this->call_trigger('USER_CREATE',$user);
if ($result < 0) { $error++; $this->db->rollback(); return -1; } if ($result < 0) { $error++; $this->db->rollback(); return -1; }
// End call triggers // End call triggers
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment