diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/comment/helpers/comment_event.php | 27 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_block.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_event.php | 28 | ||||
-rw-r--r-- | modules/gallery/tests/Database_Test.php | 22 | ||||
-rw-r--r-- | modules/notification/helpers/notification_event.php | 7 |
5 files changed, 61 insertions, 25 deletions
diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index ddf72e3c..a72102b9 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -24,23 +24,24 @@ class comment_event_Core { static function user_deleted($user) { $guest = identity::guest(); - Database::instance() - ->query("UPDATE {comments} - SET author_id = {$guest->id}, - guest_email = NULL, - guest_name = 'guest', - guest_url = NULL - WHERE author_id = {$user->id}"); + Database::instance()->from("comments") + ->set(array("author_id" => $guest->id, + "guest_email" => null, + "guest_name" => "guest", + "guest_url" => null)) + ->where(array("author_id" => $user->id)) + ->update(); } static function identity_provider_changed($old_provider, $new_provider) { $guest = identity::guest(); - Database::instance() - ->query("UPDATE {comments} - SET author_id = {$guest->id}, - guest_email = NULL, - guest_name = 'guest', - guest_url = null"); + Database::instance()->from("comments") + ->set(array("author_id" => $guest->id, + "guest_email" => null, + "guest_name" => "guest", + "guest_url" => null)) + ->where("1 = 1") + ->update(); } static function admin_menu($menu, $theme) { diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index 0052affc..b5c32ad2 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -72,7 +72,7 @@ class gallery_block_Core { $block->content = new View("admin_block_platform.html"); if (is_readable("/proc/loadavg")) { $block->content->load_average = - join(" ", array_slice(split(" ", array_shift(file("/proc/loadavg"))), 0, 3)); + join(" ", array_slice(explode(" ", array_shift(file("/proc/loadavg"))), 0, 3)); } else { $block->content->load_average = t("Unavailable"); } diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 582e3267..67a6f41f 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -31,15 +31,35 @@ class gallery_event_Core { static function user_deleted($user) { $admin = identity::admin_user(); $db = Database::instance(); - $db->query("UPDATE {tasks} SET owner_id = {$admin->id} where owner_id = {$user->id}"); - $db->query("UPDATE {items} SET owner_id = {$admin->id} where owner_id = {$user->id}"); + $db->from("tasks") + ->set(array("owner_id" => $admin->id)) + ->where(array("owner_id" => $user->id)) + ->update(); + $db->from("items") + ->set(array("owner_id" => $admin->id)) + ->where(array("owner_id" => $user->id)) + ->update(); + $db->from("logs") + ->set(array("user_id" => $admin->id)) + ->where(array("user_id" => $user->id)) + ->update(); } static function identity_provider_changed($old_provider, $new_provider) { $admin = identity::admin_user(); $db = Database::instance(); - $db->query("UPDATE {tasks} SET owner_id = {$admin->id}"); - $db->query("UPDATE {items} SET owner_id = {$admin->id}"); + $db->from("tasks") + ->set(array("owner_id" => $admin->id)) + ->where("1 = 1") + ->update(); + $db->from("items") + ->set(array("owner_id" => $admin->id)) + ->where("1 = 1") + ->update(); + $db->from("logs") + ->set(array("user_id" => $admin->id)) + ->where("1 = 1") + ->update(); } static function group_created($group) { diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index d83212ad..ad2bbba1 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -99,7 +99,7 @@ class Database_Test extends Unit_Test_Case { UNIQUE KEY(`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"; $this->assert_same($expected, $converted); - + $sql = "UPDATE {test_tables} SET `name` = '{test string}' " . "WHERE `item_id` IN " . " (SELECT `id` FROM {items} " . @@ -116,12 +116,16 @@ class Database_Test extends Unit_Test_Case { $this->assert_same($expected, $sql); } - public function setup() { - } + function prefix_no_replacement_test() { + $update = Database_For_Test::instance()->from("test_tables") + ->where("1 = 1") + ->set(array("name" => "Test Name")) + ->update(); - public function teardown() { - } + $expected = "UPDATE `g3test_test_tables` SET `name` = 'Test Name' WHERE 1 = 1"; + $this->assert_same($expected, $update); + } } class Database_For_Test extends Database { @@ -131,4 +135,12 @@ class Database_For_Test extends Database { $db->config["table_prefix"] = "g3test_"; return $db; } + + public function query($sql = '') { + if (!empty($sql)) { + print " query($sql)\n"; + $sql = $this->add_table_prefixes($sql); + } + return $sql; + } } diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index b82e4f0f..6b2df574 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -53,11 +53,14 @@ class notification_event_Core { } static function user_deleted($user) { - Database::instance()->query("DELETE FROM {subscriptions} where user_id = {$user->id}"); + ORM::factory("subscriptions") + ->where(array("user_id", $user->id)) + ->delete_all(); } static function identity_provider_changed($old_provider, $new_provider) { - Database::instance()->query("DELETE FROM {subscriptions}"); + ORM::factory("subscriptions") + ->delete_all(); } static function comment_created($comment) { |