From f8b8103c24cb50612b061cb6a4787695b600735c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 25 Jan 2010 19:49:52 -0800 Subject: Make only one attempt to restore the old identity provider in case of failure. Else, we can get into an infinite recursion. --- modules/gallery/libraries/IdentityProvider.php | 34 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php index e07838d1..2ed85bd1 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -86,18 +86,28 @@ class IdentityProvider_Core { 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))); + static $restore_already_running; + + // In case of error, make an attempt to restore the old provider. Since that's calling into + // this function again and can fail, we should be sure not to get into an infinite recursion. + if (!$restore_already_running) { + $restore_already_running = true; + + // 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))); + + $restore_already_running = false; + } throw $e; } } -- cgit v1.2.3 From 119297e2adc3dfb452d2337f4b167b3e00c5b7e6 Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Mon, 25 Jan 2010 23:05:41 -0800 Subject: Apply html::clean() to UI visible strings, and show language names instead of locale tags to be consistent with the user edit form. --- modules/gallery/helpers/gallery_event.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 6b70513a..b35ae3c4 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -381,18 +381,22 @@ class gallery_event_Core { static function show_user_profile($data) { $v = new View("user_profile_info.html"); - $fields = array("name" => t("Name"), "locale" => t("Locale"), "email" => t("Email"), - "full_name" => t("Full name"), "url" => "Web site"); + $fields = array("name" => t("Name"), "locale" => t("Language Preference"), + "email" => t("Email"), "full_name" => t("Full name"), "url" => "Web site"); if (!$data->display_all) { $fields = array("name" => t("Name"), "full_name" => t("Full name"), "url" => "Web site"); } $v->fields = array(); foreach ($fields as $field => $label) { if (!empty($data->user->$field)) { - $v->fields[(string)$label->for_html()] = $data->user->$field; + $value = $data->user->$field; + if ($field == "locale") { + $value = locales::display_name($value); + } + $v->fields[(string) $label] = html::clean($value); } } - $data->content[] = (object)array("title" => t("User information"), "view" => $v); + $data->content[] = (object) array("title" => t("User information"), "view" => $v); } } -- cgit v1.2.3 From accd00464e2d7e1d1fd0e24e1ee583a7baa73611 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 26 Jan 2010 07:03:14 -0800 Subject: Add a maintenance task that will clear the expired files (older than 2 weeks) from var/logs and var/tmp. Fixes ticket #982 --- modules/gallery/helpers/gallery_task.php | 74 +++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index b3b79e06..5402b5d1 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -37,6 +37,11 @@ class gallery_task_Core { ->description(t("Download new and updated translated strings")) ->severity(log::SUCCESS); + $tasks[] = Task_Definition::factory() + ->callback("gallery_task::file_cleanup") + ->name(t("Remove old files")) + ->description(t("Remove files from the logs and tmp directory")) + ->severity(log::SUCCESS); return $tasks; } @@ -116,7 +121,7 @@ class gallery_task_Core { } } - static function update_l10n(&$task) { + static function update_l10n($task) { $errors = array(); try { $start = microtime(true); @@ -218,4 +223,71 @@ class gallery_task_Core { $task->log($errors); } } + + /** + * Task that removes old files from var/logs and var/tmp. + * @param Task_Model the task + */ + static function file_cleanup($task) { + $errors = array(); + try { + $start = microtime(true); + $data = Cache::instance()->get("file_cleanup_cache:{$task->id}"); + if ($data) { + $files = unserialize($data); + } + $i = 0; + + switch ($task->get("mode", "init")) { + case "init": // 0% + $threshold = time() - 1209600; // older than 2 weeks + foreach(array("logs", "tmp") as $dir) { + $dir = VARPATH . $dir; + if ($dh = opendir($dir)) { + while (($file = readdir($dh)) !== false) { + if ($file[0] == ".") { + continue; + } + + if (filemtime("$dir/$file") <= $threshold) { + $files[] = "$dir/$file"; + } + } + } + } + $task->set("mode", "delete_files"); + $task->set("current", 0); + $task->set("total", count($files)); + Cache::instance()->set("file_cleanup_cache:{$task->id}", serialize($files)); + if (count($files) == 0) { + break; + } + case "delete_files": + $current = $task->get("current"); + $total = $task->get("total"); + while ($current < $total && microtime(true) - $start < 1) { + @unlink($files[$current]); + $task->log(t("%file removed", array("file" => $files[$current++]))); + } + $task->percent_complete = $current / $total * 100; + $task->set("current", $current); + } + + $task->status = t("Removed: %count files. Total: %total_count.", + array("count" => $current, "total_count" => $total)); + + if ($total == $current) { + $task->done = true; + $task->state = "success"; + } + } catch (Exception $e) { + $task->done = true; + $task->state = "error"; + $task->status = $e->getMessage(); + $errors[] = $e->__toString(); + } + if ($errors) { + $task->log($errors); + } + } } \ No newline at end of file -- cgit v1.2.3 From e315ce348bee75290e65e2376cc4f34b0f285cea Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 26 Jan 2010 13:26:03 -0800 Subject: Added view_permissions_propagate_down_to_photos_test(). --- modules/gallery/tests/Access_Helper_Test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'modules') diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index b2244766..298dd0ac 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -203,6 +203,18 @@ class Access_Helper_Test extends Unit_Test_Case { $this->assert_true(access::group_can(identity::everybody(), "view", $album)); } + public function view_permissions_propagate_down_to_photos_test() { + $album = album::create(item::root(), rand(), "test album"); + $photo = photo::create($album, MODPATH . "gallery/images/gallery.png", "", ""); + identity::set_active_user(identity::guest()); + + $this->assert_true(access::can("view", $photo)); + access::deny(identity::everybody(), "view", $album); + + $photo->reload(); // view permissions are cached in the photo + $this->assert_false(access::can("view", $photo)); + } + public function can_toggle_view_permissions_propagate_down_test() { $root = ORM::factory("item", 1); $album1 = album::create($root, rand(), "test album"); -- cgit v1.2.3 From 0de067312e375fae00d63b99d280aa796f043c22 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 26 Jan 2010 19:59:44 -0800 Subject: Add a routing that allow add and edit form requests to be routed the same way as non admin forms. i.e. a uri of /form/add/admin//parms gets routed as admin/ --- modules/gallery/config/routes.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'modules') diff --git a/modules/gallery/config/routes.php b/modules/gallery/config/routes.php index 63cc6150..8ccd5a01 100644 --- a/modules/gallery/config/routes.php +++ b/modules/gallery/config/routes.php @@ -21,6 +21,10 @@ // Admin controllers are not available, except via /admin $config["^admin_.*"] = null; +// Redirect /form/add/admin/controller and /form/edit/admin/controller to +// admin/controller/form_(add|edit)/parms. provides the same as below for admin pages +$config["^form/(edit|add)/admin/(\w+)/(.*)$"] = "admin/$2/form_$1/$3"; + // Redirect /form/add and /form/edit to the module/form_(add|edit)/parms. $config["^form/(edit|add)/(\w+)/(.*)$"] = "$2/form_$1/$3"; -- cgit v1.2.3