From 2e420522ece22942a9b3b6ee413ca0e1dfa76148 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 13:22:24 -0800 Subject: Preliminary work to cut over to Kohana 2.4 - Kohana::log() -> Kohana_Log::add() - Kohana::config_XXX -> Kohana_Config::instance()->XXX - Implement View::set_global in MY_View - Updated Cache_Database_Driver to latest APIs - ORM::$loaded -> ORM::loaded() - Updated item::viewable() to use K2.4 parenthesization --- modules/gallery/helpers/item.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'modules/gallery/helpers/item.php') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 8f96c3d9..109fa6f8 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -156,13 +156,7 @@ class item_Core { $view_restrictions = array(); if (!identity::active_user()->admin) { foreach (identity::group_ids_for_active_user() as $id) { - // Separate the first restriction from the rest to make it easier for us to formulate - // our where clause below - if (empty($view_restrictions)) { - $view_restrictions[0] = "items.view_$id"; - } else { - $view_restrictions[1]["items.view_$id"] = access::ALLOW; - } + $view_restrictions[] = "items.view_$id"; } } switch (count($view_restrictions)) { @@ -170,14 +164,14 @@ class item_Core { break; case 1: - $model->where($view_restrictions[0], access::ALLOW); + $model->where($view_restrictions[0], "=", access::ALLOW); break; default: - $model->open_paren(); - $model->where($view_restrictions[0], access::ALLOW); - $model->orwhere($view_restrictions[1]); - $model->close_paren(); + $model + ->and_open() + ->or_where($view_restrictions, "=", access::ALLOW) + ->close(); break; } -- cgit v1.2.3 From 0121bfd5850bdc59bf0cd656c61c953421a85890 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 19:26:52 -0800 Subject: ORM::orderby -> ORM::order_by --- modules/comment/controllers/admin_comments.php | 2 +- modules/comment/helpers/comment_block.php | 2 +- modules/comment/helpers/comment_rss.php | 2 +- modules/comment/helpers/comment_theme.php | 2 +- .../controllers/admin_advanced_settings.php | 2 +- modules/gallery/controllers/admin_maintenance.php | 4 +-- modules/gallery/helpers/access.php | 10 +++---- modules/gallery/helpers/gallery_block.php | 4 +-- modules/gallery/helpers/gallery_rss.php | 4 +-- modules/gallery/helpers/graphics.php | 2 +- modules/gallery/helpers/item.php | 2 +- modules/gallery/helpers/module.php | 2 +- modules/gallery/models/item.php | 32 +++++++++++----------- modules/server_add/controllers/server_add.php | 2 +- modules/tag/controllers/admin_tags.php | 2 +- modules/tag/controllers/tags.php | 2 +- modules/user/controllers/admin_users.php | 4 +-- 17 files changed, 40 insertions(+), 40 deletions(-) (limited to 'modules/gallery/helpers/item.php') diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php index 1a9f0e6a..039956d7 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -48,7 +48,7 @@ class Admin_Comments_Controller extends Admin_Controller { $view->content->menu = $this->_menu($view->content->counts); $view->content->state = $state; $view->content->comments = ORM::factory("comment") - ->orderby("created", "DESC") + ->order_by("created", "DESC") ->where("state", $state) ->limit(self::$items_per_page, ($page - 1) * self::$items_per_page) ->find_all(); diff --git a/modules/comment/helpers/comment_block.php b/modules/comment/helpers/comment_block.php index 7cd5d429..ab86b90a 100644 --- a/modules/comment/helpers/comment_block.php +++ b/modules/comment/helpers/comment_block.php @@ -30,7 +30,7 @@ class comment_block_Core { $block->title = t("Recent comments"); $block->content = new View("admin_block_recent_comments.html"); $block->content->comments = - ORM::factory("comment")->orderby("created", "DESC")->limit(5)->find_all(); + ORM::factory("comment")->order_by("created", "DESC")->limit(5)->find_all(); break; } diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php index 3692a30d..d0bb7859 100644 --- a/modules/comment/helpers/comment_rss.php +++ b/modules/comment/helpers/comment_rss.php @@ -36,7 +36,7 @@ class comment_rss_Core { $comments = ORM::factory("comment") ->viewable() ->where("state", "published") - ->orderby("created", "DESC"); + ->order_by("created", "DESC"); if ($feed_id == "item") { $comments->where("item_id", $id); diff --git a/modules/comment/helpers/comment_theme.php b/modules/comment/helpers/comment_theme.php index af0e1ca4..2f12192b 100644 --- a/modules/comment/helpers/comment_theme.php +++ b/modules/comment/helpers/comment_theme.php @@ -39,7 +39,7 @@ class comment_theme_Core { $view->comments = ORM::factory("comment") ->where("item_id", $theme->item()->id) ->where("state", "published") - ->orderby("created", "ASC") + ->order_by("created", "ASC") ->find_all(); $block->content = $view; diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php index 79bc1183..c9de7e57 100644 --- a/modules/gallery/controllers/admin_advanced_settings.php +++ b/modules/gallery/controllers/admin_advanced_settings.php @@ -22,7 +22,7 @@ class Admin_Advanced_Settings_Controller extends Admin_Controller { $view = new Admin_View("admin.html"); $view->content = new View("admin_advanced_settings.html"); $view->content->vars = ORM::factory("var") - ->orderby("module_name", "name") + ->order_by("module_name", "name") ->find_all(); print $view; } diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index fe5059e7..3b896553 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -41,9 +41,9 @@ class Admin_Maintenance_Controller extends Admin_Controller { $view->content = new View("admin_maintenance.html"); $view->content->task_definitions = task::get_definitions(); $view->content->running_tasks = ORM::factory("task") - ->where("done", 0)->orderby("updated", "DESC")->find_all(); + ->where("done", 0)->order_by("updated", "DESC")->find_all(); $view->content->finished_tasks = ORM::factory("task") - ->where("done", 1)->orderby("updated", "DESC")->find_all(); + ->where("done", 1)->order_by("updated", "DESC")->find_all(); print $view; } diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index 9d27181a..d0200a73 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -171,7 +171,7 @@ class access_Core { ->where("items.id <> $item->id") ->join("access_intents", "items.id", "access_intents.item_id") ->where("access_intents.view_$group->id", self::DENY) - ->orderby("level", "DESC") + ->order_by("level", "DESC") ->limit(1) ->find(); @@ -494,7 +494,7 @@ class access_Core { ->where("right_ptr >", $item->right_ptr) ->join("access_intents", "access_intents.item_id", "items.id") ->where("access_intents.$field", self::DENY) - ->orderby("left_ptr", "DESC") + ->order_by("left_ptr", "DESC") ->limit(1) ->find(); if ($tmp_item->loaded()) { @@ -516,7 +516,7 @@ class access_Core { ->where("right_ptr <=", $item->right_ptr) ->where("type", "album") ->where("access_intents.$field IS NOT", self::INHERIT) - ->orderby("level", "DESC") + ->order_by("level", "DESC") ->find_all(); foreach ($query as $row) { if ($row->$field == self::ALLOW) { @@ -565,7 +565,7 @@ class access_Core { ->where("left_ptr <", $item->left_ptr) ->where("right_ptr >", $item->right_ptr) ->where("$field IS NOT", self::UNKNOWN) - ->orderby("left_ptr", "DESC") + ->order_by("left_ptr", "DESC") ->limit(1) ->find(); if ($tmp_item->loaded()) { @@ -581,7 +581,7 @@ class access_Core { ->where("left_ptr >=", $item->left_ptr) ->where("right_ptr <=", $item->right_ptr) ->where("$field IS NOT", self::INHERIT) - ->orderby("level", "ASC") + ->order_by("level", "ASC") ->find_all(); foreach ($query as $row) { $value = ($row->$field === self::ALLOW) ? "TRUE" : "FALSE"; diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index b5c32ad2..d09f1c80 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -46,7 +46,7 @@ class gallery_block_Core { $block->title = t("Photo stream"); $block->content = new View("admin_block_photo_stream.html"); $block->content->photos = - ORM::factory("item")->where("type", "photo")->orderby("created", "DESC")->find_all(10); + ORM::factory("item")->where("type", "photo")->order_by("created", "DESC")->find_all(10); break; case "log_entries": @@ -54,7 +54,7 @@ class gallery_block_Core { $block->title = t("Log entries"); $block->content = new View("admin_block_log_entries.html"); $block->content->entries = ORM::factory("log") - ->orderby(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5); + ->order_by(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5); break; case "stats": diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index 155edfb5..e195be8d 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -30,13 +30,13 @@ class gallery_rss_Core { $feed->children = ORM::factory("item") ->viewable() ->where("type !=", "album") - ->orderby("created", "DESC") + ->order_by("created", "DESC") ->find_all($limit, $offset); $all_children = ORM::factory("item") ->viewable() ->where("type !=", "album") - ->orderby("created", "DESC"); + ->order_by("created", "DESC"); $feed->max_pages = ceil($all_children->find_all()->count() / $limit); $feed->title = t("Recent updates"); diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index a78cadd0..aef09003 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -183,7 +183,7 @@ class graphics_Core { foreach (ORM::factory("graphics_rule") ->where("target", $target) ->where("active", true) - ->orderby("priority", "asc") + ->order_by("priority", "asc") ->find_all() as $rule) { $rules[] = (object)$rule->as_array(); } diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 109fa6f8..7496d368 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -142,7 +142,7 @@ class item_Core { // @todo: figure out a better way to bootstrap the weight. $result = Database::instance() ->select("weight")->from("items") - ->orderby("weight", "desc")->limit(1) + ->order_by("weight", "desc")->limit(1) ->get()->current(); return ($result ? $result->weight : 0) + 1; } diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index e54a4352..b7e13b9a 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -364,7 +364,7 @@ class module_Core { foreach (Database::instance() ->select("module_name", "name", "value") ->from("vars") - ->orderby("module_name", "name") + ->order_by("module_name", "name") ->get() as $row) { if ($row->module_name == "gallery" && $row->name == "_cache") { // This could happen if there's a race condition diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index bd1f9af5..1efac37f 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -291,7 +291,7 @@ class Item_Model extends ORM_MPTT { ->where("left_ptr <=", $this->left_ptr) ->where("right_ptr >=", $this->right_ptr) ->where("id <>", 1) - ->orderby("left_ptr", "ASC") + ->order_by("left_ptr", "ASC") ->get() as $row) { // Don't encode the names segment $names[] = rawurlencode($row->name); @@ -460,7 +460,7 @@ class Item_Model extends ORM_MPTT { ->where("parent_id", $this->id) ->where($sort_column, $child->$sort_column) ->where($where) - ->orderby(array("id" => "ASC")) + ->order_by(array("id" => "ASC")) ->get() as $row) { $position++; if ($row->id == $child->id) { @@ -475,10 +475,10 @@ class Item_Model extends ORM_MPTT { // // Reproduce the children() functionality here using Database directly to avoid loading the // whole ORM for each row. - $orderby = array($this->sort_column => $this->sort_order); + $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker if ($this->sort_column != "id") { - $orderby["id"] = "ASC"; + $order_by["id"] = "ASC"; } $position = 0; @@ -486,7 +486,7 @@ class Item_Model extends ORM_MPTT { ->from("items") ->where("parent_id", $this->id) ->where($where) - ->orderby($orderby) + ->order_by($order_by) ->get() as $row) { $position++; if ($row->id == $child->id) { @@ -592,18 +592,18 @@ class Item_Model extends ORM_MPTT { * @param integer SQL limit * @param integer SQL offset * @param array additional where clauses - * @param array orderby + * @param array order_by * @return array ORM */ - function children($limit=null, $offset=0, $where=array(), $orderby=null) { - if (empty($orderby)) { - $orderby = array($this->sort_column => $this->sort_order); + function children($limit=null, $offset=0, $where=array(), $order_by=null) { + if (empty($order_by)) { + $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker if ($this->sort_column != "id") { - $orderby["id"] = "ASC"; + $order_by["id"] = "ASC"; } } - return parent::children($limit, $offset, $where, $orderby); + return parent::children($limit, $offset, $where, $order_by); } /** @@ -617,14 +617,14 @@ class Item_Model extends ORM_MPTT { * @param array additional where clauses * @return object ORM_Iterator */ - function descendants($limit=null, $offset=0, $where=array(), $orderby=null) { - if (empty($orderby)) { - $orderby = array($this->sort_column => $this->sort_order); + function descendants($limit=null, $offset=0, $where=array(), $order_by=null) { + if (empty($order_by)) { + $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker if ($this->sort_column != "id") { - $orderby["id"] = "ASC"; + $order_by["id"] = "ASC"; } } - return parent::descendants($limit, $offset, $where, $orderby); + return parent::descendants($limit, $offset, $where, $order_by); } } diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 25961129..053a1891 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -199,7 +199,7 @@ class Server_Add_Controller extends Admin_Controller { $entries = ORM::factory("server_add_file") ->where("task_id", $task->id) ->where("item_id", null) - ->orderby("id", "ASC") + ->order_by("id", "ASC") ->limit(10) ->find_all(); if ($entries->count() == 0) { diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index 93b51814..aff44803 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -29,7 +29,7 @@ class Admin_Tags_Controller extends Admin_Controller { if ($filter) { $query->like("name", $filter); } - $view->content->tags = $query->orderby("name", "ASC")->find_all(); + $view->content->tags = $query->order_by("name", "ASC")->find_all(); print $view; } diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 9f9e45d9..dfa3a9b3 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -84,7 +84,7 @@ class Tags_Controller extends Controller { $tag_part = end($tag_parts); $tag_list = ORM::factory("tag") ->like("name", "{$tag_part}%", false) - ->orderby("name", "ASC") + ->order_by("name", "ASC") ->limit($limit) ->find_all(); foreach ($tag_list as $tag) { diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index 619e6e18..ee65efd2 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -22,10 +22,10 @@ class Admin_Users_Controller extends Admin_Controller { $view = new Admin_View("admin.html"); $view->content = new View("admin_users.html"); $view->content->users = ORM::factory("user") - ->orderby("name", "ASC") + ->order_by("name", "ASC") ->find_all(); $view->content->groups = ORM::factory("group") - ->orderby("name", "ASC") + ->order_by("name", "ASC") ->find_all(); print $view; } -- cgit v1.2.3 From 96b00d6cfe437e376d5547a10aa8d1cf7def8c13 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 21:14:54 -0800 Subject: Convert some more Database::instance() calls to db::build() form. --- modules/comment/helpers/comment_event.php | 5 +- modules/gallery/helpers/item.php | 4 +- modules/gallery/libraries/ORM_MPTT.php | 90 +++++++++++++++++---------- modules/gallery/models/item.php | 6 +- modules/notification/helpers/notification.php | 4 +- modules/tag/helpers/tag.php | 4 +- 6 files changed, 69 insertions(+), 44 deletions(-) (limited to 'modules/gallery/helpers/item.php') diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index cf5d0a60..c90f7663 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -62,12 +62,11 @@ class comment_event_Core { } static function item_index_data($item, $data) { - foreach (Database::instance() + foreach (db::build() ->select("text") ->from("comments") ->where("item_id", "=", $item->id) - ->get() - ->as_array() as $row) { + ->execute() as $row) { $data[] = $row->text; } } diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 7496d368..c3126435 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -140,10 +140,10 @@ class item_Core { // Guard against an empty result when we create the first item. It's unfortunate that we // have to check this every time. // @todo: figure out a better way to bootstrap the weight. - $result = Database::instance() + $result = db::build() ->select("weight")->from("items") ->order_by("weight", "desc")->limit(1) - ->get()->current(); + ->execute()->current(); return ($result ? $result->weight : 0) + 1; } diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index a67f05be..0ec0a848 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -51,10 +51,16 @@ class ORM_MPTT_Core extends ORM { try { // Make a hole in the parent for this new item - $this->db->query( - "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` + 2 WHERE `left_ptr` >= {$parent->right_ptr}"); - $this->db->query( - "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` + 2 WHERE `right_ptr` >= {$parent->right_ptr}"); + $this->db_builder + ->update($this->table_name) + ->set("left_ptr", new Database_Expression("`left_ptr` + 2")) + ->where("left_ptr", ">=", $parent->right_ptr) + ->execute(); + $this->db_builder + ->update($this->table_name) + ->set("right_ptr", new Database_Expression("`right_ptr` + 2")) + ->where("right_ptr", ">=", $parent->right_ptr) + ->execute(); $parent->right_ptr += 2; // Insert this item into the hole @@ -92,10 +98,16 @@ class ORM_MPTT_Core extends ORM { $this->lock(); try { - $this->db->query( - "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` - 2 WHERE `left_ptr` > {$this->right_ptr}"); - $this->db->query( - "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` - 2 WHERE `right_ptr` > {$this->right_ptr}"); + $this->db_builder + ->update($this->table_name) + ->set("left_ptr", new Database_Expression("`left_ptr` - 2")) + ->where("left_ptr", ">", $this->right_ptr) + ->execute(); + $this->db_builder + ->update($this->table_name) + ->set("right_ptr", new Database_Expression("`right_ptr` - 2")) + ->where("right_ptr", ">", $this->right_ptr) + ->execute(); } catch (Exception $e) { $this->unlock(); throw $e; @@ -239,23 +251,32 @@ class ORM_MPTT_Core extends ORM { try { if ($level_delta) { // Update the levels for the to-be-moved items - $this->db->query( - "UPDATE {{$this->table_name}} SET `level` = `level` + $level_delta" . - " WHERE `left_ptr` >= $original_left_ptr AND `right_ptr` <= $original_right_ptr"); + $this->db_builder + ->update($this->table_name) + ->set("level", new Database_Expression("`level` + $level_delta")) + ->where("left_ptr", ">=", $original_left_ptr) + ->where("right_ptr", "<=", $original_right_ptr) + ->execute(); } // Make a hole in the target for the move - $target->db->query( - "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` + $size_of_hole" . - " WHERE `left_ptr` >= $target_right_ptr"); - $target->db->query( - "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` + $size_of_hole" . - " WHERE `right_ptr` >= $target_right_ptr"); + $target->db_builder + ->update($this->table_name) + ->set("left_ptr", new Database_Expression("`left_ptr` + $size_of_hole")) + ->where("left_ptr", ">=", $target_right_ptr) + ->execute(); + $target->db_builder + ->update($this->table_name) + ->set("right_ptr", new Database_Expression("`right_ptr` + $size_of_hole")) + ->where("right_ptr", ">=", $target_right_ptr) + ->execute(); // Change the parent. - $this->db->query( - "UPDATE {{$this->table_name}} SET `parent_id` = {$target->id}" . - " WHERE `id` = {$this->id}"); + $this->db_builder + ->update($this->table_name) + ->set("parent_id", $target->id) + ->where("id", "=", $this->id) + ->execute(); // If the source is to the right of the target then we just adjusted its left_ptr and right_ptr above. $left_ptr = $original_left_ptr; @@ -266,20 +287,25 @@ class ORM_MPTT_Core extends ORM { } $new_offset = $target->right_ptr - $left_ptr; - $this->db->query( - "UPDATE {{$this->table_name}}" . - " SET `left_ptr` = `left_ptr` + $new_offset," . - " `right_ptr` = `right_ptr` + $new_offset" . - " WHERE `left_ptr` >= $left_ptr" . - " AND `right_ptr` <= $right_ptr"); + $this->db_builder + ->update($this->table_name) + ->set("left_ptr", new Database_Expression("`left_ptr` + $new_offset")) + ->set("right_ptr", new Database_Expression("`right_ptr` + $new_offset")) + ->where("left_ptr", ">=", $left_ptr) + ->where("right_ptr", "<=", $right_ptr) + ->execute(); // Close the hole in the source's parent after the move - $this->db->query( - "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` - $size_of_hole" . - " WHERE `left_ptr` > $right_ptr"); - $this->db->query( - "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` - $size_of_hole" . - " WHERE `right_ptr` > $right_ptr"); + $this->db_builder + ->update($this->table_name) + ->set("left_ptr", new Database_Expression("`left_ptr` - $size_of_hole")) + ->where("left_ptr", ">", $right_ptr) + ->execute(); + $this->db_builder + ->update($this->table_name) + ->set("right_ptr", new Database_Expression("`right_ptr` - $size_of_hole")) + ->where("right_ptr", ">", $right_ptr) + ->execute(); } catch (Exception $e) { $this->unlock(); throw $e; diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 16c57dbc..8a42cc1e 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -285,14 +285,14 @@ class Item_Model extends ORM_MPTT { private function _build_relative_caches() { $names = array(); $slugs = array(); - foreach (Database::instance() + foreach (db::build() ->select(array("name", "slug")) ->from("items") ->where("left_ptr", "<=", $this->left_ptr) ->where("right_ptr", ">=", $this->right_ptr) ->where("id", "<>", 1) ->order_by("left_ptr", "ASC") - ->get() as $row) { + ->execute() as $row) { // Don't encode the names segment $names[] = rawurlencode($row->name); $slugs[] = rawurlencode($row->slug); @@ -489,7 +489,7 @@ class Item_Model extends ORM_MPTT { ->where("parent_id", "=", $this->id) ->merge_where($where) ->order_by($order_by) - ->get() as $row) { + ->execute() as $row) { $position++; if ($row->id == $child->id) { break; diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 7e935614..31a56c1f 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -170,10 +170,10 @@ class notification { } static function send_pending_notifications() { - foreach (Database::instance() + foreach (db::build() ->select("DISTINCT email") ->from("pending_notifications") - ->get() as $row) { + ->execute() as $row) { $email = $row->email; $result = ORM::factory("pending_notification") ->where("email", "=", $email) diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index c4c4ba15..3e8a0d20 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -89,12 +89,12 @@ class tag_Core { */ static function item_tags($item) { $tags = array(); - foreach (Database::instance() + foreach (db::build() ->select("name") ->from("tags") ->join("items_tags", "tags.id", "items_tags.tag_id", "left") ->where("items_tags.item_id", "=", $item->id) - ->get() as $row) { + ->execute() as $row) { $tags[] = $row->name; } return $tags; -- cgit v1.2.3 From b9dadb77c3c75c6ba6ead293757df440976b3917 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:21:35 -0800 Subject: Get rid of unused _method param in the item edit form. Fix viewable() to properly OR view restrictions together. --- modules/gallery/helpers/item.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'modules/gallery/helpers/item.php') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index c3126435..300a6942 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -127,7 +127,6 @@ class item_Core { $page_type = Input::instance()->get("page_type"); $form = new Forge( "quick/delete/$item->id?page_type=$page_type", "", "post", array("id" => "g-confirm-delete")); - $form->hidden("_method")->value("put"); $group = $form->group("confirm_delete")->label(t("Confirm Deletion")); $group->submit("")->value(t("Delete")); return $form; @@ -156,7 +155,7 @@ class item_Core { $view_restrictions = array(); if (!identity::active_user()->admin) { foreach (identity::group_ids_for_active_user() as $id) { - $view_restrictions[] = "items.view_$id"; + $view_restrictions["items.view_$id"] = access::ALLOW; } } switch (count($view_restrictions)) { @@ -168,10 +167,7 @@ class item_Core { break; default: - $model - ->and_open() - ->or_where($view_restrictions, "=", access::ALLOW) - ->close(); + $model->and_open()->or_where($view_restrictions)->close(); break; } -- cgit v1.2.3 From fb899c313c9cdf4d6b0529c53d2b647999ad94db Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:28:40 -0800 Subject: Further simplifications to viewable(). Stop trying to optimize for the case where we just have one restriction, it's unnecessary. --- modules/gallery/helpers/item.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'modules/gallery/helpers/item.php') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 300a6942..b7be23cd 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -158,17 +158,9 @@ class item_Core { $view_restrictions["items.view_$id"] = access::ALLOW; } } - switch (count($view_restrictions)) { - case 0: - break; - case 1: - $model->where($view_restrictions[0], "=", access::ALLOW); - break; - - default: + if (count($view_restrictions)) { $model->and_open()->or_where($view_restrictions)->close(); - break; } return $model; -- cgit v1.2.3 From 0650109d4bb5442cd77fcda61745dab67a632836 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 13:50:52 -0800 Subject: Add merge_or_where() to MY_Datatabase_Builder and use that instead of or_where() for compatibility and convenience. Caught by failing unit tests. --- modules/gallery/helpers/item.php | 4 ++-- modules/kohana23_compat/libraries/MY_Database_Builder.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'modules/gallery/helpers/item.php') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index b7be23cd..f6181f8a 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -155,12 +155,12 @@ class item_Core { $view_restrictions = array(); if (!identity::active_user()->admin) { foreach (identity::group_ids_for_active_user() as $id) { - $view_restrictions["items.view_$id"] = access::ALLOW; + $view_restrictions[] = array("items.view_$id", "=", access::ALLOW); } } if (count($view_restrictions)) { - $model->and_open()->or_where($view_restrictions)->close(); + $model->and_open()->merge_or_where($view_restrictions)->close(); } return $model; diff --git a/modules/kohana23_compat/libraries/MY_Database_Builder.php b/modules/kohana23_compat/libraries/MY_Database_Builder.php index 54a10860..c82b6ac4 100644 --- a/modules/kohana23_compat/libraries/MY_Database_Builder.php +++ b/modules/kohana23_compat/libraries/MY_Database_Builder.php @@ -29,6 +29,17 @@ class Database_Builder extends Database_Builder_Core { return $this; } + /** + * Merge in a series of where clause tuples and call or_where() on each one. + * @chainable + */ + public function merge_or_where($tuples) { + foreach ($tuples as $tuple) { + $this->or_where($tuple[0], $tuple[1], $tuple[2]); + } + return $this; + } + public function compile() { return parent::compile(); } -- cgit v1.2.3