diff options
Diffstat (limited to 'modules/gallery/helpers/module.php')
-rw-r--r-- | modules/gallery/helpers/module.php | 34 |
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. |