diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-03-19 02:35:51 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-03-19 02:35:51 +0000 |
commit | 61d8a143eaf7478b15edf554f2ccaada75c8bd9d (patch) | |
tree | 182a026565370e42d22db9ae15cc9fcbed8828c9 /core | |
parent | 0b721258f42c0775d1fb90966a82fe3a81763e00 (diff) |
Rejigger the way we do reinstalls while Kohana is running.
core_installer::install() now takes an $initial_install param that
allows us to enforce that we're doing a clean install. Use this in
both the scaffolding and the unit test code.
Greatly simplify the scaffolding uninstall/reinstall code.
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/scaffold.php | 55 | ||||
-rw-r--r-- | core/helpers/core_installer.php | 9 |
2 files changed, 17 insertions, 47 deletions
diff --git a/core/controllers/scaffold.php b/core/controllers/scaffold.php index 1c2ce896..63b00f2d 100644 --- a/core/controllers/scaffold.php +++ b/core/controllers/scaffold.php @@ -273,57 +273,26 @@ class Scaffold_Controller extends Template_Controller { } } - function uninstall($module_name, $redirect=true) { - $clean = true; - if ($module_name == "core") { - // We have to uninstall all other modules first, else their tables, etc don't - // get cleaned up. - $old_handler = set_error_handler(array("scaffold_Controller", "_error_handler")); - try { - foreach (ORM::factory("module")->find_all() as $module) { - if ($module->name != "core" && $module->version) { - try { - call_user_func(array("{$module->name}_installer", "uninstall")); - } catch (Exception $e) { - print $e; - } - } - } - core_installer::uninstall(); - } catch (Exception $e) { - print $e; - } + public function package() { + $this->auto_render = false; + $db = Database::instance(); - // Since we're in a state of flux, it's possible that other stuff went wrong with the - // uninstall, so back off and nuke it from orbit. It's the only way to be sure. - $db = Database::instance(); - foreach ($db->list_tables() as $table) { + // Drop all tables + foreach ($db->list_tables() as $table) { $db->query("DROP TABLE IF EXISTS `$table`"); - } - set_error_handler($old_handler); - } else { - module::uninstall($module_name); } - if ($redirect) { - url::redirect("scaffold"); - } - } - - public function package() { - $this->auto_render = false; - // Cleanly uninstalling and reinstalling within the same request requires us to do the "cache - // invalidation" cha-cha. It's a dance of many steps. - $this->uninstall("core", false); module::$module_names = array(); module::$modules = array(); - Database::instance()->clear_cache(); - $this->install("core", false); + $db->clear_cache(); + + core_installer::install(true); module::load_modules(); - foreach (array("core", "user", "comment", "info", - "rss", "search", "slideshow", "tag") as $module_name) { - $this->install($module_name, false); + + foreach (array("user", "comment", "info", "rss", + "search", "slideshow", "tag") as $module_name) { + module::install($module_name); } url::redirect("scaffold/dump_database"); } diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php index cd318ebd..4755e39a 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -18,9 +18,9 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class core_installer { - static function install() { + static function install($initial_install=false) { $db = Database::instance(); - if (TEST_MODE) { + if ($initial_install) { $version = 0; } else { $version = module::get_version("core"); @@ -280,8 +280,9 @@ class core_installer { $db->query("DROP TABLE IF EXISTS {sessions}"); $db->query("DROP TABLE IF EXISTS {tasks}"); $db->query("DROP TABLE IF EXISTS {vars}"); - foreach (array("albums", "resizes", "thumbs", "uploads", "modules") as $dir) { - system("/bin/rm -rf " . VARPATH . $dir); + foreach (array("albums", "resizes", "thumbs", "uploads", + "modules", "logs", "database.php") as $entry) { + system("/bin/rm -rf " . VARPATH . $entry); } } } |