From a1144e1f66fdc0208f35d4097020b5582a71cbb4 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Thu, 8 Jun 2017 11:18:41 +0200
Subject: [PATCH] Fix missing init of hookmanager

---
 htdocs/core/class/hookmanager.class.php |  5 ++---
 htdocs/install/upgrade2.php             | 11 ++++++++---
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php
index afb670dc267..8faea875ab5 100644
--- a/htdocs/core/class/hookmanager.class.php
+++ b/htdocs/core/class/hookmanager.class.php
@@ -59,15 +59,14 @@ class HookManager
 
 	/**
 	 *	Init array $this->hooks with instantiated action controlers.
-	 *  First, a hook is declared by a module by adding a constant MAIN_MODULE_MYMODULENAME_HOOKS
-	 *  with value 'nameofcontext1:nameofcontext2:...' into $this->const of module descriptor file.
+	 *  First, a hook is declared by a module by adding a constant MAIN_MODULE_MYMODULENAME_HOOKS with value 'nameofcontext1:nameofcontext2:...' into $this->const of module descriptor file.
 	 *  This makes $conf->hooks_modules loaded with an entry ('modulename'=>array(nameofcontext1,nameofcontext2,...))
 	 *  When initHooks function is called, with initHooks(list_of_contexts), an array $this->hooks is defined with instance of controler
 	 *  class found into file /mymodule/class/actions_mymodule.class.php (if module has declared the context as a managed context).
 	 *  Then when a hook executeHooks('aMethod'...) is called, the method aMethod found into class will be executed.
 	 *
 	 *	@param	string[]	$arraycontext	    Array list of searched hooks tab/features. For example: 'thirdpartycard' (for hook methods into page card thirdparty), 'thirdpartydao' (for hook methods into Societe), ...
-	 *	@return	int							Always 1
+	 *	@return	int							    Always 1
 	 */
 	function initHooks($arraycontext)
 	{
diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php
index 36bbeb966d4..6beeb7ca7b2 100644
--- a/htdocs/install/upgrade2.php
+++ b/htdocs/install/upgrade2.php
@@ -136,6 +136,7 @@ if (! GETPOST('action','aZ09') || preg_match('/upgrade/i',GETPOST('action','aZ09
     // Create the global $hookmanager object
     include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
     $hookmanager=new HookManager($db);
+    $hookmanager->initHooks(array('upgrade'));
 
     if (!$db->connected)
     {
@@ -491,9 +492,13 @@ if (! GETPOST('action','aZ09') || preg_match('/upgrade/i',GETPOST('action','aZ09
         }
         else
         {
-            print '<tr><td colspan="4">';
-            print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: '.$langs->trans("None");
-            print '</td></tr>';
+            //if (! empty($conf->modules))
+            if (! empty($conf->modules_parts['hooks']))     // If there is at least one module with one hook, we show message to say nothing was done
+            {
+                print '<tr><td colspan="4">';
+                print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: '.$langs->trans("None");
+                print '</td></tr>';
+            }
         }
     }
 
-- 
GitLab