From 1fd0e14359a7c7164573e4aa897c07680339e713 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 12:09:04 -0800 Subject: Convert all DB where() calls to take 3 arguments. Convert all open_paren() calls to and_open() or or_open() as appropriate. --- modules/gallery/helpers/gallery_event.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'modules/gallery/helpers/gallery_event.php') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 02bfdf28..fa4db317 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -33,15 +33,15 @@ class gallery_event_Core { $db = Database::instance(); $db->from("tasks") ->set(array("owner_id" => $admin->id)) - ->where(array("owner_id" => $user->id)) + ->where("owner_id", "=", $user->id) ->update(); $db->from("items") ->set(array("owner_id" => $admin->id)) - ->where(array("owner_id" => $user->id)) + ->where("owner_id", "=", $user->id) ->update(); $db->from("logs") ->set(array("user_id" => $admin->id)) - ->where(array("user_id" => $user->id)) + ->where("user_id", "=", $user->id) ->update(); } @@ -50,15 +50,15 @@ class gallery_event_Core { $db = Database::instance(); $db->from("tasks") ->set(array("owner_id" => $admin->id)) - ->where("1 = 1") + ->where("1", "=", "1") // @todo why do we need this? ->update(); $db->from("items") ->set(array("owner_id" => $admin->id)) - ->where("1 = 1") + ->where("1", "=", "1") // @todo why do we need this? ->update(); $db->from("logs") ->set(array("user_id" => $admin->id)) - ->where("1 = 1") + ->where("1", "=", "1") // @todo why do we need this? ->update(); } -- cgit v1.2.3 From dec084fe08db1505d272e6a577b8627f57abef16 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:34:09 -0800 Subject: Update database queries. --- modules/gallery/helpers/gallery_event.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'modules/gallery/helpers/gallery_event.php') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index fa4db317..37f39d15 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -30,19 +30,21 @@ class gallery_event_Core { static function user_deleted($user) { $admin = identity::admin_user(); - $db = Database::instance(); - $db->from("tasks") - ->set(array("owner_id" => $admin->id)) + db::build() + ->update("tasks") + ->set("owner_id", $admin->id) ->where("owner_id", "=", $user->id) - ->update(); - $db->from("items") - ->set(array("owner_id" => $admin->id)) + ->execute(); + db::build() + ->update("items") + ->set("owner_id", $admin->id) ->where("owner_id", "=", $user->id) - ->update(); - $db->from("logs") - ->set(array("user_id" => $admin->id)) + ->execute(); + db::build() + ->update("logs") + ->set("user_id", $admin->id) ->where("user_id", "=", $user->id) - ->update(); + ->execute(); } static function identity_provider_changed($old_provider, $new_provider) { -- cgit v1.2.3 From 9d19e272d672ffc224dfed2799f8e480ecb583e4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 17 Dec 2009 21:16:51 -0800 Subject: Convert some database queries. --- modules/gallery/helpers/gallery_event.php | 25 ++++++++++++------------- modules/gallery/helpers/module.php | 23 ++++++++++++++++++----- 2 files changed, 30 insertions(+), 18 deletions(-) (limited to 'modules/gallery/helpers/gallery_event.php') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 37f39d15..301432d4 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -49,19 +49,18 @@ class gallery_event_Core { static function identity_provider_changed($old_provider, $new_provider) { $admin = identity::admin_user(); - $db = Database::instance(); - $db->from("tasks") - ->set(array("owner_id" => $admin->id)) - ->where("1", "=", "1") // @todo why do we need this? - ->update(); - $db->from("items") - ->set(array("owner_id" => $admin->id)) - ->where("1", "=", "1") // @todo why do we need this? - ->update(); - $db->from("logs") - ->set(array("user_id" => $admin->id)) - ->where("1", "=", "1") // @todo why do we need this? - ->update(); + db::build() + ->update("tasks") + ->set("owner_id", $admin->id) + ->execute(); + db::build() + ->update("items") + ->set("owner_id", $admin->id) + ->execute(); + db::build() + ->update("logs") + ->set("user_id", $admin->id) + ->execute(); } static function group_created($group) { diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index b8928f7b..71c4efa0 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -432,17 +432,30 @@ class module_Core { /** * Increment the value of a variable for this module + * + * Note: Frequently updating counters is very inefficient because it invalidates the cache value + * which has to be rebuilt every time we make a change. + * + * @todo Get rid of this and find an alternate approach for all callers (currently only Akismet) + * + * @deprecated * @param string $module_name * @param string $name * @param string $increment (optional, default is 1) */ static function incr_var($module_name, $name, $increment=1) { - Database::instance()->query( - "UPDATE {vars} SET `value` = `value` + $increment " . - "WHERE `module_name` = '$module_name' " . - "AND `name` = '$name'"); + db::build() + ->update("vars") + ->set("value", new Database_Expression("`value` + $increment")) + ->where("module_name", "=", $module_name) + ->where("name", "=", $name) + ->execute(); - Database::instance()->delete("vars", array("module_name" => "gallery", "name" => "_cache")); + db::build() + ->delete("vars") + ->where("module_name", "=", "gallery") + ->where("name", "=", "_cache") + ->execute(); self::$var_cache = null; } -- cgit v1.2.3 From 41969cc9e454637f6e3a04b0e339942cbb140cf6 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 29 Dec 2009 15:48:21 -0800 Subject: Another holdover from the K2.4 conversion. In R2.4 the url::current(true) was returning an empty string. This fixes ticket #955. --- modules/gallery/helpers/gallery_event.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/gallery/helpers/gallery_event.php') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 301432d4..0303c9cb 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -109,6 +109,7 @@ class gallery_event_Core { ->label(t("Login"))); } else { $csrf = access::csrf_token(); + $item = $theme->item(); $menu->append(Menu::factory("dialog") ->id("user_menu_edit_profile") ->css_id("g-user-profile-link") @@ -119,7 +120,7 @@ class gallery_event_Core { ->id("user_menu_logout") ->css_id("g-logout-link") ->url(url::site("logout?csrf=$csrf&continue=" . - urlencode(url::current(true)))) + urlencode($item->url()))) ->label(t("Logout"))); } } -- cgit v1.2.3 From 20bd09ff004816ae152a2f890a24dc5e85741fac Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 31 Dec 2009 17:21:19 -0800 Subject: A more thorough fix for #745 and #940. Stop using the referer to guess how to send the user back. Instead, proxy the originating item id through the edit forms so that we can tell exactly what page we were on when we began editing. If we were viewing the item, then redirect to its new url (in case it changed) to fix ticket #745. But if we were viewing some other item, then just stay on the current page to fix #940. The page_type approach didn't work because you'd have the same "collection" page_type when doing a context menu edit for an album. --- modules/gallery/controllers/albums.php | 12 +++++++----- modules/gallery/controllers/movies.php | 10 ++++++++-- modules/gallery/controllers/photos.php | 15 ++++++++------- modules/gallery/controllers/quick.php | 14 +++++++++++--- modules/gallery/helpers/album.php | 1 + modules/gallery/helpers/gallery_event.php | 13 ++++++------- modules/gallery/helpers/movie.php | 1 + modules/gallery/helpers/photo.php | 1 + 8 files changed, 43 insertions(+), 24 deletions(-) (limited to 'modules/gallery/helpers/gallery_event.php') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 2134a419..2eeefdf1 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -157,8 +157,6 @@ class Albums_Controller extends Items_Controller { } if ($valid) { - $watching_album = $album->url() != ($location = parse_url(request::referrer(), PHP_URL_PATH)); - $album->title = $form->edit_item->title->value; $album->description = $form->edit_item->description->value; $album->sort_column = $form->edit_item->sort_order->column->value; @@ -174,9 +172,13 @@ class Albums_Controller extends Items_Controller { message::success(t("Saved album %album_title", array("album_title" => html::purify($album->title)))); - print json_encode( - array("result" => "success", - "location" => $watching_album ? $location : $album->url())); + if ($form->from_id->value == $album->id) { + // Use the new url; it might have changed. + print json_encode(array("result" => "success", "location" => $album->url())); + } else { + // Stay on the same page + print json_encode(array("result" => "success")); + } } else { print json_encode( array("result" => "error", diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index b5785ecf..7a8e4d2a 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -110,8 +110,13 @@ class Movies_Controller extends Items_Controller { message::success( t("Saved movie %movie_title", array("movie_title" => $movie->title))); - print json_encode( - array("result" => "success")); + if ($form->from_id->value == $movie->id) { + // Use the new url; it might have changed. + print json_encode(array("result" => "success", "location" => $movie->url())); + } else { + // Stay on the same page + print json_encode(array("result" => "success")); + } } else { print json_encode( array("result" => "error", @@ -123,6 +128,7 @@ class Movies_Controller extends Items_Controller { $movie = ORM::factory("item", $movie_id); access::required("view", $movie); access::required("edit", $movie); + print movie::get_edit_form($movie); } } diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index ced9da2f..56b454ce 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -99,8 +99,6 @@ class Photos_Controller extends Items_Controller { } if ($valid) { - $watching_album = $photo->url() != ($location = parse_url(request::referrer(), PHP_URL_PATH)); - $photo->title = $form->edit_item->title->value; $photo->description = $form->edit_item->description->value; $photo->slug = $form->edit_item->slug->value; @@ -110,12 +108,15 @@ class Photos_Controller extends Items_Controller { log::success("content", "Updated photo", "url()}\">view"); message::success( - t("Saved photo %photo_title", - array("photo_title" => html::purify($photo->title)))); + t("Saved photo %photo_title", array("photo_title" => html::purify($photo->title)))); - print json_encode( - array("result" => "success", - "location" => $watching_album ? $location : $photo->url())); + if ($form->from_id->value == $photo->id) { + // Use the new url; it might have changed. + print json_encode(array("result" => "success", "location" => $photo->url())); + } else { + // Stay on the same page + print json_encode(array("result" => "success")); + } } else { print json_encode( array("result" => "error", diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php index 7f1ad43b..7f9a9826 100644 --- a/modules/gallery/controllers/quick.php +++ b/modules/gallery/controllers/quick.php @@ -133,13 +133,21 @@ class Quick_Controller extends Controller { switch ($item->type) { case "album": - return print album::get_edit_form($item); + $form = album::get_edit_form($item); + break; case "photo": - return print photo::get_edit_form($item); + $form = photo::get_edit_form($item); + break; case "movie": - return print movie::get_edit_form($item); + $form = movie::get_edit_form($item); + break; } + + // Pass on the source item where this form was generated, so we have an idea where to return to. + $form->hidden("from_id")->value((int)Input::instance()->get("from_id", 0)); + + print $form; } } diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index da42bf28..feaf74cc 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -115,6 +115,7 @@ class album_Core { static function get_edit_form($parent) { $form = new Forge("albums/update/{$parent->id}", "", "post", array("id" => "g-edit-album-form")); + $form->hidden("from_id"); $group = $form->group("edit_item")->label(t("Edit Album")); $group->input("title")->label(t("Title"))->value($parent->title); diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 0303c9cb..5565850d 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -272,8 +272,6 @@ class gallery_event_Core { ->css_class("ui-icon-carat-1-n")); if (access::can("edit", $item)) { - $page_type = $theme->page_type(); - $page_subtype = $theme->page_subtype(); switch ($item->type) { case "movie": $edit_title = t("Edit this movie"); @@ -295,11 +293,12 @@ class gallery_event_Core { $csrf = access::csrf_token(); + $theme_item = $theme->item(); $options_menu->append(Menu::factory("dialog") ->id("edit") ->label($edit_title) ->css_class("ui-icon-pencil") - ->url(url::site("quick/form_edit/$item->id?page_type=$page_type"))); + ->url(url::site("quick/form_edit/$item->id?from_id=$theme_item->id"))); if ($item->is_photo() && graphics::can("rotate")) { $options_menu @@ -310,7 +309,7 @@ class gallery_event_Core { ->css_class("ui-icon-rotate-ccw") ->ajax_handler("function(data) { " . "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }") - ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&page_type=$page_type"))) + ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&from_id=$theme_item->id"))) ->append( Menu::factory("ajax_link") ->id("rotate_cw") @@ -318,12 +317,12 @@ class gallery_event_Core { ->css_class("ui-icon-rotate-cw") ->ajax_handler("function(data) { " . "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }") - ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&page_type=$page_type"))); + ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&from_id=$theme_item->id"))); } // @todo Don't move photos from the photo page; we don't yet have a good way of redirecting // after move - if ($page_subtype == "album") { + if ($theme->page_subtype() == "album") { $options_menu ->append(Menu::factory("dialog") ->id("move") @@ -358,7 +357,7 @@ class gallery_event_Core { ->label($delete_title) ->css_class("ui-icon-trash") ->css_id("g-quick-delete") - ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&page_type=$page_type"))); + ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&from_id=$theme_item->id"))); } if ($item->is_album()) { diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 60059c61..01859924 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -130,6 +130,7 @@ class movie_Core { static function get_edit_form($movie) { $form = new Forge("movies/update/$movie->id", "", "post", array("id" => "g-edit-movie-form")); + $form->hidden("from_id"); $group = $form->group("edit_item")->label(t("Edit Movie")); $group->input("title")->label(t("Title"))->value($movie->title); $group->textarea("description")->label(t("Description"))->value($movie->description); diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index ceffac65..4e20e610 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -139,6 +139,7 @@ class photo_Core { static function get_edit_form($photo) { $form = new Forge("photos/update/$photo->id", "", "post", array("id" => "g-edit-photo-form")); + $form->hidden("from_id"); $group = $form->group("edit_item")->label(t("Edit Photo")); $group->input("title")->label(t("Title"))->value($photo->title); $group->textarea("description")->label(t("Description"))->value($photo->description); -- cgit v1.2.3