Skip to content

Commit

Permalink
Fix: missing context before calling trigger.
Browse files Browse the repository at this point in the history
Clean demo file with list of triggers.
  • Loading branch information
eldy committed Jul 19, 2015
1 parent 0402a16 commit 4f5e8e2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Expand Up @@ -222,7 +222,8 @@ Dolibarr better:
- 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
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 *****
Expand Down
3 changes: 2 additions & 1 deletion htdocs/core/class/commonobject.class.php
Expand Up @@ -3532,7 +3532,8 @@ function add_thumb($file)


/**
* 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
* NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction.
*
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/class/interfaces.class.php
Expand Up @@ -50,7 +50,7 @@ function __construct($db)
* This function call all qualified triggers.
*
* @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 Lang $langs Objet lang
* @param Conf $conf Objet conf
Expand Down
24 changes: 11 additions & 13 deletions htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN
Expand Up @@ -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)
*
* @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 Translate $langs Object langs
* @param conf $conf Object conf
Expand All @@ -62,24 +62,18 @@ class InterfaceDemo extends DolibarrTriggers
switch ($action) {

// 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_FROM_CONTACT':
case 'USER_MODIFY':
case 'USER_NEW_PASSWORD':
case 'USER_ENABLEDISABLE':
case 'USER_DELETE':
case 'USER_LOGOUT':
case 'USER_SETINGROUP':
case 'USER_REMOVEFROMGROUP':

case 'USER_LOGIN':
case 'USER_LOGIN_FAILED':
case 'USER_LOGOUT':

// Actions
case 'ACTION_MODIFY':
case 'ACTION_CREATE':
Expand Down Expand Up @@ -208,8 +202,12 @@ class InterfaceDemo extends DolibarrTriggers
case 'PAYMENT_SUPPLIER_CREATE':
case 'PAYMENT_ADD_TO_BANK':
case 'PAYMENT_DELETE':

//Donation

// Online
case 'PAYMENT_PAYBOX_OK':
case 'PAYMENT_PAYPAL_OK':

// Donation
case 'DON_CREATE':
case 'DON_UPDATE':
case 'DON_DELETE':
Expand Down
4 changes: 3 additions & 1 deletion htdocs/user/class/user.class.php
Expand Up @@ -978,8 +978,10 @@ function create_from_contact($contact,$login='',$password='')
dol_syslog(get_class($this)."::create_from_contact", LOG_DEBUG);
if ($resql)
{
$this->context['createfromcontact']='createfromcontact';

// 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; }
// End call triggers

Expand Down

0 comments on commit 4f5e8e2

Please sign in to comment.