From 6a76d6f747768106f8bccd8b74059371dbac615a Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 28 Nov 2008 21:22:34 +0000 Subject: Dynamically create the list of available modules. This permits new modules to be added without having to update the config.php file --- core/config/config.php | 11 ----------- core/controllers/welcome.php | 9 +++------ core/helpers/module.php | 22 ++++++++++++++++++++++ core/hooks/load_modules.php | 21 +++++++++++++++++++++ 4 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 core/hooks/load_modules.php diff --git a/core/config/config.php b/core/config/config.php index 67c913bb..db016ffd 100644 --- a/core/config/config.php +++ b/core/config/config.php @@ -123,16 +123,5 @@ $config['modules'] = array MODPATH . 'forge', THEMEPATH . 'default', - - MODPATH . 'carousel', - MODPATH . 'tag', - MODPATH . 'user', - MODPATH . 'info', - MODPATH . 'gmaps', - MODPATH . 'media_rss', - MODPATH . 'slideshow', - MODPATH . 'comment', - MODPATH . 'atom', - MODPATH . 'search' ); diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php index a75b225f..5cf6d7bf 100644 --- a/core/controllers/welcome.php +++ b/core/controllers/welcome.php @@ -346,16 +346,13 @@ class Welcome_Controller extends Template_Controller { private function _read_modules() { $modules = array(); try { - $installed = ORM::factory("module")->find_all(); + $installed = module::installed(); foreach ($installed as $installed_module) { $modules[$installed_module->name] = $installed_module->version; } - foreach (glob(MODPATH . "*/helpers/*_installer.php") as $file) { - if (empty($modules[basename(dirname(dirname($file)))])) { - $modules[basename(dirname(dirname($file)))] = 0; - } - } + $modules = module::available($modules); + } catch (Exception $e) { // The database may not be installed } diff --git a/core/helpers/module.php b/core/helpers/module.php index afba658a..599cc618 100644 --- a/core/helpers/module.php +++ b/core/helpers/module.php @@ -64,4 +64,26 @@ class module_Core { } } } + + public static function available($modules=array()) { + foreach (glob(MODPATH . "*/helpers/*_installer.php") as $file) { + if (empty($modules[basename(dirname(dirname($file)))])) { + $modules[basename(dirname(dirname($file)))] = 0; + } + } + + return $modules; + } + + public static function load_modules() { + Kohana::log("debug", "module::load_modules()"); + $modules = Kohana::config('core.modules'); + + foreach (array_keys(self::available()) as $module_name) { + $modules[] = MODPATH . $module_name; + } + Kohana::log("debug", print_r($modules, true)); + + Kohana::config_set('core.modules', $modules); + } } diff --git a/core/hooks/load_modules.php b/core/hooks/load_modules.php new file mode 100644 index 00000000..57d0fffb --- /dev/null +++ b/core/hooks/load_modules.php @@ -0,0 +1,21 @@ +