From 146aa7815bdf3cf07f9e994f211f4b768efcb576 Mon Sep 17 00:00:00 2001
From: Paris Liakos <rootatwc@gmail.com>
Date: Mon, 16 Nov 2015 20:27:51 +0200
Subject: [PATCH] Add X_SET_MULTILANGS triggers to make possible reacting on
 translation changes for products and categories

---
 htdocs/categories/class/categorie.class.php       | 13 ++++++++++++-
 htdocs/categories/traduction.php                  |  4 ++--
 .../interface_90_all_Demo.class.php-NORUN         |  2 ++
 htdocs/product/class/product.class.php            | 15 +++++++++++++--
 htdocs/product/traduction.php                     |  4 ++--
 5 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php
index 46a48b31bf8..18ae5e764e3 100644
--- a/htdocs/categories/class/categorie.class.php
+++ b/htdocs/categories/class/categorie.class.php
@@ -1508,9 +1508,11 @@ class Categorie extends CommonObject
 	/**
 	 *	Update ou cree les traductions des infos produits
 	 *
+	 *	@param	User	$user		Object user
+	 *
 	 *	@return		int		<0 if KO, >0 if OK
 	 */
-	function setMultiLangs()
+	function setMultiLangs($user)
 	{
 	    global $langs;
 
@@ -1574,6 +1576,15 @@ class Categorie extends CommonObject
 	            }
 	        }
 	    }
+
+			// Call trigger
+			$result = $this->call_trigger('CATEGORY_SET_MULTILANGS',$user);
+			if ($result < 0) {
+				$this->error = $this->db->lasterror();
+				return -1;
+			}
+			// End call triggers
+
 	    return 1;
 	}
 
diff --git a/htdocs/categories/traduction.php b/htdocs/categories/traduction.php
index 98f02c7a742..02033b27bff 100644
--- a/htdocs/categories/traduction.php
+++ b/htdocs/categories/traduction.php
@@ -88,7 +88,7 @@ $cancel != $langs->trans("Cancel") &&
 	}
 
 	// sauvegarde en base
-	if ( $object->setMultiLangs() > 0 )
+	if ( $object->setMultiLangs($user) > 0 )
 	{
 		$action = '';
 	}
@@ -121,7 +121,7 @@ $cancel != $langs->trans("Cancel") &&
 		}
 	}
 
-	if ( $object->setMultiLangs() > 0 )
+	if ( $object->setMultiLangs($user) > 0 )
 	{
 		$action = '';
 	}
diff --git a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN
index 84f67660c41..b7cb255bfc3 100644
--- a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN
+++ b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN
@@ -100,6 +100,7 @@ class InterfaceDemo extends DolibarrTriggers
 		    case 'PRODUCT_MODIFY':
 		    case 'PRODUCT_DELETE':
 		    case 'PRODUCT_PRICE_MODIFY':
+		    case 'PRODUCT_SET_MULTILANGS':
 
 			//Stock mouvement
 		    case 'STOCK_MOVEMENT':
@@ -234,6 +235,7 @@ class InterfaceDemo extends DolibarrTriggers
 		    case 'CATEGORY_CREATE':
 		    case 'CATEGORY_MODIFY':
 		    case 'CATEGORY_DELETE':
+		    case 'CATEGORY_SET_MULTILANGS':
 
 			// Projects
 		    case 'PROJECT_CREATE':
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 64068652ca9..f0942786afa 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -738,7 +738,7 @@ class Product extends CommonObject
 				// Multilangs
 				if (! empty($conf->global->MAIN_MULTILANGS))
 				{
-					if ( $this->setMultiLangs() < 0)
+					if ( $this->setMultiLangs($user) < 0)
 					{
 						$this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
 						return -2;
@@ -968,9 +968,11 @@ class Product extends CommonObject
 	/**
 	 *	Update or add a translation for a product
 	 *
+	 *	@param  User	$user       Object user making update
+	 *
 	 *	@return		int		<0 if KO, >0 if OK
 	 */
-	function setMultiLangs()
+	function setMultiLangs($user)
 	{
 		global $langs;
 
@@ -1049,6 +1051,15 @@ class Product extends CommonObject
 				// language is not current language and we didn't provide a multilang description for this language
 			}
 		}
+
+		// Call trigger
+		$result = $this->call_trigger('PRODUCT_SET_MULTILANGS',$user);
+		if ($result < 0) {
+			$this->error = $this->db->lasterror();
+			return -1;
+		}
+		// End call triggers
+
 		return 1;
 	}
 
diff --git a/htdocs/product/traduction.php b/htdocs/product/traduction.php
index 96187fad8dd..3d97467f552 100644
--- a/htdocs/product/traduction.php
+++ b/htdocs/product/traduction.php
@@ -87,7 +87,7 @@ $cancel != $langs->trans("Cancel") &&
 	}
 
 	// sauvegarde en base
-	if ( $object->setMultiLangs() > 0 )
+	if ( $object->setMultiLangs($user) > 0 )
 	{
 		$action = '';
 	}
@@ -123,7 +123,7 @@ $cancel != $langs->trans("Cancel") &&
 		}
 	}
 
-	if ( $object->setMultiLangs() > 0 )
+	if ( $object->setMultiLangs($user) > 0 )
 	{
 		$action = '';
 	}
-- 
GitLab