From 90ef5daa49a2c9718ac508d74e752dde48153571 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 25 Dec 2009 13:25:36 -0800 Subject: [PATCH] Update some database calls. --- .../gwtorganise/controllers/json_album.php | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/modules/gwtorganise/controllers/json_album.php b/modules/gwtorganise/controllers/json_album.php index 70743e3d..85cf1128 100644 --- a/modules/gwtorganise/controllers/json_album.php +++ b/modules/gwtorganise/controllers/json_album.php @@ -102,7 +102,11 @@ class Json_Album_Controller extends Controller { $i = 0; foreach ($album->children() as $child) { // Do this directly in the database to avoid sending notifications - Database::Instance()->update("items", array("weight" => ++$i), array("id" => $child->id)); + db::build() + ->update("items") + ->set("weight", ++$i) + ->where("id", "=", $child->id) + ->execute(); } $album->sort_column = "weight"; $album->sort_order = "ASC"; @@ -118,15 +122,20 @@ class Json_Album_Controller extends Controller { // Make a hole $count = count($source_ids); - Database::Instance()->query( - "UPDATE {items} " . - "SET `weight` = `weight` + $count " . - "WHERE `weight` >= $target_weight AND `parent_id` = {$album->id}"); + db::build() + ->update("items") + ->set("weight", new Database_Expression("`weight` + $count")) + ->where("weight", ">=", $target_weight) + ->where("parent_id", "=", $album->id) + ->execute(); // Insert source items into the hole foreach ($source_ids as $source_id) { - Database::Instance()->update( - "items", array("weight" => $target_weight++), array("id" => $source_id)); + db::build() + ->update("items") + ->set("weight", $target_weight++) + ->where("id", "=", $source_id) + ->execute(); } module::event("album_rearrange", $album);