diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-12 08:41:48 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-12 08:41:48 +0000 |
commit | e12451cf1033e6b6cfa8e278894ccac3098ddd84 (patch) | |
tree | 4d73d5fea4dcc7d102aab4593ef2e56e8f2c3536 | |
parent | 7e4d13d9bdc43ecc3b6cdd7144c40d70cda11c5a (diff) |
Refaactor module::install() and module::uninstall() out of the
scaffolding and unit test code so that we can use it consistently.
This fixes an issue where adding a module was not refreshing the
statically cached module list causing the test framework to break.
-rw-r--r-- | core/controllers/welcome.php | 10 | ||||
-rw-r--r-- | core/helpers/module.php | 31 | ||||
-rw-r--r-- | modules/gallery_unit_test/controllers/gallery_unit_test.php | 18 |
3 files changed, 38 insertions, 21 deletions
diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php index 9d3ca996..5e76789c 100644 --- a/core/controllers/welcome.php +++ b/core/controllers/welcome.php @@ -74,12 +74,7 @@ class Welcome_Controller extends Template_Controller { if ($module_name != "core") { require_once(DOCROOT . "modules/${module_name}/helpers/${module_name}_installer.php"); } - $modules = Kohana::config('core.modules'); - $modules[] = MODPATH . $module_name; - Kohana::config_set('core.modules', $modules); - - Kohana::log("debug", "${module_name}_install (initial)"); - call_user_func(array("${module_name}_installer", "install")); + module::install($module_name); } url::redirect("welcome"); @@ -109,8 +104,9 @@ class Welcome_Controller extends Template_Controller { $db->query("DROP TABLE `$table`"); } set_error_handler($old_handler); + } else { + module::uninstall($module_name); } - call_user_func(array("{$module_name}_installer", "uninstall")); url::redirect("welcome"); } diff --git a/core/helpers/module.php b/core/helpers/module.php index 10effbe3..a06f2999 100644 --- a/core/helpers/module.php +++ b/core/helpers/module.php @@ -79,6 +79,31 @@ class module_Core { return $modules; } + public static function install($module_name) { + $installer_class = "{$module_name}_installer"; + Kohana::log("debug", "$installer_class install (initial)"); + if ($module_name != "core") { + require_once(DOCROOT . "modules/${module_name}/helpers/{$installer_class}.php"); + } + $kohana_modules = Kohana::config('core.modules'); + $kohana_modules[] = MODPATH . $module_name; + Kohana::config_set('core.modules', $kohana_modules); + + call_user_func(array($installer_class, "install")); + + if (method_exists($installer_class, "install")) { + call_user_func_array(array($installer_class, "install"), array()); + } + + self::load_modules(); + } + + public static function uninstall($module_name) { + $installer_class = "{$module_name}_installer"; + Kohana::log("debug", "$installer_class uninstall"); + call_user_func(array($installer_class, "uninstall")); + } + public static function load_modules() { // This is one of the first database operations that we'll do, so it may fail if there's no // install yet. Try to handle this situation gracefully expecting that the scaffolding will @@ -87,8 +112,12 @@ class module_Core { // @todo get rid of this extra error checking when we have an installer. set_error_handler(array("module", "_dummy_error_handler")); + // Reload module list from the config file since we'll do a refresh after calling install() + $core = Kohana::config_load('core'); + $kohana_modules = $core['modules']; + self::$module_names = array(); + self::$modules = array(); try { - $kohana_modules = Kohana::config('core.modules'); foreach (ORM::factory("module")->find_all() as $module) { self::$module_names[] = $module->name; self::$modules[] = $module; diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index 0275ed79..4394cebf 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -50,6 +50,9 @@ class Gallery_Unit_Test_Controller extends Controller { // Make this the default database for the rest of this run Database::$instances = array('default' => $db); + + // Reset our loaded modules + module::load_modules(); } catch (Exception $e) { print "{$e->getMessage()}\n"; return; @@ -75,25 +78,14 @@ class Gallery_Unit_Test_Controller extends Controller { @system('mkdir -p test/var/logs'); // Install all modules - core_installer::install(); + module::install("core"); $modules = array(); foreach (glob(MODPATH . "*/helpers/*_installer.php") as $file) { $module_name = basename(dirname(dirname($file))); if ($module_name == "core") { continue; } - - require_once(DOCROOT . "modules/${module_name}/helpers/${module_name}_installer.php"); - - $test_dir = MODPATH . "$module_name/tests"; - if (file_exists($test_dir)) { - $modules[] = $test_dir; - } - - $installer_class = "{$module_name}_installer"; - if (method_exists($installer_class, "install")) { - call_user_func_array(array($installer_class, "install"), array()); - } + module::install($module_name); } $filter = count($_SERVER["argv"]) > 2 ? $_SERVER["argv"][2] : null; |