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') 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') 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 ff2d81b7c3b75e548766fb8a0ae370cbb2e39bf5 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 21 Jan 2010 13:03:58 -0800 Subject: Convert the slideshow module to use the new check environment and pre_deactivate api methods. --- modules/slideshow/helpers/slideshow_event.php | 6 ++++++ modules/slideshow/helpers/slideshow_installer.php | 8 ++++++++ 2 files changed, 14 insertions(+) (limited to 'modules') diff --git a/modules/slideshow/helpers/slideshow_event.php b/modules/slideshow/helpers/slideshow_event.php index c4d7c56d..137ec313 100644 --- a/modules/slideshow/helpers/slideshow_event.php +++ b/modules/slideshow/helpers/slideshow_event.php @@ -18,6 +18,12 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class slideshow_event_Core { + static function pre_deactivate($data) { + if ($data->module == "rss") { + $data->messages["warn"][] = t("The Slideshow module requires the RSS module."); + } + } + static function module_change($changes) { if (!module::is_active("rss") || in_array("rss", $changes->deactivate)) { site_status::warning( diff --git a/modules/slideshow/helpers/slideshow_installer.php b/modules/slideshow/helpers/slideshow_installer.php index 03f3332c..319e2e79 100644 --- a/modules/slideshow/helpers/slideshow_installer.php +++ b/modules/slideshow/helpers/slideshow_installer.php @@ -33,4 +33,12 @@ class slideshow_installer { static function deactivate() { site_status::clear("slideshow_needs_rss"); } + + static function check_environment() { + $messages = array(); + if (!module::is_active("rss")) { + $messages["warn"][] = t("The Slideshow module requires the RSS module."); + } + return $messages; + } } -- cgit v1.2.3 From 0da5d9e606fba5b6dc6137812df32cd1d0f5750f Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 21 Jan 2010 20:33:26 -0800 Subject: Internationalize all strings in admin_modules.hmtl and corrected comments. --- modules/gallery/helpers/module.php | 6 ++++-- modules/gallery/views/admin_modules.html.php | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 2ae83f0d..595f600b 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -122,6 +122,7 @@ class module_Core { /** * Check that the module can be installed. (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) { module::_add_to_path($module_name); @@ -132,14 +133,15 @@ class module_Core { $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 + // Remove it from the active path module::_remove_from_path($module_name); return $messages; } /** - * Check that the module can be installed. (i.e. all the prerequistes exist) + * Allow modules to indicate the impact of deactivating the specifeid module * @param string $module_name + * @return array an array of warning or error messages to be displayed */ static function can_deactivate($module_name) { $data = (object)array("module" => $module_name, "messages" => array()); diff --git a/modules/gallery/views/admin_modules.html.php b/modules/gallery/views/admin_modules.html.php index 7f572411..704e7beb 100644 --- a/modules/gallery/views/admin_modules.html.php +++ b/modules/gallery/views/admin_modules.html.php @@ -18,12 +18,12 @@ height: 400, width: 500, position: "center", - title: "Confirm Module Activation", + title: for_js() ?>, buttons: { - "Continue": function() { + for_js() ?>: function() { $("form", this).submit(); }, - Cancel: function() { + for_js() ?>: function() { $(this).dialog("destroy").remove(); } } -- cgit v1.2.3 From 07ba5fe43aaa53be840b1842fe2eb4fc63ee7686 Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Thu, 21 Jan 2010 23:53:21 -0800 Subject: Use Unicode instead of HTML entity (since the l10n server normalizes this way and rejects submissions that change under the normalization step) --- modules/gallery/helpers/gallery_event.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 679d65c2..b39be169 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -305,7 +305,7 @@ class gallery_event_Core { ->append( Menu::factory("ajax_link") ->id("rotate_ccw") - ->label(t("Rotate 90° counter clockwise")) + ->label(t("Rotate 90° counter clockwise")) ->css_class("ui-icon-rotate-ccw") ->ajax_handler("function(data) { " . "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }") @@ -313,7 +313,7 @@ class gallery_event_Core { ->append( Menu::factory("ajax_link") ->id("rotate_cw") - ->label(t("Rotate 90° clockwise")) + ->label(t("Rotate 90° clockwise")) ->css_class("ui-icon-rotate-cw") ->ajax_handler("function(data) { " . "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }") -- cgit v1.2.3 From 120c9c749e175cc6c67ae628ee1a8a967a8ddbcc Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Fri, 22 Jan 2010 01:16:16 -0800 Subject: Change "fetch translations" task to fetch them in batches. The request limit was in place already, but the client didn't respect it before, leading to unhappy users in case they had lots of 3rd party modules installed, or more than 2-3 locales enabled. This is all taken care of now. --- modules/gallery/helpers/gallery_task.php | 31 +++++++++++++-------- modules/gallery/helpers/l10n_client.php | 47 +++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 22 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 3a705027..b3b79e06 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -122,7 +122,7 @@ class gallery_task_Core { $start = microtime(true); $data = Cache::instance()->get("update_l10n_cache:{$task->id}"); if ($data) { - list($dirs, $files, $cache) = unserialize($data); + list($dirs, $files, $cache, $num_fetched) = unserialize($data); } $i = 0; @@ -130,6 +130,7 @@ class gallery_task_Core { case "init": // 0% $dirs = array("gallery", "modules", "themes", "installer"); $files = $cache = array(); + $num_fetched = 0; $task->set("mode", "find_files"); $task->status = t("Finding files"); break; @@ -161,7 +162,7 @@ class gallery_task_Core { } break; - case "scan_files": // 10% - 90% + case "scan_files": // 10% - 70% while (($file = array_pop($files)) && microtime(true) - $start < 0.5) { $file = DOCROOT . $file; switch (pathinfo($file, PATHINFO_EXTENSION)) { @@ -179,25 +180,31 @@ class gallery_task_Core { $task->status = t2("Scanning files: scanned 1 file", "Scanning files: scanned %count files", $total_files - count($files)); - $task->percent_complete = 10 + 80 * ($total_files - count($files)) / $total_files; + $task->percent_complete = 10 + 60 * ($total_files - count($files)) / $total_files; if (empty($files)) { $task->set("mode", "fetch_updates"); $task->status = t("Fetching updates"); - $task->percent_complete = 90; + $task->percent_complete = 70; } break; - case "fetch_updates": // 90% - 100% - l10n_client::fetch_updates(); - $task->done = true; - $task->state = "success"; - $task->status = t("Translations installed/updated"); - $task->percent_complete = 100; + case "fetch_updates": // 70% - 100% + // Send fetch requests in batches until we're done + $num_remaining = l10n_client::fetch_updates($num_fetched); + if ($num_remaining) { + $total = $num_fetched + $num_remaining; + $task->percent_complete = 70 + 30 * ((float) $num_fetched / $total); + } else { + $task->done = true; + $task->state = "success"; + $task->status = t("Translations installed/updated"); + $task->percent_complete = 100; + } } - if ($task->percent_complete < 100) { + if (!$task->done) { Cache::instance()->set("update_l10n_cache:{$task->id}", - serialize(array($dirs, $files, $cache))); + serialize(array($dirs, $files, $cache, $num_fetched))); } else { Cache::instance()->delete("update_l10n_cache:{$task->id}"); } diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index fe70933d..086245e8 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -68,9 +68,15 @@ class l10n_client_Core { } /** - * @return an array of messages that will be written to the task log + * Fetches translations for l10n messages. Must be called repeatedly + * until 0 is returned (which is a countdown indicating progress). + * + * @param $num_fetched in/out parameter to specify which batch of + * messages to fetch translations for. + * @return The number of messages for which we didn't fetch + * translations for. */ - static function fetch_updates() { + static function fetch_updates(&$num_fetched) { $request->locales = array(); $request->messages = new stdClass(); @@ -79,23 +85,42 @@ class l10n_client_Core { $request->locales[] = $locale; } - // @todo Batch requests (max request size) - foreach (db::build() - ->select("key", "locale", "revision", "translation") - ->from("incoming_translations") - ->execute() as $row) { + // See the server side code for how we arrive at this + // number as a good limit for #locales * #messages. + $max_messages = 2000 / count($locales); + $num_messages = 0; + $rows = db::build() + ->select("key", "locale", "revision", "translation") + ->from("incoming_translations") + ->order_by("key") + ->limit(1000000) // ignore, just there to satisfy SQL syntax + ->offset($num_fetched) + ->execute(); + $num_remaining = $rows->count(); + foreach ($rows as $row) { if (!isset($request->messages->{$row->key})) { + if ($num_messages >= $max_messages) { + break; + } $request->messages->{$row->key} = 1; + $num_messages++; } - if (!empty($row->revision) && !empty($row->translation)) { + if (!empty($row->revision) && !empty($row->translation) && + isset($locales[$row->locale])) { if (!is_object($request->messages->{$row->key})) { $request->messages->{$row->key} = new stdClass(); } - $request->messages->{$row->key}->{$row->locale} = $row->revision; + $request->messages->{$row->key}->{$row->locale} = (int) $row->revision; } + $num_fetched++; + $num_remaining--; } // @todo Include messages from outgoing_translations? + if (!$num_messages) { + return $num_remaining; + } + $request_data = json_encode($request); $url = self::_server_url() . "?q=translations/fetch"; list ($response_data, $response_status) = remote::post($url, array("data" => $request_data)); @@ -103,7 +128,7 @@ class l10n_client_Core { throw new Exception("@todo TRANSLATIONS_FETCH_REQUEST_FAILED " . $response_status); } if (empty($response_data)) { - return array(t("Translations fetch request resulted in an empty response")); + return $num_remaining; } $response = json_decode($response_data); @@ -150,6 +175,8 @@ class l10n_client_Core { $entry->translation = $translation; $entry->save(); } + + return $num_remaining; } static function submit_translations() { -- cgit v1.2.3 From 603c3049a1ce7249c55ff8338fc3ea69323f0cb3 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Jan 2010 09:39:29 -0800 Subject: Treat identity providers just like other modules and use the admin_module to install and switch to a different identity provider. --- modules/comment/helpers/comment_event.php | 18 +++++++++-------- modules/gallery/helpers/gallery_event.php | 32 ++++++++++++++++--------------- modules/user/helpers/user_installer.php | 24 +++++++++++------------ modules/user/module.info | 2 -- 4 files changed, 38 insertions(+), 38 deletions(-) (limited to 'modules') diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index 43a30d70..bd336cda 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -27,14 +27,16 @@ class comment_event_Core { static function user_deleted($user) { $guest = identity::guest(); - db::build() - ->update("comments") - ->set("author_id", $guest->id) - ->set("guest_email", null) - ->set("guest_name", "guest") - ->set("guest_url", null) - ->where("author_id", "=", $user->id) - ->execute(); + if (!empty($guest)) { // could be empty if there is not identity provider + db::build() + ->update("comments") + ->set("author_id", $guest->id) + ->set("guest_email", null) + ->set("guest_name", "guest") + ->set("guest_url", null) + ->where("author_id", "=", $user->id) + ->execute(); + } } static function identity_provider_changed($old_provider, $new_provider) { diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 679d65c2..1d8e3581 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -30,21 +30,23 @@ class gallery_event_Core { static function user_deleted($user) { $admin = identity::admin_user(); - db::build() - ->update("tasks") - ->set("owner_id", $admin->id) - ->where("owner_id", "=", $user->id) - ->execute(); - db::build() - ->update("items") - ->set("owner_id", $admin->id) - ->where("owner_id", "=", $user->id) - ->execute(); - db::build() - ->update("logs") - ->set("user_id", $admin->id) - ->where("user_id", "=", $user->id) - ->execute(); + if (!empty($admin)) { // could be empty if there is not identity provider + db::build() + ->update("tasks") + ->set("owner_id", $admin->id) + ->where("owner_id", "=", $user->id) + ->execute(); + db::build() + ->update("items") + ->set("owner_id", $admin->id) + ->where("owner_id", "=", $user->id) + ->execute(); + db::build() + ->update("logs") + ->set("user_id", $admin->id) + ->where("user_id", "=", $user->id) + ->execute(); + } } static function identity_provider_changed($old_provider, $new_provider) { diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 0cba502f..dd21c93c 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -20,6 +20,13 @@ class user_installer { static function install() { $db = Database::instance(); + $current_provider = module::get_var("gallery", "identity_provider"); + if (!empty($current_provider)) { + module::uninstall($current_provider); + } + IdentityProvider::reset(); + module::set_var("gallery", "identity_provider", "user"); + $db->query("CREATE TABLE IF NOT EXISTS {users} ( `id` int(9) NOT NULL auto_increment, `name` varchar(32) NOT NULL, @@ -70,19 +77,6 @@ class user_installer { $admin->admin = true; $admin->save(); - $current_provider = module::get_var("gallery", "identity_provider"); - if (empty($current_provider)) { - // If there is no provider defined then we are doing an initial install - // so we need to set the provider and make the administrator own everything - // If the installer is called and there is an identity provider, then we - // are switching identity providers and and the event handlers will do the - // right things - module::set_var("gallery", "identity_provider", "user"); - - // Let the admin own everything - $db->query("update {items} set owner_id = {$admin->id}"); - } - $root = ORM::factory("item", 1); access::allow($everybody, "view", $root); access::allow($everybody, "view_full", $root); @@ -93,6 +87,10 @@ class user_installer { module::set_var("user", "mininum_password_length", 5); module::set_version("user", 2); + module::event("identity_provider_changed", $current_provider, "user"); + + auth::login(IdentityProvider::instance()->admin_user()); + Session::instance()->regenerate(); } static function upgrade($version) { diff --git a/modules/user/module.info b/modules/user/module.info index 7178f108..d1e02382 100644 --- a/modules/user/module.info +++ b/modules/user/module.info @@ -2,5 +2,3 @@ name = "Users and Groups" description = "Gallery 3 user and group management" version = 2 -; Don't show this module on the module administration screen -no_module_admin = 1 -- cgit v1.2.3 From ae568b6182544b84067aa099eec494da477d083f Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Jan 2010 12:09:11 -0800 Subject: Refactor the identity provider installation in to a common helper method (change_provider) with an initialization callback. --- modules/gallery/libraries/IdentityProvider.php | 29 +++++++++++ modules/user/helpers/user_installer.php | 68 ++++++++++++-------------- 2 files changed, 61 insertions(+), 36 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php index bcb3056a..f7be33e3 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -57,6 +57,35 @@ class IdentityProvider_Core { Kohana_Config::instance()->clear("identity"); } + /** + * Return a commen confirmation message + */ + static function confirmation_message() { + return t("Are you sure you want to change your Identity Provider? " . + "Continuing will delete all existing users."); + } + + static function change_provider($new_provider) { + $current_provider = module::get_var("gallery", "identity_provider"); + if (!empty($current_provider)) { + 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"); + } + + module::event("identity_provider_changed", $current_provider, $new_provider); + + auth::login($provider->admin_user()); + Session::instance()->regenerate(); + } + /** * Loads the configured driver and validates it. * diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index dd21c93c..3882f5f2 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -18,15 +18,40 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class user_installer { + static function check_environment() { + return array("warn" => array(IdentityProvider::confirmation_message())); + } + static function install() { - $db = Database::instance(); - $current_provider = module::get_var("gallery", "identity_provider"); - if (!empty($current_provider)) { - module::uninstall($current_provider); + IdentityProvider::change_provider("user"); + } + + static function upgrade($version) { + if ($version == 1) { + module::set_var("user", "mininum_password_length", 5); + + module::set_version("user", $version = 2); + } + } + + static function uninstall() { + // Delete all users and groups so that we give other modules an opportunity to clean up + foreach (ORM::factory("user")->find_all() as $user) { + $user->delete(); + } + + foreach (ORM::factory("group")->find_all() as $group) { + $group->delete(); } - IdentityProvider::reset(); - module::set_var("gallery", "identity_provider", "user"); + $db = Database::instance(); + $db->query("DROP TABLE IF EXISTS {users};"); + $db->query("DROP TABLE IF EXISTS {groups};"); + $db->query("DROP TABLE IF EXISTS {groups_users};"); + } + + static function initialize() { + $db = Database::instance(); $db->query("CREATE TABLE IF NOT EXISTS {users} ( `id` int(9) NOT NULL auto_increment, `name` varchar(32) NOT NULL, @@ -84,36 +109,7 @@ class user_installer { access::allow($registered, "view", $root); access::allow($registered, "view_full", $root); - module::set_var("user", "mininum_password_length", 5); - module::set_version("user", 2); - module::event("identity_provider_changed", $current_provider, "user"); - - auth::login(IdentityProvider::instance()->admin_user()); - Session::instance()->regenerate(); - } - - static function upgrade($version) { - if ($version == 1) { - module::set_var("user", "mininum_password_length", 5); - - module::set_version("user", $version = 2); - } - } - - static function uninstall() { - // Delete all users and groups so that we give other modules an opportunity to clean up - foreach (ORM::factory("user")->find_all() as $user) { - $user->delete(); - } - - foreach (ORM::factory("group")->find_all() as $group) { - $group->delete(); - } - - $db = Database::instance(); - $db->query("DROP TABLE IF EXISTS {users};"); - $db->query("DROP TABLE IF EXISTS {groups};"); - $db->query("DROP TABLE IF EXISTS {groups_users};"); + module::set_var("user", "mininum_password_length", 5); } } \ No newline at end of file -- cgit v1.2.3 From 11757831233da528662864e23d89f39bfb908801 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Jan 2010 12:16:36 -0800 Subject: Disable the continue button after clicking so it can only clicked once. --- modules/gallery/views/admin_modules.html.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules') diff --git a/modules/gallery/views/admin_modules.html.php b/modules/gallery/views/admin_modules.html.php index 704e7beb..a021d969 100644 --- a/modules/gallery/views/admin_modules.html.php +++ b/modules/gallery/views/admin_modules.html.php @@ -22,6 +22,9 @@ buttons: { for_js() ?>: function() { $("form", this).submit(); + $(".ui-dialog-buttonpane button:contains(Continue)") + .attr("disabled", "disabled") + .addClass("ui-state-disabled"); }, for_js() ?>: function() { $(this).dialog("destroy").remove(); -- 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') 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') 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') 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 b01fce613b8df5f23a3a257f5680433a8224247d Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Jan 2010 14:16:41 -0800 Subject: Remove the g-right class on groups element on the manage user/groups page. fixes ticket #911 --- modules/user/views/admin_users.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php index 45d04916..270a7207 100644 --- a/modules/user/views/admin_users.html.php +++ b/modules/user/views/admin_users.html.php @@ -107,7 +107,7 @@
-
+
" class="g-dialog-link g-button g-right ui-icon-left ui-state-default ui-corner-all" title="for_html_attr() ?>"> -- cgit v1.2.3 From ff5ccf0fb34a19306e4177a9a2f2c4c6f503cb1a Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Jan 2010 14:38:58 -0800 Subject: Specify the height and overflow-y on l10n-client translation element. fixes ticket #899. --- modules/gallery/css/l10n_client.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/css/l10n_client.css b/modules/gallery/css/l10n_client.css index 3771c049..053b4432 100644 --- a/modules/gallery/css/l10n_client.css +++ b/modules/gallery/css/l10n_client.css @@ -184,7 +184,9 @@ } #l10n-client-string-editor .translation { - overflow:hidden; + overflow-y:auto; + overflow-x: hidden; + height: 20em; width:49%; float: right; } -- 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') 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 From 06ef3885b30be843a7c86a93f5642680ab881b1c Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 23 Jan 2010 09:23:08 -0800 Subject: Increase the size of the 'select photos' button so that it doesn't wrap and set the size of the underlying flash object. --- modules/gallery/views/form_uploadify.html.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/gallery/views/form_uploadify.html.php b/modules/gallery/views/form_uploadify.html.php index f3b9c883..b3b81ecb 100644 --- a/modules/gallery/views/form_uploadify.html.php +++ b/modules/gallery/views/form_uploadify.html.php @@ -2,17 +2,21 @@ @@ -21,6 +25,8 @@