summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers/module.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-06-23 12:00:49 -0700
committerBharat Mediratta <bharat@menalto.com>2009-06-23 12:00:49 -0700
commitbfca0c79030d5b8a18e41e8b80f5560ebaf6f202 (patch)
tree71568f5d924277879cf645c0190ebd7c98a80228 /modules/gallery/helpers/module.php
parent342d5e118664274fb1d8329734815640f5169887 (diff)
Refactor the install/upgrade code to be more flexible.
Add xxx_installer::upgrade($version) method so that upgrade stanzas are separate from install stanzas. In the old code, to do an upgrade meant that you had to re-evolve everything from the initial install because we'd step through each version's changes. But what we really want is for the initial install to start off in the perfect initial state, and the upgrades to do the work behind the scenes. So now the install() function gets things set up properly the first time, and the upgrade() function does any work to catch you up to the latest code. See gallery_installer.php for a good example.
Diffstat (limited to 'modules/gallery/helpers/module.php')
-rw-r--r--modules/gallery/helpers/module.php34
1 files changed, 33 insertions, 1 deletions
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index dea8e22c..0d483206 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -107,7 +107,7 @@ class module_Core {
/**
* Install a module. This will call <module>_installer::install(), which is responsible for
- * creating database tables, setting module variables and and calling module::set_version().
+ * creating database tables, setting module variables and calling module::set_version().
* Note that after installing, the module must be activated before it is available for use.
* @param string $module_name
*/
@@ -131,6 +131,38 @@ class module_Core {
}
/**
+ * Upgrade a module. This will call <module>_installer::upgrade(), which is responsible for
+ * modifying database tables, changing module variables and calling module::set_version().
+ * Note that after upgrading, the module must be activated before it is available for use.
+ * @param string $module_name
+ */
+ static function upgrade($module_name) {
+ $kohana_modules = Kohana::config("core.modules");
+ array_unshift($kohana_modules, MODPATH . $module_name);
+ Kohana::config_set("core.modules", $kohana_modules);
+
+ $version_before = module::get_version($module_name);
+ $installer_class = "{$module_name}_installer";
+ if (method_exists($installer_class, "upgrade")) {
+ call_user_func_array(array($installer_class, "upgrade"), array($version_before));
+ }
+ module::load_modules();
+
+ // Now the module is upgraded but inactive, so don't leave it in the active path
+ array_shift($kohana_modules);
+ Kohana::config_set("core.modules", $kohana_modules);
+
+ $version_after = module::get_version($module_name);
+ if ($version_before != $version_after) {
+ log::success(
+ "module", t("Upgraded module %module_name from %version_before to %version_after",
+ array("module_name" => $module_name,
+ "version_before" => $version_before,
+ "version_after" => $version_after)));
+ }
+ }
+
+ /**
* Activate an installed module. This will call <module>_installer::activate() which should take
* any steps to make sure that the module is ready for use. This will also activate any
* existing graphics rules for this module.