The admin module controller allows modules to provide a check_environment method

which is called prior to installation.  The method allows the module to provide
an error message or warnings if the module can not be installed or activated
without issues.  The admin module controller also will fire a pre_deactivate
event, which allows modules to indicate issues that may arise be deactivating the
specified module.

These messages are displayed in a dialog box prior to installation in order to
allow the gallery administrator to determine the appropriate action before proceeding.

Lays the foundation for implementing a fix for ticket #937
This commit is contained in:
Tim Almdal
2010-01-21 12:57:45 -08:00
parent 6dd92cfa1c
commit d59c6ed4f1
4 changed files with 154 additions and 14 deletions
+53 -12
View File
@@ -119,6 +119,36 @@ class module_Core {
return self::$active;
}
/**
* Check that the module can be installed. (i.e. all the prerequistes exist)
* @param string $module_name
*/
static function check_environment($module_name) {
module::_add_to_path($module_name);
$messages = array();
$installer_class = "{$module_name}_installer";
if (method_exists($installer_class, "check_environment")) {
$messages = call_user_func(array($installer_class, "check_environment"));
}
// Now the module is installed but inactive, so don't leave it in the active path
module::_remove_from_path($module_name);
return $messages;
}
/**
* Check that the module can be installed. (i.e. all the prerequistes exist)
* @param string $module_name
*/
static function can_deactivate($module_name) {
$data = (object)array("module" => $module_name, "messages" => array());
module::event("pre_deactivate", $data);
return $data->messages;
}
/**
* Install a module. This will call <module>_installer::install(), which is responsible for
* creating database tables, setting module variables and calling module::set_version().
@@ -126,13 +156,8 @@ class module_Core {
* @param string $module_name
*/
static function install($module_name) {
$config = Kohana_Config::instance();
$kohana_modules = $config->get("core.modules");
array_unshift($kohana_modules, MODPATH . $module_name);
$config->set("core.modules", $kohana_modules);
module::_add_to_path($module_name);
// Rebuild the include path so the module installer can benefit from auto loading
Kohana::include_paths(true);
$installer_class = "{$module_name}_installer";
if (method_exists($installer_class, "install")) {
call_user_func_array(array($installer_class, "install"), array());
@@ -142,13 +167,32 @@ class module_Core {
module::load_modules();
// Now the module is installed but inactive, so don't leave it in the active path
array_shift($kohana_modules);
$config->set("core.modules", $kohana_modules);
module::_remove_from_path($module_name);
log::success(
"module", t("Installed module %module_name", array("module_name" => $module_name)));
}
private static function _add_to_path($module_name) {
$config = Kohana_Config::instance();
$kohana_modules = $config->get("core.modules");
array_unshift($kohana_modules, MODPATH . $module_name);
$config->set("core.modules", $kohana_modules);
// Rebuild the include path so the module installer can benefit from auto loading
Kohana::include_paths(true);
}
private static function _remove_from_path($module_name) {
$config = Kohana_Config::instance();
$kohana_modules = $config->get("core.modules");
if (($key = array_search(MODPATH . $module_name, $kohana_modules)) !== false) {
unset($kohana_modules[$key]);
$kohana_modules = array_values($kohana_modules); // reindex
}
$config->set("core.modules", $kohana_modules);
Kohana::include_paths(true);
}
/**
* Upgrade a module. This will call <module>_installer::upgrade(), which is responsible for
* modifying database tables, changing module variables and calling module::set_version().
@@ -194,10 +238,7 @@ class module_Core {
* @param string $module_name
*/
static function activate($module_name) {
$config = Kohana_Config::instance();
$kohana_modules = $config->get("core.modules");
array_unshift($kohana_modules, MODPATH . $module_name);
$config->set("core.modules", $kohana_modules);
module::_add_to_path($module_name);
$installer_class = "{$module_name}_installer";
if (method_exists($installer_class, "activate")) {