summaryrefslogtreecommitdiff
path: root/modules/gallery/controllers/admin_modules.php
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2010-01-21 12:57:45 -0800
committerTim Almdal <tnalmdal@shaw.ca>2010-01-21 12:57:45 -0800
commitd59c6ed4f149c201542c8b38f9ad9d61b4daabf4 (patch)
treeec977402f5a2a83990efb5159654d8083be22b0f /modules/gallery/controllers/admin_modules.php
parent6dd92cfa1cbdade77721f153aa1b6aab965cff82 (diff)
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
Diffstat (limited to 'modules/gallery/controllers/admin_modules.php')
-rw-r--r--modules/gallery/controllers/admin_modules.php41
1 files changed, 40 insertions, 1 deletions
diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php
index 549718e7..46defbef 100644
--- a/modules/gallery/controllers/admin_modules.php
+++ b/modules/gallery/controllers/admin_modules.php
@@ -25,9 +25,48 @@ class Admin_Modules_Controller extends Admin_Controller {
print $view;
}
+
+ public function confirm() {
+ access::verify_csrf();
+
+ $messages = array("error" => array(), "warn" => array());
+ $desired_list = array();
+ foreach (module::available() as $module_name => $info) {
+ if ($info->locked) {
+ continue;
+ }
+
+ if ($desired = Input::instance()->post($module_name) == 1) {
+ $desired_list[] = $module_name;
+ }
+ if ($info->active && !$desired && module::is_active($module_name)) {
+ $messages = array_merge($messages, module::can_deactivate($module_name));
+ } else if (!$info->active && $desired && !module::is_active($module_name)) {
+ $messages = array_merge($messages, module::check_environment($module_name));
+ }
+ }
+
+ if (empty($messages["error"]) && empty($messages["warn"])) {
+ $this->_do_save();
+ $result["reload"] = 1;
+ } else {
+ $v = new View("admin_modules_confirm.html");
+ $v->messages = $messages;
+ $v->modules = $desired_list;
+ $result["dialog"] = (string)$v;
+ $result["allow_continue"] = empty($messages["error"]);
+ }
+ print json_encode($result);
+ }
+
public function save() {
access::verify_csrf();
+ $this->_do_save();
+ url::redirect("admin/modules");
+ }
+
+ private function _do_save() {
$changes->activate = array();
$changes->deactivate = array();
$activated_names = array();
@@ -45,6 +84,7 @@ class Admin_Modules_Controller extends Admin_Controller {
} else if (!$info->active && $desired && !module::is_active($module_name)) {
$changes->activate[] = $module_name;
$activated_names[] = t($info->name);
+
if (module::is_installed($module_name)) {
module::upgrade($module_name);
} else {
@@ -63,7 +103,6 @@ class Admin_Modules_Controller extends Admin_Controller {
if ($deactivated_names) {
message::success(t("Deactivated: %names", array("names" => join(", ", $deactivated_names))));
}
- url::redirect("admin/modules");
}
}