From 6dd92cfa1cbdade77721f153aa1b6aab965cff82 Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Wed, 20 Jan 2010 23:12:36 -0800 Subject: Fix maintenance tasks / language admin for bug introduced earlier by no longer casting in ORM. Task->done is now a string, boolean false is stored as integer 0 and loaded as string "0". On the client side that's interpreted as truthy in JavaScript. Fix: cast "0" to (bool) before encoding to JSON. --- modules/gallery/controllers/admin_maintenance.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 213e4fe2..aa4fb29f 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -216,7 +216,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { "task" => array( "percent_complete" => $task->percent_complete, "status" => $task->status, - "done" => $task->done), + "done" => (bool) $task->done), "location" => url::site("admin/maintenance"))); } else { @@ -224,7 +224,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { "task" => array( "percent_complete" => $task->percent_complete, "status" => $task->status, - "done" => $task->done))); + "done" => (bool) $task->done))); } } } -- cgit v1.2.3 From d59c6ed4f149c201542c8b38f9ad9d61b4daabf4 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 21 Jan 2010 12:57:45 -0800 Subject: 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 --- modules/gallery/controllers/admin_modules.php | 41 +++++++++++++- modules/gallery/helpers/module.php | 65 ++++++++++++++++++---- modules/gallery/views/admin_modules.html.php | 40 ++++++++++++- .../gallery/views/admin_modules_confirm.html.php | 22 ++++++++ 4 files changed, 154 insertions(+), 14 deletions(-) create mode 100644 modules/gallery/views/admin_modules_confirm.html.php (limited to 'modules/gallery/controllers') 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"); } } diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 6c7078a3..2ae83f0d 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -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 _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 _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")) { diff --git a/modules/gallery/views/admin_modules.html.php b/modules/gallery/views/admin_modules.html.php index aebedf09..7f572411 100644 --- a/modules/gallery/views/admin_modules.html.php +++ b/modules/gallery/views/admin_modules.html.php @@ -1,12 +1,50 @@
+

-
"> + "> diff --git a/modules/gallery/views/admin_modules_confirm.html.php b/modules/gallery/views/admin_modules_confirm.html.php new file mode 100644 index 00000000..59592505 --- /dev/null +++ b/modules/gallery/views/admin_modules_confirm.html.php @@ -0,0 +1,22 @@ + +
+

+ +

+ +
+
    + "g-error", "warn" => "g-warning") as $type => $class): ?> + +
  • + + +
+ "> + + + + + +
+
-- cgit v1.2.3 From dabd5b84b21c711592a1f3bcd2ca298dd6d7fde2 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Jan 2010 12:22:31 -0800 Subject: Remove the identity manager screens and controller as alterntive identity providers are installed in the admin module screen. --- modules/gallery/controllers/admin_identity.php | 76 ---------------------- modules/gallery/helpers/gallery_event.php | 6 +- modules/gallery/views/admin_identity.html.php | 59 ----------------- .../gallery/views/admin_identity_confirm.html.php | 10 --- 4 files changed, 1 insertion(+), 150 deletions(-) delete mode 100644 modules/gallery/controllers/admin_identity.php delete mode 100644 modules/gallery/views/admin_identity.html.php delete mode 100644 modules/gallery/views/admin_identity_confirm.html.php (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/admin_identity.php b/modules/gallery/controllers/admin_identity.php deleted file mode 100644 index 354e6c0c..00000000 --- a/modules/gallery/controllers/admin_identity.php +++ /dev/null @@ -1,76 +0,0 @@ -content = new View("admin_identity.html"); - $view->content->available = identity::providers(); - $view->content->active = module::get_var("gallery", "identity_provider", "user"); - print $view; - } - - public function confirm() { - access::verify_csrf(); - - $v = new View("admin_identity_confirm.html"); - $v->new_provider = Input::instance()->post("provider"); - - print $v; - } - - public function change() { - access::verify_csrf(); - - $active_provider = module::get_var("gallery", "identity_provider", "user"); - $providers = identity::providers(); - $new_provider = Input::instance()->post("provider"); - - if ($new_provider != $active_provider) { - - module::deactivate($active_provider); - - // Switch authentication - identity::reset(); - module::set_var("gallery", "identity_provider", $new_provider); - - module::install($new_provider); - module::activate($new_provider); - - module::event("identity_provider_changed", $active_provider, $new_provider); - - module::uninstall($active_provider); - - message::success(t("Changed to %description", - array("description" => $providers->$new_provider))); - - try { - Session::instance()->destroy(); - } catch (Exception $e) { - // We don't care if there was a problem destroying the session. - } - url::redirect(item::root()->abs_url()); - } - - message::info(t("The selected provider \"%description\" is already active.", - array("description" => $providers->$new_provider))); - url::redirect("admin/identity"); - } -} - diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 1d8e3581..6c7c2ea4 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -230,11 +230,7 @@ class gallery_event_Core { ->append(Menu::factory("link") ->id("advanced") ->label(t("Advanced")) - ->url(url::site("admin/advanced_settings"))) - ->append(Menu::factory("link") - ->id("authentication") - ->label(t("Authentication")) - ->url(url::site("admin/identity")))) + ->url(url::site("admin/advanced_settings")))) ->append(Menu::factory("link") ->id("modules") ->label(t("Modules")) diff --git a/modules/gallery/views/admin_identity.html.php b/modules/gallery/views/admin_identity.html.php deleted file mode 100644 index 51eaa58a..00000000 --- a/modules/gallery/views/admin_identity.html.php +++ /dev/null @@ -1,59 +0,0 @@ - - -
-

-

- -

- -
"> - -
- - - - - $description): ?> - "> - "provider"); ?> - - - - -
- for_html_attr() ?>" /> - -
diff --git a/modules/gallery/views/admin_identity_confirm.html.php b/modules/gallery/views/admin_identity_confirm.html.php deleted file mode 100644 index 54aae9c8..00000000 --- a/modules/gallery/views/admin_identity_confirm.html.php +++ /dev/null @@ -1,10 +0,0 @@ - -
"> - - - -

- -

-
- -- cgit v1.2.3 From df313cac567bee77f5a73308381fe67dcac9b92c Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Jan 2010 12:30:17 -0800 Subject: Change the check_environment method in the module helper and the module installers to can_activate to reflect that it is doing more than just checking the environment. --- modules/gallery/controllers/admin_modules.php | 2 +- modules/gallery/helpers/module.php | 8 ++++---- modules/slideshow/helpers/slideshow_installer.php | 2 +- modules/user/helpers/user_installer.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php index 46defbef..a2168280 100644 --- a/modules/gallery/controllers/admin_modules.php +++ b/modules/gallery/controllers/admin_modules.php @@ -42,7 +42,7 @@ class Admin_Modules_Controller extends Admin_Controller { 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)); + $messages = array_merge($messages, module::can_activate($module_name)); } } diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 595f600b..f680ff6a 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -120,17 +120,17 @@ class module_Core { } /** - * Check that the module can be installed. (i.e. all the prerequistes exist) + * Check that the module can be activated. (i.e. all the prerequistes exist) * @param string $module_name * @return array an array of warning or error messages to be displayed */ - static function check_environment($module_name) { + static function can_activate($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")); + if (method_exists($installer_class, "can_activate")) { + $messages = call_user_func(array($installer_class, "can_activate")); } // Remove it from the active path diff --git a/modules/slideshow/helpers/slideshow_installer.php b/modules/slideshow/helpers/slideshow_installer.php index 319e2e79..8d612f3e 100644 --- a/modules/slideshow/helpers/slideshow_installer.php +++ b/modules/slideshow/helpers/slideshow_installer.php @@ -34,7 +34,7 @@ class slideshow_installer { site_status::clear("slideshow_needs_rss"); } - static function check_environment() { + static function can_activate() { $messages = array(); if (!module::is_active("rss")) { $messages["warn"][] = t("The Slideshow module requires the RSS module."); diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 3882f5f2..38f8020b 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class user_installer { - static function check_environment() { + static function can_activate() { return array("warn" => array(IdentityProvider::confirmation_message())); } -- cgit v1.2.3 From eabeeeb1267e0c925b5f31b2455a080bc2e9f237 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Jan 2010 13:38:05 -0800 Subject: Trap any errors that may occur when trying to install a new identity provider and then reinstall the current one. --- modules/gallery/controllers/admin_modules.php | 31 +++++++++++--------- modules/gallery/libraries/IdentityProvider.php | 40 ++++++++++++++++++-------- 2 files changed, 45 insertions(+), 26 deletions(-) (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php index a2168280..84fee25d 100644 --- a/modules/gallery/controllers/admin_modules.php +++ b/modules/gallery/controllers/admin_modules.php @@ -76,21 +76,24 @@ class Admin_Modules_Controller extends Admin_Controller { continue; } - $desired = Input::instance()->post($module_name) == 1; - if ($info->active && !$desired && module::is_active($module_name)) { - $changes->deactivate[] = $module_name; - $deactivated_names[] = t($info->name); - module::deactivate($module_name); - } 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 { - module::install($module_name); + try { + $desired = Input::instance()->post($module_name) == 1; + if ($info->active && !$desired && module::is_active($module_name)) { + module::deactivate($module_name); + $changes->deactivate[] = $module_name; + $deactivated_names[] = t($info->name); + } else if (!$info->active && $desired && !module::is_active($module_name)) { + if (module::is_installed($module_name)) { + module::upgrade($module_name); + } else { + module::install($module_name); + } + module::activate($module_name); + $changes->activate[] = $module_name; + $activated_names[] = t($info->name); } - module::activate($module_name); + } catch (Exception $e) { + Kohana_Log::add("error", (string)$e); } } diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php index f7be33e3..e07838d1 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -71,19 +71,35 @@ class IdentityProvider_Core { module::uninstall($current_provider); } - IdentityProvider::reset(); - $provider = new IdentityProvider($new_provider); - - module::set_var("gallery", "identity_provider", $new_provider); - - if (method_exists("{$new_provider}_installer", "initialize")) { - call_user_func("{$new_provider}_installer::initialize"); + try { + IdentityProvider::reset(); + $provider = new IdentityProvider($new_provider); + + module::set_var("gallery", "identity_provider", $new_provider); + + if (method_exists("{$new_provider}_installer", "initialize")) { + call_user_func("{$new_provider}_installer::initialize"); + } + + module::event("identity_provider_changed", $current_provider, $new_provider); + + auth::login($provider->admin_user()); + Session::instance()->regenerate(); + } catch (Exception $e) { + // Make sure new provider is not in the database + module::uninstall($new_provider); + + // Lets reset to the current provider so that the gallery installation is still + // working. + module::set_var("gallery", "identity_provider", null); + IdentityProvider::change_provider($current_provider); + module::activate($current_provider); + message::error( + t("Error attempting to enable \"%new_provider\" identity provider, " . + "reverted to \"%old_provider\" identity provider", + array("new_provider" => $new_provider, "old_provider" => $current_provider))); + throw $e; } - - module::event("identity_provider_changed", $current_provider, $new_provider); - - auth::login($provider->admin_user()); - Session::instance()->regenerate(); } /** -- cgit v1.2.3 From ece403877fa0a8bf385a1c52d7be99b1e2b002f4 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Jan 2010 18:12:30 -0800 Subject: If the userid/password combination, render the full page instead of just printing the form. Fixes ticket #980. --- modules/gallery/controllers/login.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php index 75ee6b9c..cfccaf17 100644 --- a/modules/gallery/controllers/login.php +++ b/modules/gallery/controllers/login.php @@ -50,7 +50,11 @@ class Login_Controller extends Controller { if ($valid) { url::redirect(item::root()->abs_url()); } else { - print $form; + $view = new Theme_View("page.html", "other", "login"); + $view->page_title = t("Log in to Gallery"); + $view->content = new View("login_ajax.html"); + $view->content->form = $form; + print $view; } } -- cgit v1.2.3