Skip to content

Commit

Permalink
Use db::expr instead of "new Database_Expression". Resolves #1560.
Browse files Browse the repository at this point in the history
  • Loading branch information
bharat committed Dec 29, 2010
1 parent 9f3c6e4 commit b42fcb9
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion modules/comment/controllers/admin_manage_comments.php
Expand Up @@ -25,7 +25,7 @@ public function index() {
db::build() db::build()
->delete("comments") ->delete("comments")
->where("state", "IN", array("deleted", "spam")) ->where("state", "IN", array("deleted", "spam"))
->where("updated", "<", new Database_Expression("UNIX_TIMESTAMP() - 86400 * 7")) ->where("updated", "<", db::expr("UNIX_TIMESTAMP() - 86400 * 7"))
->execute(); ->execute();


// Redirect to the appropriate queue // Redirect to the appropriate queue
Expand Down
2 changes: 1 addition & 1 deletion modules/digibug/controllers/digibug.php
Expand Up @@ -114,7 +114,7 @@ public function close_window() {
private function _clean_expired() { private function _clean_expired() {
db::build() db::build()
->delete("digibug_proxies") ->delete("digibug_proxies")
->where("request_date", "<=", new Database_Expression("(CURDATE() - INTERVAL 10 DAY)")) ->where("request_date", "<=", db::expr("(CURDATE() - INTERVAL 10 DAY)"))
->limit(20) ->limit(20)
->execute(); ->execute();
} }
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/controllers/admin_maintenance.php
Expand Up @@ -27,7 +27,7 @@ public function index() {
->set("state", "stalled") ->set("state", "stalled")
->where("done", "=", 0) ->where("done", "=", 0)
->where("state", "<>", "stalled") ->where("state", "<>", "stalled")
->where(new Database_Expression("UNIX_TIMESTAMP(NOW()) - `updated` > 15")) ->where(db::expr("UNIX_TIMESTAMP(NOW()) - `updated` > 15"))
->execute(); ->execute();
$stalled_count = $query->count(); $stalled_count = $query->count();
if ($stalled_count) { if ($stalled_count) {
Expand Down
6 changes: 3 additions & 3 deletions modules/gallery/helpers/gallery_installer.php
Expand Up @@ -503,7 +503,7 @@ static function upgrade($version) {
foreach (db::build() foreach (db::build()
->from("items") ->from("items")
->select("id", "slug") ->select("id", "slug")
->where(new Database_Expression("`slug` REGEXP '[^_A-Za-z0-9-]'"), "=", 1) ->where(db::expr("`slug` REGEXP '[^_A-Za-z0-9-]'"), "=", 1)
->execute() as $row) { ->execute() as $row) {
$new_slug = item::convert_filename_to_slug($row->slug); $new_slug = item::convert_filename_to_slug($row->slug);
if (empty($new_slug)) { if (empty($new_slug)) {
Expand Down Expand Up @@ -540,7 +540,7 @@ static function upgrade($version) {
if ($version == 25) { if ($version == 25) {
db::build() db::build()
->update("items") ->update("items")
->set("title", new Database_Expression("`name`")) ->set("title", db::expr("`name`"))
->and_open() ->and_open()
->where("title", "IS", null) ->where("title", "IS", null)
->or_where("title", "=", "") ->or_where("title", "=", "")
Expand Down Expand Up @@ -581,7 +581,7 @@ static function upgrade($version) {
$db->query("ALTER TABLE {modules} ADD COLUMN `weight` int(9) DEFAULT NULL"); $db->query("ALTER TABLE {modules} ADD COLUMN `weight` int(9) DEFAULT NULL");
$db->query("ALTER TABLE {modules} ADD KEY (`weight`)"); $db->query("ALTER TABLE {modules} ADD KEY (`weight`)");
db::update("modules") db::update("modules")
->set("weight", new Database_Expression("`id`")) ->set("weight", db::expr("`id`"))
->execute(); ->execute();
module::set_version("gallery", $version = 32); module::set_version("gallery", $version = 32);
} }
Expand Down
6 changes: 3 additions & 3 deletions modules/gallery/helpers/gallery_task.php
Expand Up @@ -74,7 +74,7 @@ static function rebuild_dirty_images($task) {
// Choose the dirty images in a random order so that if we run this task multiple times // Choose the dirty images in a random order so that if we run this task multiple times
// concurrently each task is rebuilding different images simultaneously. // concurrently each task is rebuilding different images simultaneously.
$result = graphics::find_dirty_images_query()->select("id") $result = graphics::find_dirty_images_query()->select("id")
->select(new Database_Expression("RAND() as r")) ->select(db::expr("RAND() as r"))
->order_by("r", "ASC") ->order_by("r", "ASC")
->execute(); ->execute();
$total_count = $task->get("total_count", $result->count()); $total_count = $task->get("total_count", $result->count());
Expand Down Expand Up @@ -608,7 +608,7 @@ static function fix($task) {
static function find_dupe_slugs() { static function find_dupe_slugs() {
return db::build() return db::build()
->select_distinct( ->select_distinct(
array("parent_slug" => new Database_Expression("CONCAT(`parent_id`, ':', LOWER(`slug`))"))) array("parent_slug" => db::expr("CONCAT(`parent_id`, ':', LOWER(`slug`))")))
->select("id") ->select("id")
->select(array("C" => "COUNT(\"*\")")) ->select(array("C" => "COUNT(\"*\")"))
->from("items") ->from("items")
Expand All @@ -620,7 +620,7 @@ static function find_dupe_slugs() {
static function find_dupe_names() { static function find_dupe_names() {
return db::build() return db::build()
->select_distinct( ->select_distinct(
array("parent_name" => new Database_Expression("CONCAT(`parent_id`, ':', LOWER(`name`))"))) array("parent_name" => db::expr("CONCAT(`parent_id`, ':', LOWER(`name`))")))
->select("id") ->select("id")
->select(array("C" => "COUNT(\"*\")")) ->select(array("C" => "COUNT(\"*\")"))
->from("items") ->from("items")
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/helpers/module.php
Expand Up @@ -488,7 +488,7 @@ static function set_var($module_name, $name, $value) {
static function incr_var($module_name, $name, $increment=1) { static function incr_var($module_name, $name, $increment=1) {
db::build() db::build()
->update("vars") ->update("vars")
->set("value", new Database_Expression("`value` + $increment")) ->set("value", db::expr("`value` + $increment"))
->where("module_name", "=", $module_name) ->where("module_name", "=", $module_name)
->where("name", "=", $name) ->where("name", "=", $name)
->execute(); ->execute();
Expand Down
22 changes: 11 additions & 11 deletions modules/gallery/libraries/ORM_MPTT.php
Expand Up @@ -54,12 +54,12 @@ function save() {
// Make a hole in the parent for this new item // Make a hole in the parent for this new item
db::build() db::build()
->update($this->table_name) ->update($this->table_name)
->set("left_ptr", new Database_Expression("`left_ptr` + 2")) ->set("left_ptr", db::expr("`left_ptr` + 2"))
->where("left_ptr", ">=", $parent->right_ptr) ->where("left_ptr", ">=", $parent->right_ptr)
->execute(); ->execute();
db::build() db::build()
->update($this->table_name) ->update($this->table_name)
->set("right_ptr", new Database_Expression("`right_ptr` + 2")) ->set("right_ptr", db::expr("`right_ptr` + 2"))
->where("right_ptr", ">=", $parent->right_ptr) ->where("right_ptr", ">=", $parent->right_ptr)
->execute(); ->execute();
$parent->right_ptr += 2; $parent->right_ptr += 2;
Expand Down Expand Up @@ -109,12 +109,12 @@ public function delete($ignored_id=null) {
try { try {
db::build() db::build()
->update($this->table_name) ->update($this->table_name)
->set("left_ptr", new Database_Expression("`left_ptr` - 2")) ->set("left_ptr", db::expr("`left_ptr` - 2"))
->where("left_ptr", ">", $this->right_ptr) ->where("left_ptr", ">", $this->right_ptr)
->execute(); ->execute();
db::build() db::build()
->update($this->table_name) ->update($this->table_name)
->set("right_ptr", new Database_Expression("`right_ptr` - 2")) ->set("right_ptr", db::expr("`right_ptr` - 2"))
->where("right_ptr", ">", $this->right_ptr) ->where("right_ptr", ">", $this->right_ptr)
->execute(); ->execute();
} catch (Exception $e) { } catch (Exception $e) {
Expand Down Expand Up @@ -253,7 +253,7 @@ protected function move_to($target) {
// Update the levels for the to-be-moved items // Update the levels for the to-be-moved items
db::build() db::build()
->update($this->table_name) ->update($this->table_name)
->set("level", new Database_Expression("`level` + $level_delta")) ->set("level", db::expr("`level` + $level_delta"))
->where("left_ptr", ">=", $original_left_ptr) ->where("left_ptr", ">=", $original_left_ptr)
->where("right_ptr", "<=", $original_right_ptr) ->where("right_ptr", "<=", $original_right_ptr)
->execute(); ->execute();
Expand All @@ -262,12 +262,12 @@ protected function move_to($target) {
// Make a hole in the target for the move // Make a hole in the target for the move
db::build() db::build()
->update($this->table_name) ->update($this->table_name)
->set("left_ptr", new Database_Expression("`left_ptr` + $size_of_hole")) ->set("left_ptr", db::expr("`left_ptr` + $size_of_hole"))
->where("left_ptr", ">=", $target_right_ptr) ->where("left_ptr", ">=", $target_right_ptr)
->execute(); ->execute();
db::build() db::build()
->update($this->table_name) ->update($this->table_name)
->set("right_ptr", new Database_Expression("`right_ptr` + $size_of_hole")) ->set("right_ptr", db::expr("`right_ptr` + $size_of_hole"))
->where("right_ptr", ">=", $target_right_ptr) ->where("right_ptr", ">=", $target_right_ptr)
->execute(); ->execute();


Expand All @@ -290,21 +290,21 @@ protected function move_to($target) {
$new_offset = $target->right_ptr - $left_ptr; $new_offset = $target->right_ptr - $left_ptr;
db::build() db::build()
->update($this->table_name) ->update($this->table_name)
->set("left_ptr", new Database_Expression("`left_ptr` + $new_offset")) ->set("left_ptr", db::expr("`left_ptr` + $new_offset"))
->set("right_ptr", new Database_Expression("`right_ptr` + $new_offset")) ->set("right_ptr", db::expr("`right_ptr` + $new_offset"))
->where("left_ptr", ">=", $left_ptr) ->where("left_ptr", ">=", $left_ptr)
->where("right_ptr", "<=", $right_ptr) ->where("right_ptr", "<=", $right_ptr)
->execute(); ->execute();


// Close the hole in the source's parent after the move // Close the hole in the source's parent after the move
db::build() db::build()
->update($this->table_name) ->update($this->table_name)
->set("left_ptr", new Database_Expression("`left_ptr` - $size_of_hole")) ->set("left_ptr", db::expr("`left_ptr` - $size_of_hole"))
->where("left_ptr", ">", $right_ptr) ->where("left_ptr", ">", $right_ptr)
->execute(); ->execute();
db::build() db::build()
->update($this->table_name) ->update($this->table_name)
->set("right_ptr", new Database_Expression("`right_ptr` - $size_of_hole")) ->set("right_ptr", db::expr("`right_ptr` - $size_of_hole"))
->where("right_ptr", ">", $right_ptr) ->where("right_ptr", ">", $right_ptr)
->execute(); ->execute();
} catch (Exception $e) { } catch (Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/tests/Gallery_Installer_Test.php
Expand Up @@ -35,7 +35,7 @@ public function install_registers_gallery_module_test() {


public function install_creates_root_item_test() { public function install_creates_root_item_test() {
$max_right_ptr = ORM::factory("item") $max_right_ptr = ORM::factory("item")
->select(new Database_Expression("MAX(`right_ptr`) AS `right_ptr`")) ->select(db::expr("MAX(`right_ptr`) AS `right_ptr`"))
->find()->right_ptr; ->find()->right_ptr;
$root = ORM::factory('item')->find(1); $root = ORM::factory('item')->find(1);
$this->assert_equal("Gallery", $root->title); $this->assert_equal("Gallery", $root->title);
Expand Down
2 changes: 1 addition & 1 deletion modules/notification/helpers/notification.php
Expand Up @@ -160,7 +160,7 @@ static function send_comment_published($comment) {


static function send_pending_notifications() { static function send_pending_notifications() {
foreach (db::build() foreach (db::build()
->select(new Database_Expression("DISTINCT `email`")) ->select(db::expr("DISTINCT `email`"))
->from("pending_notifications") ->from("pending_notifications")
->execute() as $row) { ->execute() as $row) {
$email = $row->email; $email = $row->email;
Expand Down
2 changes: 1 addition & 1 deletion modules/tag/helpers/tag.php
Expand Up @@ -118,7 +118,7 @@ static function get_delete_form($tag) {
static function clear_all($item) { static function clear_all($item) {
db::build() db::build()
->update("tags") ->update("tags")
->set("count", new Database_Expression("`count` - 1")) ->set("count", db::expr("`count` - 1"))
->where("count", ">", 0) ->where("count", ">", 0)
->where("id", "IN", db::build()->select("tag_id")->from("items_tags")->where("item_id", "=", $item->id)) ->where("id", "IN", db::build()->select("tag_id")->from("items_tags")->where("item_id", "=", $item->id))
->execute(); ->execute();
Expand Down

0 comments on commit b42fcb9

Please sign in to comment.