From 813542943076927485e522e7ea61cef237195c05 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 17 Sep 2010 13:39:48 -0700 Subject: Checkpoint. --- modules/gallery/tests/controller_auth_data.txt | 2 +- modules/gallery/tests/xss_data.txt | 32 +++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'modules') diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index 03032fd9..9ea6043a 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -34,7 +34,7 @@ modules/search/controllers/search.php index modules/server_add/controllers/admin_server_add.php autocomplete DIRTY_CSRF modules/server_add/controllers/server_add.php children DIRTY_CSRF modules/tag/controllers/admin_tags.php index DIRTY_CSRF -modules/tag/controllers/tags.php show DIRTY_CSRF|DIRTY_AUTH +modules/tag/controllers/tag.php __call DIRTY_CSRF|DIRTY_AUTH modules/tag/controllers/tags.php autocomplete DIRTY_CSRF|DIRTY_AUTH modules/user/controllers/password.php reset DIRTY_AUTH modules/user/controllers/password.php do_reset DIRTY_CSRF|DIRTY_AUTH diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 6821c963..a714b3e5 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -58,9 +58,9 @@ modules/gallery/views/admin_block_photo_stream.html.php 6 DIRTY photo: modules/gallery/views/admin_block_photo_stream.html.php 7 DIRTY_ATTR $photo->thumb_url() modules/gallery/views/admin_dashboard.html.php 5 DIRTY_JS $csrf modules/gallery/views/admin_dashboard.html.php 35 DIRTY $blocks -modules/gallery/views/admin_graphics.html.php 24 DIRTY newView("admin_graphics_none.html") -modules/gallery/views/admin_graphics.html.php 26 DIRTY newView("admin_graphics_$active.html",array("tk"=>$tk->$active,"is_active"=>true)) -modules/gallery/views/admin_graphics.html.php 33 DIRTY newView("admin_graphics_$id.html",array("tk"=>$tk->$id,"is_active"=>false)) +modules/gallery/views/admin_graphics.html.php 25 DIRTY newView("admin_graphics_none.html") +modules/gallery/views/admin_graphics.html.php 27 DIRTY newView("admin_graphics_$active.html",array("tk"=>$tk->$active,"is_active"=>true)) +modules/gallery/views/admin_graphics.html.php 34 DIRTY newView("admin_graphics_$id.html",array("tk"=>$tk->$id,"is_active"=>false)) modules/gallery/views/admin_graphics_gd.html.php 2 DIRTY_ATTR $is_active?" g-selected":"" modules/gallery/views/admin_graphics_gd.html.php 2 DIRTY_ATTR $tk->installed?" g-installed-toolkit":" g-unavailable" modules/gallery/views/admin_graphics_gd.html.php 19 DIRTY $tk->error @@ -274,19 +274,19 @@ modules/notification/views/item_updated.html.php 20 DIRTY_JS $item- modules/notification/views/item_updated.html.php 20 DIRTY $item->abs_url() modules/notification/views/user_profile_notification.html.php 5 DIRTY_ATTR $subscription->id modules/notification/views/user_profile_notification.html.php 6 DIRTY_JS $subscription->url -modules/organize/views/organize_dialog.html.php 90 DIRTY_JS $domain -modules/organize/views/organize_dialog.html.php 91 DIRTY_JS $access_key -modules/organize/views/organize_dialog.html.php 92 DIRTY_JS request::protocol() -modules/organize/views/organize_dialog.html.php 93 DIRTY_JS $file_filter -modules/organize/views/organize_dialog.html.php 94 DIRTY_JS $sort_order -modules/organize/views/organize_dialog.html.php 95 DIRTY_JS $sort_fields -modules/organize/views/organize_dialog.html.php 96 DIRTY_JS $album->id -modules/organize/views/organize_dialog.html.php 97 DIRTY_JS $selected_id -modules/organize/views/organize_dialog.html.php 98 DIRTY_JS $rest_uri -modules/organize/views/organize_dialog.html.php 99 DIRTY_JS $controller_uri -modules/organize/views/organize_dialog.html.php 105 DIRTY_JS $flash_minimum_version="10.0.0" -modules/organize/views/organize_dialog.html.php 123 DIRTY_JS $swf_uri -modules/organize/views/organize_dialog.html.php 136 DIRTY_ATTR request::protocol() +modules/organize/views/organize_dialog.html.php 94 DIRTY_JS $domain +modules/organize/views/organize_dialog.html.php 95 DIRTY_JS $access_key +modules/organize/views/organize_dialog.html.php 96 DIRTY_JS request::protocol() +modules/organize/views/organize_dialog.html.php 97 DIRTY_JS $file_filter +modules/organize/views/organize_dialog.html.php 98 DIRTY_JS $sort_order +modules/organize/views/organize_dialog.html.php 99 DIRTY_JS $sort_fields +modules/organize/views/organize_dialog.html.php 100 DIRTY_JS $album->id +modules/organize/views/organize_dialog.html.php 101 DIRTY_JS $selected_id +modules/organize/views/organize_dialog.html.php 102 DIRTY_JS $rest_uri +modules/organize/views/organize_dialog.html.php 103 DIRTY_JS $controller_uri +modules/organize/views/organize_dialog.html.php 109 DIRTY_JS $flash_minimum_version="10.0.0" +modules/organize/views/organize_dialog.html.php 127 DIRTY_JS $swf_uri +modules/organize/views/organize_dialog.html.php 140 DIRTY_ATTR request::protocol() modules/recaptcha/views/admin_recaptcha.html.php 11 DIRTY $form modules/recaptcha/views/admin_recaptcha.html.php 23 DIRTY_JS $public_key modules/recaptcha/views/form_recaptcha.html.php 7 DIRTY_JS $public_key -- cgit v1.2.3 From 8ee25157ec92662f92e428b8fbbe9e03f87cb036 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 18 Sep 2010 14:29:52 -0700 Subject: Fix a bug in the way that we calculate expiration dates for old comments by using Database_Expression. Fixes ticket #1386. --- modules/comment/controllers/admin_manage_comments.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/comment/controllers/admin_manage_comments.php b/modules/comment/controllers/admin_manage_comments.php index 0889dc4e..49bd85d5 100644 --- a/modules/comment/controllers/admin_manage_comments.php +++ b/modules/comment/controllers/admin_manage_comments.php @@ -25,7 +25,7 @@ class Admin_Manage_Comments_Controller extends Admin_Controller { db::build() ->delete("comments") ->where("state", "IN", array("deleted", "spam")) - ->where("updated", "<", "UNIX_TIMESTAMP() - 86400 * 7") + ->where("updated", "<", new Database_Expression("UNIX_TIMESTAMP() - 86400 * 7")) ->execute(); // Redirect to the appropriate queue -- cgit v1.2.3 From 77ec06166320dee631bbffcf3d57b0e2debcb157 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 18 Sep 2010 15:12:43 -0700 Subject: Redirect to the root album when there's an empty path and empty id. Fixes ticket #1387. --- modules/g2_import/controllers/g2.php | 54 ++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'modules') diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php index d260c9b4..1c07c729 100644 --- a/modules/g2_import/controllers/g2.php +++ b/modules/g2_import/controllers/g2.php @@ -34,38 +34,44 @@ class G2_Controller extends Controller { $path = $input->get("path"); $id = $input->get("g2_itemId"); - if ($id) { - // Requests by id are either core.DownloadItem or core.ShowItem requests. Later versions of - // Gallery 2 don't specify g2_view if it's the default (core.ShowItem). And in some cases - // (bbcode, embedding) people are using the id style URLs although URL rewriting is enabled. - $where = array(array("g2_id", "=", $id)); - $view = $input->get("g2_view"); - if ($view) { - $where[] = array("g2_url", "like", "%g2_view=$view%"); - } // else: Assuming that the first search hit is sufficiently good. - } else if ($path) { - $where = array(array("g2_url", "=", $path)); - } else { - throw new Kohana_404_Exception(); - } + if ($path || $id) { + if ($id) { + // Requests by id are either core.DownloadItem or core.ShowItem requests. Later versions of + // Gallery 2 don't specify g2_view if it's the default (core.ShowItem). And in some cases + // (bbcode, embedding) people are using the id style URLs although URL rewriting is enabled. + $where = array(array("g2_id", "=", $id)); + $view = $input->get("g2_view"); + if ($view) { + $where[] = array("g2_url", "like", "%g2_view=$view%"); + } // else: Assuming that the first search hit is sufficiently good. + } else if ($path) { + $where = array(array("g2_url", "=", $path)); + } else { + throw new Kohana_404_Exception(); + } - $g2_map = ORM::factory("g2_map") - ->merge_where($where) - ->find(); + $g2_map = ORM::factory("g2_map") + ->merge_where($where) + ->find(); - if (!$g2_map->loaded()) { - throw new Kohana_404_Exception(); - } + if (!$g2_map->loaded()) { + throw new Kohana_404_Exception(); + } - $item = ORM::factory("item", $g2_map->g3_id); - if (!$item->loaded()) { - throw new Kohana_404_Exception(); + $item = ORM::factory("item", $g2_map->g3_id); + if (!$item->loaded()) { + throw new Kohana_404_Exception(); + } + $resource_type = $g2_map->resource_type(); + } else { + $item = item::root(); + $resource_type = "album"; } access::required("view", $item); // Redirect the user to the new url - switch ($g2_map->resource_type) { + switch ($resource_type) { case "thumbnail": url::redirect($item->thumb_url(true)); -- cgit v1.2.3 From 6bb75f623e6dbb58e873b5c7f3f2f3238abe99fd Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 18 Sep 2010 16:34:48 -0700 Subject: Fix a bug in that last commit where I was treating resource_type as a function. --- modules/g2_import/controllers/g2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php index 1c07c729..c529c147 100644 --- a/modules/g2_import/controllers/g2.php +++ b/modules/g2_import/controllers/g2.php @@ -62,7 +62,7 @@ class G2_Controller extends Controller { if (!$item->loaded()) { throw new Kohana_404_Exception(); } - $resource_type = $g2_map->resource_type(); + $resource_type = $g2_map->resource_type; } else { $item = item::root(); $resource_type = "album"; -- cgit v1.2.3 From a1b1d323af458958c9e06c8160bffb97882b8d41 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 18 Sep 2010 16:46:15 -0700 Subject: When looking for G2 urls in the g2_map, try also swapping spaces for + in case the url had spaces in it. Fixes ticket #1388. --- modules/g2_import/controllers/g2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php index c529c147..0f51173a 100644 --- a/modules/g2_import/controllers/g2.php +++ b/modules/g2_import/controllers/g2.php @@ -45,7 +45,7 @@ class G2_Controller extends Controller { $where[] = array("g2_url", "like", "%g2_view=$view%"); } // else: Assuming that the first search hit is sufficiently good. } else if ($path) { - $where = array(array("g2_url", "=", $path)); + $where = array(array("g2_url", "IN", array($path, str_replace(" ", "+", $path)))); } else { throw new Kohana_404_Exception(); } -- cgit v1.2.3 From fad1f05203f9c45b759fd0f4731e9025bca86114 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 18 Sep 2010 17:46:28 -0700 Subject: The Kohana folks removed the cache cleanup code back in http://dev.kohanaframework.org/projects/kohana2/repository/revisions/4605 So now our cache entries don't expire. For now, do cache expiration whenever we render Admin > Maintenance, since that's the type of place that users will go when they want their cache to expire anyway. --- modules/gallery/controllers/admin_maintenance.php | 7 +++++++ modules/gallery/libraries/drivers/Cache/Database.php | 14 -------------- modules/gallery/tests/Cache_Test.php | 20 -------------------- 3 files changed, 7 insertions(+), 34 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index a9cc933c..7729d797 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -48,6 +48,13 @@ class Admin_Maintenance_Controller extends Admin_Controller { $view->content->finished_tasks = ORM::factory("task") ->where("done", "=", 1)->order_by("updated", "DESC")->find_all(); print $view; + + // Do some maintenance while we're in here + db::build() + ->delete("caches") + ->where("expiration", "<>", 0) + ->where("expiration", "<=", time()) + ->execute(); } /** diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index 9ada52e1..b7822811 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -178,20 +178,6 @@ class Cache_Database_Driver extends Cache_Driver { return $this->delete($tags, true); } - /** - * Deletes all cache files that are older than the current time. - */ - public function delete_expired() { - // Delete all expired caches - $status = db::build() - ->delete("caches") - ->where("expiration", "<>", 0) - ->where("expiration", "<=", time()) - ->execute(); - - return count($status) > 0; - } - /** * Empty the cache */ diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php index 4c65698a..e8d8b6f4 100644 --- a/modules/gallery/tests/Cache_Test.php +++ b/modules/gallery/tests/Cache_Test.php @@ -85,26 +85,6 @@ class Cache_Test extends Gallery_Unit_Test_Case { $this->assert_equal(array($id3 => $value3), $data, "Expected id3"); } - public function cache_delete_expired_test() { - $id1 = md5(rand()); - $value1 = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), -84600); - - $id2 = md5(rand()); - $value2 = array("field3" => "value3", "field4" => "value4"); - $this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), -846000); - - $id3 = md5(rand()); - $value3 = array("field5" => "value5", "field6" => "value6"); - $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), -84600); - - $data = $this->_driver->delete_expired(); - - $this->assert_false($this->_driver->exists($id1), "$id1 should have been deleted"); - $this->assert_false($this->_driver->exists($id2), "$id2 should have been deleted"); - $this->assert_false($this->_driver->exists($id3), "$id3 should have been deleted"); - } - public function cache_delete_id_test() { $id1 = md5(rand()); $value1 = array("field1" => "value1", "field2" => "value2"); -- cgit v1.2.3 From 3b8475908feded1a982cf9a7e43e0dd18755c470 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 22 Sep 2010 20:55:27 -0700 Subject: Use alternate path to the CoolIris slideshow that fixes the problem with Adobe not properly signing TextLayout.swz. Fixes #1390. --- modules/slideshow/helpers/slideshow_theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/slideshow/helpers/slideshow_theme.php b/modules/slideshow/helpers/slideshow_theme.php index 3203b7bc..a3d6ef37 100644 --- a/modules/slideshow/helpers/slideshow_theme.php +++ b/modules/slideshow/helpers/slideshow_theme.php @@ -20,7 +20,7 @@ class slideshow_theme_Core { static function page_bottom($theme) { $proto = request::protocol(); - return ""; } } -- cgit v1.2.3 From 790bf4e871b1a1555dc32287ab222b6694d402a2 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 22 Sep 2010 21:35:49 -0700 Subject: Prioritize using the value in graphics_toolkit_path over the standard path so that if you change that value in Admin > Settings > Advanced we prefer it over other paths (which may be restricted by open_basedir). Fixes #1395. --- modules/gallery/helpers/gallery.php | 13 +++++++++++++ modules/gallery/helpers/graphics.php | 9 ++++----- modules/gallery/helpers/movie.php | 9 ++++----- 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index ca8c92c9..3cf0eacd 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -140,4 +140,17 @@ class gallery_Core { return $file_name; } + /** + * Set the PATH environment variable to the paths specified. + * @param array Array of paths. Each array entry can contain a colon separated list of paths. + */ + static function set_path_env($paths) { + $path_env = array(); + foreach ($paths as $path) { + if ($path) { + array_push($path_env, $path); + } + } + putenv("PATH=" . implode(":", $path_env)); + } } \ No newline at end of file diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 2868a28d..dd521d84 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -313,11 +313,10 @@ class graphics_Core { $toolkits->graphicsmagick->installed = false; $toolkits->graphicsmagick->error = t("GraphicsMagick requires the exec function"); } else { - $graphics_path = module::get_var("gallery", "graphics_toolkit_path", null); - $extra_binary_paths = module::get_var("gallery", "extra_binary_paths", null); - - putenv("PATH=" . getenv("PATH") . (empty($graphics_path) ? "" : ":$graphics_path") . - ":" . $extra_binary_paths); + gallery::set_path_env( + array(module::get_var("gallery", "graphics_toolkit_path"), + getenv("PATH"), + module::get_var("gallery", "extra_binary_paths"))); // @todo: consider refactoring the two segments below into a loop since they are so // similar. diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 50339541..78358b6b 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -85,11 +85,10 @@ class movie_Core { static function find_ffmpeg() { if (!($ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) || !file_exists($ffmpeg_path)) { - $graphics_path = module::get_var("gallery", "graphics_toolkit_path", null); - $extra_binary_paths = module::get_var("gallery", "extra_binary_paths", null); - - putenv("PATH=" . getenv("PATH") . (empty($graphics_path) ? "" : ":$graphics_path") . - ":" . $extra_binary_paths); + gallery::set_path_env( + array(module::get_var("gallery", "graphics_toolkit_path"), + getenv("PATH"), + module::get_var("gallery", "extra_binary_paths"))); if (function_exists("exec")) { $ffmpeg_path = exec("which ffmpeg"); } -- cgit v1.2.3 From 7116f820ca2b6338abdca233a4b1d42d29a41150 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 22 Sep 2010 21:43:44 -0700 Subject: Remove the 4 character minimum for group name length. Fixes ticket #1396. --- modules/user/controllers/admin_users.php | 8 +++----- modules/user/models/group.php | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index c22fcc2e..23032ab3 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -381,8 +381,8 @@ class Admin_Users_Controller extends Admin_Controller { $form_group->inputs["name"]->error_messages("conflict", t("There is already a group with that name")) ->error_messages("required", t("You must enter a group name")) ->error_messages("length", - t("The group name must be between %min_length and %max_length characters", - array("min_length" => 4, "max_length" => 255))); + t("The group name must be less than %max_length characters", + array("max_length" => 255))); $form_group->submit("")->value(t("Save")); return $form; } @@ -392,9 +392,7 @@ class Admin_Users_Controller extends Admin_Controller { $form_group = $form->group("add_group")->label(t("Add group")); $form_group->input("name")->label(t("Name"))->id("g-name"); $form_group->inputs["name"]->error_messages("conflict", t("There is already a group with that name")) - ->error_messages("required", t("You must enter a group name")) - ->error_messages("length", t("The group name must be at least %min_length characters", - array("min_length" => 4))); + ->error_messages("required", t("You must enter a group name")); $form_group->submit("")->value(t("Add group")); return $form; } diff --git a/modules/user/models/group.php b/modules/user/models/group.php index 57b12963..b27c7250 100644 --- a/modules/user/models/group.php +++ b/modules/user/models/group.php @@ -41,7 +41,7 @@ class Group_Model extends ORM implements Group_Definition { // validate() is recursive, only modify the rules on the outermost call. if (!$array) { $this->rules = array( - "name" => array("rules" => array("required", "length[4,255]"), + "name" => array("rules" => array("required", "length[1,255]"), "callbacks" => array(array($this, "valid_name")))); } -- cgit v1.2.3 From 85637a08265cbfef3cc615724b22195439f5afa5 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 23 Sep 2010 20:45:27 -0700 Subject: Fix a bug introduced recently in f84c4a6192ea0e47ca5b2006baa0bfd7e09a682c where we were generating bad SQL. If we're checking for a conflict on a new item, the id is null and we were doing a comparison that resulted in "id <> NULL" which won't work -- in that case we need "id IS NOT NULL". Fixes #1393. --- modules/gallery/models/item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 7bcf1f31..07f781d1 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -498,7 +498,7 @@ class Item_Model_Core extends ORM_MPTT { $base_slug = $this->slug; while (ORM::factory("item") ->where("parent_id", "=", $this->parent_id) - ->where("id", "<>", $this->id) + ->where("id", $this->id ? "<>" : "IS NOT", $this->id) ->and_open() ->where("name", "=", $this->name) ->or_where("slug", "=", $this->slug) -- cgit v1.2.3 From ef8751468b998baddbc6d5827a392ed6e12e5548 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 25 Sep 2010 13:27:35 -0700 Subject: Base64 encode the data result if the encoding param is set to "base64". Fixes #1400. --- modules/gallery/helpers/data_rest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/helpers/data_rest.php b/modules/gallery/helpers/data_rest.php index 98c98894..791de9c0 100644 --- a/modules/gallery/helpers/data_rest.php +++ b/modules/gallery/helpers/data_rest.php @@ -72,7 +72,12 @@ class data_rest_Core { header("Content-Type: {$item->mime_type}"); } Kohana::close_buffers(false); - readfile($file); + + if (isset($p->encoding) && $p->encoding == "base64") { + print base64_encode(file_get_contents($file)); + } else { + readfile($file); + } // We must exit here to keep the regular REST framework reply code from adding more bytes on // at the end or tinkering with headers. -- cgit v1.2.3 From f84782d6200efb424731c93bd029c7cbeb9f3dad Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 29 Sep 2010 20:47:43 -0700 Subject: Stop caching all module variables in the vars table using the name=_cache row. If that overflows, it will cause us to be unable to load variables, and we can't recover from that. Instead, use the Cache table. Bump the gallery module to v40. Fixes ticket #1405. --- modules/gallery/controllers/packager.php | 5 -- modules/gallery/helpers/gallery_installer.php | 7 ++- modules/gallery/helpers/module.php | 55 ++++------------------ modules/gallery/module.info | 2 +- .../gallery/views/admin_advanced_settings.html.php | 1 - 5 files changed, 15 insertions(+), 55 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php index f463d0de..bd51b93c 100644 --- a/modules/gallery/controllers/packager.php +++ b/modules/gallery/controllers/packager.php @@ -81,11 +81,6 @@ class Packager_Controller extends Controller { Database::instance()->query("TRUNCATE {caches}"); Database::instance()->query("TRUNCATE {sessions}"); Database::instance()->query("TRUNCATE {logs}"); - db::build() - ->delete("vars") - ->where("module_name", "=", "gallery") - ->where("name", "=", "_cache") - ->execute(); db::build()->update("users") ->set(array("password" => "")) ->where("id", "in", array(1, 2)) diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 83961d6b..3d82bc69 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -309,7 +309,7 @@ class gallery_installer { module::set_var("gallery", "show_user_profiles_to", "registered_users"); module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin"); - module::set_version("gallery", 40); + module::set_version("gallery", 41); } static function upgrade($version) { @@ -637,6 +637,11 @@ class gallery_installer { module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin"); module::set_version("gallery", $version = 40); } + + if ($version == 40) { + module::clear_var("gallery", "_cache"); + module::set_version("gallery", $version = 41); + } } static function uninstall() { diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 7863520e..64d0d1d6 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -425,48 +425,21 @@ class module_Core { * @return the value */ static function get_var($module_name, $name, $default_value=null) { - // We cache all vars in gallery._cache so that we can load all vars at once for - // performance. + // We cache vars so we can load them all at once for performance. if (empty(self::$var_cache)) { - $row = db::build() - ->select("value") - ->from("vars") - ->where("module_name", "=", "gallery") - ->where("name", "=", "_cache") - ->execute() - ->current(); - if ($row) { - self::$var_cache = unserialize($row->value); - } else { - // gallery._cache doesn't exist. Create it now. + self::$var_cache = Cache::instance()->get("var_cache"); + if (empty(self::$var_cache)) { + // Cache doesn't exist, create it now. foreach (db::build() ->select("module_name", "name", "value") ->from("vars") ->order_by("module_name") ->order_by("name") ->execute() as $row) { - if ($row->module_name == "gallery" && $row->name == "_cache") { - // This could happen if there's a race condition - continue; - } // Mute the "Creating default object from empty value" warning below @self::$var_cache->{$row->module_name}->{$row->name} = $row->value; } - $cache = ORM::factory("var"); - $cache->module_name = "gallery"; - $cache->name = "_cache"; - $cache->value = serialize(self::$var_cache); - try { - $cache->save(); - } catch (Database_Exception $e) { - // There's a potential race condition here. Don't fail if that happens because it's - // bound to be transient and not a huge deal, but at least put something in the logs. - if (stristr($e->getMessage(), "duplicate entry")) { - Kohana_Log::add("error", "Failed to cache vars"); - } else { - throw $e; - } - } + Cache::instance()->set("var_cache", self::$var_cache, array("vars")); } } @@ -495,11 +468,7 @@ class module_Core { $var->value = $value; $var->save(); - db::build() - ->delete("vars") - ->where("module_name", "=", "gallery") - ->where("name", "=", "_cache") - ->execute(); + Cache::instance()->delete("var_cache"); self::$var_cache = null; } @@ -524,11 +493,7 @@ class module_Core { ->where("name", "=", $name) ->execute(); - db::build() - ->delete("vars") - ->where("module_name", "=", "gallery") - ->where("name", "=", "_cache") - ->execute(); + Cache::instance()->delete("var_cache"); self::$var_cache = null; } @@ -546,11 +511,7 @@ class module_Core { $var->delete(); } - db::build() - ->delete("vars") - ->where("module_name", "=", "gallery") - ->where("name", "=", "_cache") - ->execute(); + Cache::instance()->delete("var_cache"); self::$var_cache = null; } diff --git a/modules/gallery/module.info b/modules/gallery/module.info index 1155ddf7..2b684e5e 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = "Gallery 3" description = "Gallery core application" -version = 40 +version = 41 diff --git a/modules/gallery/views/admin_advanced_settings.html.php b/modules/gallery/views/admin_advanced_settings.html.php index 1f7d2f64..edaeecaf 100644 --- a/modules/gallery/views/admin_advanced_settings.html.php +++ b/modules/gallery/views/admin_advanced_settings.html.php @@ -17,7 +17,6 @@ - module_name == "gallery" && $var->name == "_cache") continue ?> "> module_name ?> name) ?> -- cgit v1.2.3 From 86981c5afb980f744103af8b2e9a229e745d98fb Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 1 Oct 2010 21:09:14 -0700 Subject: Use the "loading" image from themes/wind since it's no longer in gallery3/lib. --- modules/gallery/views/upgrader.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/views/upgrader.html.php b/modules/gallery/views/upgrader.html.php index 1ec49c77..ad2e3421 100644 --- a/modules/gallery/views/upgrader.html.php +++ b/modules/gallery/views/upgrader.html.php @@ -17,7 +17,7 @@