From d7b46e80af7269ec7a1dcd87f24ee9cdb417252d Mon Sep 17 00:00:00 2001 From: Jerome Nadaud Date: Wed, 30 Oct 2013 16:48:16 +0100 Subject: [PATCH] [+] BO : Add debug mode system --- classes/Hook.php | 11 +++- classes/module/Module.php | 17 ++++++ .../admin/AdminPerformanceController.php | 57 +++++++++++++++++-- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/classes/Hook.php b/classes/Hook.php index 8d60698f4..30efb0a76 100644 --- a/classes/Hook.php +++ b/classes/Hook.php @@ -56,6 +56,8 @@ class HookCore extends ObjectModel */ public static $executed_hooks = array(); + public static $native_module; + /** * @see ObjectModel::$definition */ @@ -416,12 +418,19 @@ class HookCore extends ObjectModel // Look on modules list $altern = 0; $output = ''; - + + if (!isset(Hook::$native_module)) + Hook::$native_module = Module::getNativeModuleList(); + foreach ($module_list as $array) { // Check errors if ($id_module && $id_module != $array['id_module']) continue; + + if ((bool)Configuration::get('PS_DISABLE_NON_NATIVE_MODULE') && !in_array($array['module'], self::$native_module)) + continue; + if (!($moduleInstance = Module::getInstanceByName($array['module']))) continue; diff --git a/classes/module/Module.php b/classes/module/Module.php index f1c861f7b..c823b68d0 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -1293,6 +1293,23 @@ abstract class ModuleCore return $db->executeS('SELECT * FROM `'._DB_PREFIX_.'module` m WHERE `name` NOT IN ('.implode(',', $arr_native_modules).') '); } + public static function getNativeModuleList() + { + $module_list_xml = _PS_ROOT_DIR_.self::CACHE_FILE_MODULES_LIST; + $native_modules = simplexml_load_file($module_list_xml); + $native_modules = $native_modules->modules; + $modules = array(); + + foreach ($native_modules as $native_modules_type) + if (in_array($native_modules_type['type'], array('native', 'partner'))) + { + foreach ($native_modules_type->module as $module) + $modules[] = $module['name']; + } + + return $modules; + } + /** * Return installed modules * diff --git a/controllers/admin/AdminPerformanceController.php b/controllers/admin/AdminPerformanceController.php index acfbe4d20..89d6554f8 100644 --- a/controllers/admin/AdminPerformanceController.php +++ b/controllers/admin/AdminPerformanceController.php @@ -134,9 +134,48 @@ class AdminPerformanceControllerCore extends AdminController $this->fields_value['smarty_console_key'] = Configuration::get('PS_SMARTY_CONSOLE_KEY'); } - public function initFieldsetFeaturesDetachables() + public function initFieldsetDebugMode() { $this->fields_form[1]['form'] = array( + 'legend' => array( + 'title' => $this->l('Debug mode'), + 'image' => '../img/admin/prefs.gif' + ), + 'input' => array( + array( + 'type' => 'radio', + 'label' => $this->l('Disable non PrestaShop modules'), + 'name' => 'native_module', + 'class' => 't', + 'is_bool' => true, + 'values' => array( + array( + 'id' => 'native_module_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'native_module_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + 'desc' => $this->l('Enable or disable non PrestaShop Modules.') + ), + ), + 'submit' => array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ), + ); + + $this->fields_value['native_module'] = Configuration::get('PS_DISABLE_NON_NATIVE_MODULE'); + $this->fields_value['debug_mode'] = Configuration::get('PS_DEBUG_MODE'); + } + + public function initFieldsetFeaturesDetachables() + { + $this->fields_form[2]['form'] = array( 'legend' => array( 'title' => $this->l('Optional features'), 'image' => '../img/admin/tab-plugins.gif' @@ -197,7 +236,7 @@ class AdminPerformanceControllerCore extends AdminController public function initFieldsetCCC() { - $this->fields_form[2]['form'] = array( + $this->fields_form[3]['form'] = array( 'legend' => array( 'title' => $this->l('CCC (Combine, Compress and Cache)'), 'image' => '../img/admin/arrow_in.png' @@ -317,7 +356,7 @@ class AdminPerformanceControllerCore extends AdminController public function initFieldsetMediaServer() { - $this->fields_form[3]['form'] = array( + $this->fields_form[4]['form'] = array( 'legend' => array( 'title' => $this->l('Media servers (use only with CCC)'), 'image' => '../img/admin/subdomain.gif' @@ -359,7 +398,7 @@ class AdminPerformanceControllerCore extends AdminController public function initFieldsetCiphering() { - $this->fields_form[4]['form'] = array( + $this->fields_form[5]['form'] = array( 'legend' => array( 'title' => $this->l('Ciphering'), 'image' => '../img/admin/computer_key.png' @@ -416,7 +455,7 @@ class AdminPerformanceControllerCore extends AdminController ) ); - $this->fields_form[5]['form'] = array( + $this->fields_form[6]['form'] = array( 'legend' => array( 'title' => $this->l('Caching'), 'image' => '../img/admin/computer_key.png' @@ -483,11 +522,12 @@ class AdminPerformanceControllerCore extends AdminController { // Initialize fieldset for a form $this->initFieldsetSmarty(); + $this->initFieldsetDebugMode(); $this->initFieldsetFeaturesDetachables(); $this->initFieldsetCCC(); $this->initFieldsetMediaServer(); $this->initFieldsetCiphering(); - $this->initFieldsetCaching(); + $this->initFieldsetCaching(); // Activate multiple fieldset $this->multiple_fieldsets = true; @@ -799,6 +839,11 @@ class AdminPerformanceControllerCore extends AdminController Autoload::getInstance()->generateIndex(); } + if (Tools::isSubmit('submitAddconfiguration')) + { + Configuration::updateGlobalValue('PS_DISABLE_NON_NATIVE_MODULE', (int)Tools::getValue('native_module')); + } + if ($redirectAdmin && (!isset($this->errors) || !count($this->errors))) { Hook::exec('action'.get_class($this).ucfirst($this->action).'After', array('controller' => $this, 'return' => ''));