Browse Source

Fix: missing context before calling trigger.
Clean demo file with list of triggers.

Laurent Destailleur 10 years ago
parent
commit
4f5e8e2480

+ 2 - 1
ChangeLog

@@ -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 *****

+ 2 - 1
htdocs/core/class/commonobject.class.php

@@ -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
      * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction.
      *

+ 1 - 1
htdocs/core/class/interfaces.class.php

@@ -50,7 +50,7 @@ class Interfaces
      *   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

+ 11 - 13
htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN

@@ -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
@@ -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':
@@ -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':

+ 3 - 1
htdocs/user/class/user.class.php

@@ -978,8 +978,10 @@ class User extends CommonObject
 			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