From 3ed7a5af46586f186a4627d8b029aec7c3ff579d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 24 Nov 2009 19:24:02 -0800 Subject: Rename I18n to Gallery_I18n to avoid conflict with Kohana 2.4 --- modules/gallery/tests/I18n_Test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/I18n_Test.php b/modules/gallery/tests/I18n_Test.php index 9010606a..d0555cbf 100644 --- a/modules/gallery/tests/I18n_Test.php +++ b/modules/gallery/tests/I18n_Test.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class I18n_Test extends Unit_Test_Case { +class Gallery_I18n_Test extends Unit_Test_Case { private $i18n; public function setup() { @@ -26,7 +26,7 @@ class I18n_Test extends Unit_Test_Case { 'root_locale' => 'en', 'default_locale' => 'te_ST', 'locale_dir' => VARPATH . 'locale/'); - $this->i18n = I18n::instance($config); + $this->i18n = Gallery_I18n::instance($config); ORM::factory("incoming_translation") ->where("locale", "te_ST") @@ -43,7 +43,7 @@ class I18n_Test extends Unit_Test_Case { foreach ($messages_te_ST as $data) { list ($message, $translation) = $data; $entry = ORM::factory("incoming_translation"); - $entry->key = I18n::get_message_key($message); + $entry->key = Gallery_I18n::get_message_key($message); $entry->message = serialize($message); $entry->translation = serialize($translation); $entry->locale = 'te_ST'; -- cgit v1.2.3 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/akismet/helpers/akismet.php | 4 +- modules/comment/controllers/admin_comments.php | 2 +- modules/comment/models/comment.php | 2 +- modules/comment/tests/Comment_Event_Test.php | 2 +- modules/digibug/controllers/digibug.php | 2 +- modules/exif/helpers/exif.php | 4 +- modules/g2_import/helpers/g2_import.php | 14 ++-- modules/g2_import/helpers/g2_import_task.php | 2 +- modules/gallery/controllers/admin_maintenance.php | 8 +- modules/gallery/controllers/albums.php | 3 +- modules/gallery/controllers/file_proxy.php | 6 +- modules/gallery/controllers/l10n_client.php | 6 +- modules/gallery/controllers/permissions.php | 2 +- modules/gallery/controllers/rest.php | 4 +- modules/gallery/controllers/simple_uploader.php | 2 +- modules/gallery/helpers/MY_url.php | 4 +- modules/gallery/helpers/access.php | 18 ++-- modules/gallery/helpers/album.php | 2 +- modules/gallery/helpers/auth.php | 2 +- modules/gallery/helpers/gallery_graphics.php | 2 +- modules/gallery/helpers/gallery_task.php | 2 +- modules/gallery/helpers/graphics.php | 2 +- modules/gallery/helpers/identity.php | 4 +- modules/gallery/helpers/item.php | 18 ++-- modules/gallery/helpers/l10n_client.php | 2 +- modules/gallery/helpers/l10n_scanner.php | 2 +- modules/gallery/helpers/model_cache.php | 4 +- modules/gallery/helpers/module.php | 35 ++++---- modules/gallery/helpers/movie.php | 2 +- modules/gallery/helpers/photo.php | 2 +- modules/gallery/helpers/site_status.php | 4 +- modules/gallery/helpers/task.php | 8 +- modules/gallery/helpers/theme.php | 2 +- modules/gallery/libraries/Admin_View.php | 2 +- modules/gallery/libraries/Gallery_I18n.php | 8 +- modules/gallery/libraries/Gallery_View.php | 6 +- modules/gallery/libraries/IdentityProvider.php | 4 +- modules/gallery/libraries/MY_ORM.php | 10 --- modules/gallery/libraries/MY_View.php | 27 +++++- modules/gallery/libraries/ORM_MPTT.php | 56 ++++++++----- modules/gallery/libraries/SafeString.php | 2 +- modules/gallery/libraries/Sendmail.php | 4 +- modules/gallery/libraries/Theme_View.php | 2 +- .../gallery/libraries/drivers/Cache/Database.php | 95 ++++++++++++---------- modules/gallery/models/item.php | 6 +- modules/gallery/models/log.php | 2 +- modules/gallery/tests/Access_Helper_Test.php | 8 +- modules/gallery/views/kohana_error_page.php | 2 +- modules/notification/helpers/notification.php | 2 +- .../notification/helpers/notification_event.php | 28 +++---- modules/search/helpers/search.php | 2 +- modules/server_add/controllers/server_add.php | 4 +- modules/tag/controllers/admin_tags.php | 8 +- modules/tag/helpers/tag.php | 2 +- modules/tag/helpers/tag_event.php | 2 +- modules/tag/helpers/tag_rss.php | 2 +- modules/user/controllers/admin_users.php | 2 +- modules/user/controllers/password.php | 2 +- modules/user/helpers/group.php | 4 +- modules/user/helpers/user.php | 4 +- modules/user/models/group.php | 2 +- modules/user/models/user.php | 2 +- modules/user/tests/User_Groups_Test.php | 4 +- 63 files changed, 257 insertions(+), 225 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/akismet/helpers/akismet.php b/modules/akismet/helpers/akismet.php index 43549ffa..46a305b2 100644 --- a/modules/akismet/helpers/akismet.php +++ b/modules/akismet/helpers/akismet.php @@ -166,7 +166,7 @@ class akismet_Core { } $response = ""; - Kohana::log("debug", "Send request\n" . print_r($http_request, 1)); + Kohana_Log::add("debug", "Send request\n" . print_r($http_request, 1)); if (false !== ($fs = @fsockopen($host, 80, $errno, $errstr, 5))) { fwrite($fs, $http_request); while ( !feof($fs) ) { @@ -181,7 +181,7 @@ class akismet_Core { } else { throw new Exception("@todo CONNECTION TO SPAM SERVICE FAILED"); } - Kohana::log("debug", "Received response\n" . print_r($response, 1)); + Kohana_Log::add("debug", "Received response\n" . print_r($response, 1)); return $response; } diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php index 13532c4e..1a9f0e6a 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -110,7 +110,7 @@ class Admin_Comments_Controller extends Admin_Controller { $comment = ORM::factory("comment", $id); $orig = clone $comment; - if ($comment->loaded) { + if ($comment->loaded()) { $comment->state = $state; $comment->save(); } diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index bb9b8833..59b85233 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -59,7 +59,7 @@ class Comment_Model extends ORM { public function save() { if (!empty($this->changed)) { $this->updated = time(); - if (!$this->loaded && empty($this->created)) { + if (!$this->loaded() && empty($this->created)) { $this->created = $this->updated; $created = true; } diff --git a/modules/comment/tests/Comment_Event_Test.php b/modules/comment/tests/Comment_Event_Test.php index f650cabf..ff7f1c26 100644 --- a/modules/comment/tests/Comment_Event_Test.php +++ b/modules/comment/tests/Comment_Event_Test.php @@ -27,6 +27,6 @@ class Comment_Event_Test extends Unit_Test_Case { $album->delete(); $deleted_comment = ORM::factory("comment", $comment->id); - $this->assert_false($deleted_comment->loaded); + $this->assert_false($deleted_comment->loaded()); } } diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index 1bb2691b..cef42b2d 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -81,7 +81,7 @@ class Digibug_Controller extends Controller { } $proxy = ORM::factory("digibug_proxy", array("uuid" => $id)); - if (!$proxy->loaded || !$proxy->item->loaded) { + if (!$proxy->loaded() || !$proxy->item->loaded()) { Kohana::show_404(); } diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index 5ddd09d4..b6a55679 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -74,7 +74,7 @@ class exif_Core { $item->save(); $record = ORM::factory("exif_record")->where("item_id", $item->id)->find(); - if (!$record->loaded) { + if (!$record->loaded()) { $record->item_id = $item->id; } $record->data = serialize($keys); @@ -88,7 +88,7 @@ class exif_Core { $record = ORM::factory("exif_record") ->where("item_id", $item->id) ->find(); - if (!$record->loaded) { + if (!$record->loaded()) { return array(); } diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 202a0e92..1e835a59 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -458,7 +458,7 @@ class g2_import_Core { switch ($g2_type) { case "GalleryPhotoItem": if (!in_array($g2_item->getMimeType(), array("image/jpeg", "image/gif", "image/png"))) { - Kohana::log("alert", "$g2_path is an unsupported image type; using a placeholder gif"); + Kohana_Log::add("alert", "$g2_path is an unsupported image type; using a placeholder gif"); $message[] = t("'%path' is an unsupported image type, using a placeholder", array("path" => $g2_path)); $g2_path = MODPATH . "g2_import/data/broken-image.gif"; @@ -473,7 +473,7 @@ class g2_import_Core { self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); } catch (Exception $e) { - Kohana::log( + Kohana_Log::add( "alert", "Corrupt image $g2_path\n" . $e->__toString()); $message[] = t("Corrupt image '%path'", array("path" => $g2_path)); $message[] = $e->__toString(); @@ -493,13 +493,13 @@ class g2_import_Core { self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); } catch (Exception $e) { - Kohana::log("alert", "Corrupt movie $g2_path\n" . $e->__toString()); + Kohana_Log::add("alert", "Corrupt movie $g2_path\n" . $e->__toString()); $message[] = t("Corrupt movie '%path'", array("path" => $g2_path)); $message[] = $e->__toString(); $corrupt = 1; } } else { - Kohana::log("alert", "$g2_path is an unsupported movie type"); + Kohana_Log::add("alert", "$g2_path is an unsupported movie type"); $message[] = t("'%path' is an unsupported movie type", array("path" => $g2_path)); $corrupt = 1; } @@ -868,7 +868,7 @@ class g2_import_Core { static function map($g2_id) { if (!array_key_exists($g2_id, self::$map)) { $g2_map = ORM::factory("g2_map")->where("g2_id", $g2_id)->find(); - self::$map[$g2_id] = $g2_map->loaded ? $g2_map->g3_id : null; + self::$map[$g2_id] = $g2_map->loaded() ? $g2_map->g3_id : null; } return self::$map[$g2_id]; @@ -887,7 +887,7 @@ class g2_import_Core { static function log($msg) { message::warning($msg); - Kohana::log("alert", $msg); + Kohana_Log::add("alert", $msg); } } @@ -906,7 +906,7 @@ function g2() { $args = func_get_arg(0); $ret = array_shift($args); if ($ret) { - Kohana::log("error", "Gallery 2 call failed with: " . $ret->getAsText()); + Kohana_Log::add("error", "Gallery 2 call failed with: " . $ret->getAsText()); throw new Exception("@todo G2_FUNCTION_FAILED"); } if (count($args) == 1) { diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index 47a205bd..fef0d186 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -66,7 +66,7 @@ class g2_import_task_Core { $root_g2_id = g2(GalleryCoreApi::getDefaultAlbumId()); $root = ORM::factory("g2_map")->where("g2_id", $root_g2_id)->find(); - if (!$root->loaded) { + if (!$root->loaded()) { $root->g2_id = $root_g2_id; $root->g3_id = 1; $root->save(); diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 66bcce55..fe5059e7 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -75,7 +75,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { access::verify_csrf(); $task = ORM::factory("task", $task_id); - if (!$task->loaded) { + if (!$task->loaded()) { throw new Exception("@todo MISSING_TASK"); } $view = new View("admin_maintenance_task.html"); @@ -97,7 +97,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { access::verify_csrf(); $task = ORM::factory("task", $task_id); - if (!$task->loaded) { + if (!$task->loaded()) { throw new Exception("@todo MISSING_TASK"); } $view = new View("admin_maintenance_show_log.html"); @@ -114,7 +114,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { access::verify_csrf(); $task = ORM::factory("task", $task_id); - if (!$task->loaded) { + if (!$task->loaded()) { throw new Exception("@todo MISSING_TASK"); } @@ -184,7 +184,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { try { $task = task::run($task_id); } catch (Exception $e) { - Kohana::log( + Kohana_Log::add( "error", sprintf( "%s in %s at line %s:\n%s", $e->getMessage(), $e->getFile(), diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index e67df6f6..cc63d43f 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -66,6 +66,7 @@ class Albums_Controller extends Items_Controller { $template = new Theme_View("page.html", "collection", "album"); $template->set_global("page", $page); + $template->set_global("page_title", null); $template->set_global("max_pages", $max_pages); $template->set_global("page_size", $page_size); $template->set_global("item", $album); @@ -76,7 +77,7 @@ class Albums_Controller extends Items_Controller { // We can't use math in ORM or the query builder, so do this by hand. It's important // that we do this with math, otherwise concurrent accesses will damage accuracy. - Database::instance()->query( + db::query( "UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id"); print $template; diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index acfd6eb9..11d858c0 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -58,7 +58,7 @@ class File_Proxy_Controller extends Controller { // We now have the relative path to the item. Search for it in the path cache $item = ORM::factory("item")->where("relative_path_cache", $path)->find(); - if (!$item->loaded) { + if (!$item->loaded()) { // We didn't turn it up. It's possible that the relative_path_cache is out of date here. // There was fallback code, but bharat deleted it in 8f1bca74. If it turns out to be // necessary, it's easily resurrected. @@ -70,14 +70,14 @@ class File_Proxy_Controller extends Controller { foreach (array("flv", "mp4") as $ext) { $movie_path = preg_replace('/.jpg$/', ".$ext", $path); $item = ORM::factory("item")->where("relative_path_cache", $movie_path)->find(); - if ($item->loaded) { + if ($item->loaded()) { break; } } } } - if (!$item->loaded) { + if (!$item->loaded()) { kohana::show_404(); } diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php index 3801e6aa..2eda741c 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -33,7 +33,7 @@ class L10n_Client_Controller extends Controller { "locale" => "root")) ->find(); - if (!$root_message->loaded) { + if (!$root_message->loaded()) { throw new Exception("@todo bad request data / illegal state"); } $is_plural = Gallery_I18n::is_plural_message(unserialize($root_message->message)); @@ -60,7 +60,7 @@ class L10n_Client_Controller extends Controller { "locale" => $locale)) ->find(); - if (!$entry->loaded) { + if (!$entry->loaded()) { $entry->key = $key; $entry->locale = $locale; $entry->message = $root_message->message; @@ -74,7 +74,7 @@ class L10n_Client_Controller extends Controller { "locale" => $locale)) ->find(); - if (!$entry_from_incoming->loaded) { + if (!$entry_from_incoming->loaded()) { $entry->base_revision = $entry_from_incoming->revision; } diff --git a/modules/gallery/controllers/permissions.php b/modules/gallery/controllers/permissions.php index 99943fbb..e03f41a9 100644 --- a/modules/gallery/controllers/permissions.php +++ b/modules/gallery/controllers/permissions.php @@ -57,7 +57,7 @@ class Permissions_Controller extends Controller { access::required("view", $item); access::required("edit", $item); - if (!empty($group) && $perm->loaded && $item->loaded) { + if (!empty($group) && $perm->loaded() && $item->loaded()) { switch($command) { case "allow": access::allow($group, $perm->name, $item); diff --git a/modules/gallery/controllers/rest.php b/modules/gallery/controllers/rest.php index 2edf079f..087f2c29 100644 --- a/modules/gallery/controllers/rest.php +++ b/modules/gallery/controllers/rest.php @@ -82,7 +82,7 @@ class REST_Controller extends Controller { } $resource = ORM::factory($this->resource_type, (int)$function); - if (!$resource->loaded && $request_method != "post") { + if (!$resource->loaded() && $request_method != "post") { return Kohana::show_404(); } @@ -111,7 +111,7 @@ class REST_Controller extends Controller { } $resource = ORM::factory($this->resource_type, $resource_id); - if (!$resource->loaded) { + if (!$resource->loaded()) { return Kohana::show_404(); } diff --git a/modules/gallery/controllers/simple_uploader.php b/modules/gallery/controllers/simple_uploader.php index 37753ff3..5d32e35f 100644 --- a/modules/gallery/controllers/simple_uploader.php +++ b/modules/gallery/controllers/simple_uploader.php @@ -72,7 +72,7 @@ class Simple_Uploader_Controller extends Controller { module::event("add_photos_form_completed", $item, $form); } } catch (Exception $e) { - Kohana::log("alert", $e->__toString()); + Kohana_Log::add("alert", $e->__toString()); if (file_exists($temp_filename)) { unlink($temp_filename); } diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php index 368c947e..e5eefad7 100644 --- a/modules/gallery/helpers/MY_url.php +++ b/modules/gallery/helpers/MY_url.php @@ -32,7 +32,7 @@ class url extends url_Core { } $item = self::get_item_from_uri(Router::$current_uri); - if ($item && $item->loaded) { + if ($item && $item->loaded()) { Router::$controller = "{$item->type}s"; Router::$controller_path = MODPATH . "gallery/controllers/{$item->type}s.php"; Router::$method = $item->id; @@ -51,7 +51,7 @@ class url extends url_Core { // but failing that, walk down the tree until we find it. The fallback code will fix caches // as it goes, so it'll never be run frequently. $item = ORM::factory("item")->where("relative_url_cache", $current_uri)->find(); - if (!$item->loaded) { + if (!$item->loaded()) { $count = count(Router::$segments); foreach (ORM::factory("item") ->where("slug", html_entity_decode(Router::$segments[$count - 1], ENT_QUOTES)) diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index c1c1f9d1..9d27181a 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -91,7 +91,7 @@ class access_Core { * @return boolean */ static function user_can($user, $perm_name, $item) { - if (!$item->loaded) { + if (!$item->loaded()) { return false; } @@ -101,7 +101,7 @@ class access_Core { $resource = $perm_name == "view" ? $item : model_cache::get("access_cache", $item->id, "item_id"); - foreach ($user->groups as $group) { + foreach ($user->groups->find_all() as $group) { if ($resource->__get("{$perm_name}_{$group->id}") === self::ALLOW) { return true; } @@ -175,7 +175,7 @@ class access_Core { ->limit(1) ->find(); - if ($lock->loaded) { + if ($lock->loaded()) { return $lock; } else { return null; @@ -201,7 +201,7 @@ class access_Core { if (!($group instanceof Group_Definition)) { throw new Exception("@todo PERMISSIONS_ONLY_WORK_ON_GROUPS"); } - if (!$album->loaded) { + if (!$album->loaded()) { throw new Exception("@todo INVALID_ALBUM $album->id"); } if (!$album->is_album()) { @@ -282,7 +282,7 @@ class access_Core { */ static function register_permission($name, $display_name) { $permission = ORM::factory("permission", $name); - if ($permission->loaded) { + if ($permission->loaded()) { throw new Exception("@todo PERMISSION_ALREADY_EXISTS $name"); } $permission->name = $name; @@ -305,7 +305,7 @@ class access_Core { self::_drop_columns($name, $group); } $permission = ORM::factory("permission")->where("name", $name)->find(); - if ($permission->loaded) { + if ($permission->loaded()) { $permission->delete(); } } @@ -342,7 +342,7 @@ class access_Core { */ static function add_item($item) { $access_intent = ORM::factory("access_intent", $item->id); - if ($access_intent->loaded) { + if ($access_intent->loaded()) { throw new Exception("@todo ITEM_ALREADY_ADDED $item->id"); } $access_intent = ORM::factory("access_intent"); @@ -497,7 +497,7 @@ class access_Core { ->orderby("left_ptr", "DESC") ->limit(1) ->find(); - if ($tmp_item->loaded) { + if ($tmp_item->loaded()) { $item = $tmp_item; } } @@ -568,7 +568,7 @@ class access_Core { ->orderby("left_ptr", "DESC") ->limit(1) ->find(); - if ($tmp_item->loaded) { + if ($tmp_item->loaded()) { $item = $tmp_item; } } diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index 72a79a75..c82a5509 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -34,7 +34,7 @@ class album_Core { * @return Item_Model */ static function create($parent, $name, $title, $description=null, $owner_id=null, $slug=null) { - if (!$parent->loaded || !$parent->is_album()) { + if (!$parent->loaded() || !$parent->is_album()) { throw new Exception("@todo INVALID_PARENT"); } diff --git a/modules/gallery/helpers/auth.php b/modules/gallery/helpers/auth.php index 9c69cecd..21a39bfb 100644 --- a/modules/gallery/helpers/auth.php +++ b/modules/gallery/helpers/auth.php @@ -46,7 +46,7 @@ class auth_Core { try { Session::instance()->destroy(); } catch (Exception $e) { - Kohana::log("error", $e); + Kohana_Log::add("error", $e); } module::event("user_logout", $user); } diff --git a/modules/gallery/helpers/gallery_graphics.php b/modules/gallery/helpers/gallery_graphics.php index c24d2bde..ce08bbd7 100644 --- a/modules/gallery/helpers/gallery_graphics.php +++ b/modules/gallery/helpers/gallery_graphics.php @@ -123,7 +123,7 @@ class gallery_graphics_Core { module::event("graphics_composite_completed", $input_file, $output_file, $options); } catch (ErrorException $e) { - Kohana::log("error", $e->get_message()); + Kohana_Log::add("error", $e->get_message()); } } } diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index e0b03682..4d6de3ba 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -66,7 +66,7 @@ class gallery_task_Core { } $item = ORM::factory("item", $row->id); - if ($item->loaded) { + if ($item->loaded()) { try { graphics::generate($item); $completed++; diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index d6a2f00c..a78cadd0 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -171,7 +171,7 @@ class graphics_Core { } catch (Exception $e) { // Something went wrong rebuilding the image. Leave it dirty and move on. // @todo we should handle this better. - Kohana::log("error", "Caught exception rebuilding image: {$item->title}\n" . + Kohana_Log::add("error", "Caught exception rebuilding image: {$item->title}\n" . $e->getMessage() . "\n" . $e->getTraceAsString()); throw $e; } diff --git a/modules/gallery/helpers/identity.php b/modules/gallery/helpers/identity.php index 72e3312d..05614559 100644 --- a/modules/gallery/helpers/identity.php +++ b/modules/gallery/helpers/identity.php @@ -75,14 +75,14 @@ class identity_Core { if (!$session->get("group_ids")) { $ids = array(); - foreach ($user->groups as $group) { + foreach ($user->groups->find_all() as $group) { $ids[] = $group->id; } $session->set("group_ids", $ids); } } catch (Exception $e) { // Log it, so we at least have so notification that we swallowed the exception. - Kohana::log("error", "Load_user Exception: " . $e->__toString()); + Kohana_Log::add("error", "Load_user Exception: " . $e->__toString()); try { Session::instance()->destroy(); } catch (Exception $e) { 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; } diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index 3460cc65..aaf6ff46 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -136,7 +136,7 @@ class l10n_client_Core { $entry = ORM::factory("incoming_translation") ->where(array("key" => $key, "locale" => $locale)) ->find(); - if (!$entry->loaded) { + if (!$entry->loaded()) { // @todo Load a message key -> message (text) dict into memory outside of this loop $root_entry = ORM::factory("incoming_translation") ->where(array("key" => $key, "locale" => "root")) diff --git a/modules/gallery/helpers/l10n_scanner.php b/modules/gallery/helpers/l10n_scanner.php index e36d419d..6c09a686 100644 --- a/modules/gallery/helpers/l10n_scanner.php +++ b/modules/gallery/helpers/l10n_scanner.php @@ -43,7 +43,7 @@ class l10n_scanner_Core { } $entry = ORM::factory("incoming_translation", array("key" => $key)); - if (!$entry->loaded) { + if (!$entry->loaded()) { $entry->key = $key; $entry->message = serialize($message); $entry->locale = "root"; diff --git a/modules/gallery/helpers/model_cache.php b/modules/gallery/helpers/model_cache.php index a3e09862..302e42d9 100644 --- a/modules/gallery/helpers/model_cache.php +++ b/modules/gallery/helpers/model_cache.php @@ -22,8 +22,8 @@ class model_cache_Core { static function get($model_name, $id, $field_name="id") { if (TEST_MODE || empty(self::$cache->$model_name->$field_name->$id)) { - $model = ORM::factory($model_name)->where($field_name, $id)->find(); - if (!$model->loaded) { + $model = ORM::factory($model_name)->where($field_name, "=", $id)->find(); + if (!$model->loaded()) { throw new Exception("@todo MISSING_MODEL $model_name:$id"); } self::$cache->$model_name->$field_name->$id = $model; diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index e6c196ce..e54a4352 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -36,13 +36,13 @@ class module_Core { */ static function set_version($module_name, $version) { $module = self::get($module_name); - if (!$module->loaded) { + if (!$module->loaded()) { $module->name = $module_name; $module->active = $module_name == "gallery"; // only gallery is active by default } $module->version = $version; $module->save(); - Kohana::log("debug", "$module_name: version is now $version"); + Kohana_Log::add("debug", "$module_name: version is now $version"); } /** @@ -126,9 +126,10 @@ class module_Core { * @param string $module_name */ static function install($module_name) { - $kohana_modules = Kohana::config("core.modules"); + $config = Kohana_Config::instance(); + $kohana_modules = $config->get("core.modules"); array_unshift($kohana_modules, MODPATH . $module_name); - Kohana::config_set("core.modules", $kohana_modules); + $config->set("core.modules", $kohana_modules); // Rebuild the include path so the module installer can benefit from auto loading Kohana::include_paths(true); @@ -142,7 +143,7 @@ class module_Core { // Now the module is installed but inactive, so don't leave it in the active path array_shift($kohana_modules); - Kohana::config_set("core.modules", $kohana_modules); + $config->set("core.modules", $kohana_modules); log::success( "module", t("Installed module %module_name", array("module_name" => $module_name))); @@ -193,9 +194,10 @@ class module_Core { * @param string $module_name */ static function activate($module_name) { - $kohana_modules = Kohana::config("core.modules"); + $config = Kohana_Config::instance(); + $kohana_modules = $config->get("core.modules"); array_unshift($kohana_modules, MODPATH . $module_name); - Kohana::config_set("core.modules", $kohana_modules); + $config->set("core.modules", $kohana_modules); $installer_class = "{$module_name}_installer"; if (method_exists($installer_class, "activate")) { @@ -203,7 +205,7 @@ class module_Core { } $module = self::get($module_name); - if ($module->loaded) { + if ($module->loaded()) { $module->active = true; $module->save(); } @@ -230,7 +232,7 @@ class module_Core { } $module = self::get($module_name); - if ($module->loaded) { + if ($module->loaded()) { $module->active = false; $module->save(); } @@ -257,7 +259,7 @@ class module_Core { graphics::remove_rules($module_name); $module = self::get($module_name); - if ($module->loaded) { + if ($module->loaded()) { $module->delete(); } module::load_modules(); @@ -290,8 +292,9 @@ class module_Core { } } self::$active[] = $gallery; // put gallery last in the module list to match core.modules - Kohana::config_set( - "core.modules", array_merge($kohana_modules, Kohana::config("core.modules"))); + $config = Kohana_Config::instance(); + $config->set( + "core.modules", array_merge($kohana_modules, $config->get("core.modules"))); } /** @@ -348,11 +351,11 @@ class module_Core { // We cache all vars in gallery._cache so that we can load all vars at once for // performance. if (empty(self::$var_cache)) { - $row = Database::instance() + $row = db::build() ->select("value") ->from("vars") ->where(array("module_name" => "gallery", "name" => "_cache")) - ->get() + ->execute() ->current(); if ($row) { self::$var_cache = unserialize($row->value); @@ -395,7 +398,7 @@ class module_Core { ->where("module_name", $module_name) ->where("name", $name) ->find(); - if (!$var->loaded) { + if (!$var->loaded()) { $var->module_name = $module_name; $var->name = $name; } @@ -432,7 +435,7 @@ class module_Core { ->where("module_name", $module_name) ->where("name", $name) ->find(); - if ($var->loaded) { + if ($var->loaded()) { $var->delete(); } diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index e84e8ea6..a319471d 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -36,7 +36,7 @@ class movie_Core { */ static function create($parent, $filename, $name, $title, $description=null, $owner_id=null, $slug=null) { - if (!$parent->loaded || !$parent->is_album()) { + if (!$parent->loaded() || !$parent->is_album()) { throw new Exception("@todo INVALID_PARENT"); } diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 01cf5278..90cb108f 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -36,7 +36,7 @@ class photo_Core { */ static function create($parent, $filename, $name, $title, $description=null, $owner_id=null, $slug=null) { - if (!$parent->loaded || !$parent->is_album()) { + if (!$parent->loaded() || !$parent->is_album()) { throw new Exception("@todo INVALID_PARENT"); } diff --git a/modules/gallery/helpers/site_status.php b/modules/gallery/helpers/site_status.php index 2b090776..d58b935d 100644 --- a/modules/gallery/helpers/site_status.php +++ b/modules/gallery/helpers/site_status.php @@ -69,7 +69,7 @@ class site_status_Core { $message = ORM::factory("message") ->where("key", $permanent_key) ->find(); - if (!$message->loaded) { + if (!$message->loaded()) { $message->key = $permanent_key; } $message->severity = $severity; @@ -83,7 +83,7 @@ class site_status_Core { */ static function clear($permanent_key) { $message = ORM::factory("message")->where("key", $permanent_key)->find(); - if ($message->loaded) { + if ($message->loaded()) { $message->delete(); } } diff --git a/modules/gallery/helpers/task.php b/modules/gallery/helpers/task.php index dac5f9d3..4aa95f33 100644 --- a/modules/gallery/helpers/task.php +++ b/modules/gallery/helpers/task.php @@ -51,7 +51,7 @@ class task_Core { static function cancel($task_id) { $task = ORM::factory("task", $task_id); - if (!$task->loaded) { + if (!$task->loaded()) { throw new Exception("@todo MISSING_TASK"); } $task->done = 1; @@ -65,14 +65,14 @@ class task_Core { static function remove($task_id) { $task = ORM::factory("task", $task_id); - if ($task->loaded) { + if ($task->loaded()) { $task->delete(); } } static function run($task_id) { $task = ORM::factory("task", $task_id); - if (!$task->loaded) { + if (!$task->loaded()) { throw new Exception("@todo MISSING_TASK"); } @@ -84,7 +84,7 @@ class task_Core { } $task->save(); } catch (Exception $e) { - Kohana::log("error", $e->__toString()); + Kohana_Log::add("error", $e->__toString()); $task->log($e->__toString()); $task->state = "error"; $task->done = true; diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index 16ed104e..c7a9b49a 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -43,7 +43,7 @@ class theme_Core { } $modules = Kohana::config("core.modules"); array_unshift($modules, THEMEPATH . $theme_name); - Kohana::config_set("core.modules", $modules); + Kohana_Config::instance()->set("core.modules", $modules); } static function get_edit_form_admin() { diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index cbb781a1..c190f110 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -31,7 +31,7 @@ class Admin_View_Core extends Gallery_View { if (!file_exists(THEMEPATH . $theme_name)) { module::set_var("gallery", "active_admin_theme", "admin_wind"); theme::load_themes(); - Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme."); + Kohana_Log::add("error", "Unable to locate theme '$theme_name', switching to default theme."); } parent::__construct($name); diff --git a/modules/gallery/libraries/Gallery_I18n.php b/modules/gallery/libraries/Gallery_I18n.php index 0571fe58..42fae266 100644 --- a/modules/gallery/libraries/Gallery_I18n.php +++ b/modules/gallery/libraries/Gallery_I18n.php @@ -128,21 +128,21 @@ class Gallery_I18n_Core { if (!isset($this->_cache[$locale])) { $this->_cache[$locale] = array(); // TODO: Load data from locale file instead of the DB. - foreach (Database::instance() + foreach (db::build() ->select("key", "translation") ->from("incoming_translations") ->where(array("locale" => $locale)) - ->get() + ->execute() ->as_array() as $row) { $this->_cache[$locale][$row->key] = unserialize($row->translation); } // Override incoming with outgoing... - foreach (Database::instance() + foreach (db::build() ->select("key", "translation") ->from("outgoing_translations") ->where(array("locale" => $locale)) - ->get() + ->execute() ->as_array() as $row) { $this->_cache[$locale][$row->key] = unserialize($row->translation); } diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php index 3bf56d0f..940c5321 100644 --- a/modules/gallery/libraries/Gallery_View.php +++ b/modules/gallery/libraries/Gallery_View.php @@ -32,7 +32,7 @@ class Gallery_View_Core extends View { if (($path = gallery::find_file("js", $file, false))) { $this->scripts[$path] = 1; } else { - Kohana::log("error", "Can't find script file: $file"); + Kohana_Log::add("error", "Can't find script file: $file"); } } @@ -55,7 +55,7 @@ class Gallery_View_Core extends View { if (($path = gallery::find_file("css", $file, false))) { $this->css[$path] = 1; } else { - Kohana::log("error", "Can't find css file: $file"); + Kohana_Log::add("error", "Can't find css file: $file"); } } @@ -130,7 +130,7 @@ class Gallery_View_Core extends View { $search[] = $match[0]; $replace[] = "url('" . url::abs_file($relative) . "')"; } else { - Kohana::log("error", "Missing URL reference '{$match[1]}' in CSS file '$css_file'"); + Kohana_Log::add("error", "Missing URL reference '{$match[1]}' in CSS file '$css_file'"); } } $replace = str_replace(DIRECTORY_SEPARATOR, "/", $replace); diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php index e213ae97..bcb3056a 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -54,7 +54,7 @@ class IdentityProvider_Core { */ static function reset() { self::$instance = null; - Kohana::config_clear("identity"); + Kohana_Config::instance()->clear("identity"); } /** @@ -90,7 +90,7 @@ class IdentityProvider_Core { get_class($this), "IdentityProvider_Driver"); } - Kohana::log("debug", "Identity Library initialized"); + Kohana_Log::add("debug", "Identity Library initialized"); } /** diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php index 2c9ad1d7..56c776aa 100644 --- a/modules/gallery/libraries/MY_ORM.php +++ b/modules/gallery/libraries/MY_ORM.php @@ -21,16 +21,6 @@ class ORM extends ORM_Core { // Track the original value of this ORM so that we can look it up in ORM::original() protected $original = null; - public function open_paren() { - $this->db->open_paren(); - return $this; - } - - public function close_paren() { - $this->db->close_paren(); - return $this; - } - public function save() { model_cache::clear(); $result = parent::save(); diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php index eb55aca6..0311f2dd 100644 --- a/modules/gallery/libraries/MY_View.php +++ b/modules/gallery/libraries/MY_View.php @@ -18,6 +18,31 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class View extends View_Core { + static $global_data; + + /** + * Reimplement Kohana 2.3's View::set_global() functionality. + */ + public function set_global($key, $value) { + View::$global_data->$key = $value; + $this->$key = $value; + } + + public function __isset($key) { + if (isset(View::$global_data->$key)) { + return true; + } + return parent::__isset($key); + } + + public function &__get($key) { + Kohana_Log::add("error",print_r("__get($key)",1)); + if (isset(View::$global_data->$key)) { + return View::$global_data->$key; + } + return parent::__get($key); + } + /** * Override View_Core::__construct so that we can set the csrf value into all views. * @@ -38,7 +63,7 @@ class View extends View_Core { try { return parent::render($print, $renderer); } catch (Exception $e) { - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); return ""; } } diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index 83d2445c..01b2d7b7 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -133,10 +133,10 @@ class ORM_MPTT_Core extends ORM { */ function parents() { return $this - ->where("`left_ptr` <= {$this->left_ptr}") - ->where("`right_ptr` >= {$this->right_ptr}") - ->where("id <> {$this->id}") - ->orderby("left_ptr", "ASC") + ->where("left_ptr", "<=", $this->left_ptr) + ->where("right_ptr", ">=", $this->right_ptr) + ->where("id", "<>", $this->id) + ->order_by("left_ptr", "ASC") ->find_all(); } @@ -147,14 +147,17 @@ class ORM_MPTT_Core extends ORM { * @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=array("id" => "ASC")) { + function children($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) { + if ($where) { + $this->where($where); + } + return $this - ->where("parent_id", $this->id) - ->where($where) - ->orderby($orderby) + ->where("parent_id", "=", $this->id) + ->order_by($order_by) ->find_all($limit, $offset); } @@ -165,10 +168,13 @@ class ORM_MPTT_Core extends ORM { * @param array additional where clauses * @return array ORM */ - function children_count($where=array()) { + function children_count($where=null) { + if ($where) { + $this->where($where); + } + return $this - ->where($where) - ->where("parent_id", $this->id) + ->where("parent_id", "=", $this->id) ->count_all(); } @@ -178,15 +184,18 @@ class ORM_MPTT_Core extends ORM { * @param integer SQL limit * @param integer SQL offset * @param array additional where clauses - * @param array orderby + * @param array order_by * @return object ORM_Iterator */ - function descendants($limit=null, $offset=0, $where=array(), $orderby=array("id" => "ASC")) { + function descendants($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) { + if ($where) { + $this->where($where); + } + return $this - ->where("left_ptr >", $this->left_ptr) - ->where("right_ptr <=", $this->right_ptr) - ->where($where) - ->orderby($orderby) + ->where("left_ptr", ">", $this->left_ptr) + ->where("right_ptr", "<=", $this->right_ptr) + ->order_by($order_by) ->find_all($limit, $offset); } @@ -196,11 +205,14 @@ class ORM_MPTT_Core extends ORM { * @param array additional where clauses * @return integer child count */ - function descendants_count($where=array()) { + function descendants_count($where=null) { + if ($where) { + $this->where($where); + } + return $this - ->where("left_ptr >", $this->left_ptr) - ->where("right_ptr <=", $this->right_ptr) - ->where($where) + ->where("left_ptr", ">", $this->left_ptr) + ->where("right_ptr", "<=", $this->right_ptr) ->count_all(); } diff --git a/modules/gallery/libraries/SafeString.php b/modules/gallery/libraries/SafeString.php index ba3a8ffd..cc63f3a7 100644 --- a/modules/gallery/libraries/SafeString.php +++ b/modules/gallery/libraries/SafeString.php @@ -146,7 +146,7 @@ class SafeString_Core { * Escape special HTML chars ("<", ">", "&", etc.) to HTML entities. */ private static function _escape_for_html($dirty_html) { - return html::specialchars($dirty_html); + return html::chars($dirty_html); } /** diff --git a/modules/gallery/libraries/Sendmail.php b/modules/gallery/libraries/Sendmail.php index 7bc21a67..aa2b51a9 100644 --- a/modules/gallery/libraries/Sendmail.php +++ b/modules/gallery/libraries/Sendmail.php @@ -52,7 +52,7 @@ class Sendmail_Core { break; case "header": if (count($value) != 2) { - Kohana::log("error", wordwrap("Invalid header parameters\n" . Kohana::debug($value))); + Kohana_Log::add("error", wordwrap("Invalid header parameters\n" . Kohana::debug($value))); throw new Exception("@todo INVALID_HEADER_PARAMETERS"); } $this->headers[$value[0]] = $value[1]; @@ -71,7 +71,7 @@ class Sendmail_Core { public function send() { if (empty($this->to)) { - Kohana::log("error", wordwrap("Sending mail failed:\nNo to address specified")); + Kohana_Log::add("error", wordwrap("Sending mail failed:\nNo to address specified")); throw new Exception("@todo TO_IS_REQUIRED_FOR_MAIL"); } $to = implode(", ", $this->to); diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index b64deab9..03f67671 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -33,7 +33,7 @@ class Theme_View_Core extends Gallery_View { if (!file_exists(THEMEPATH . $theme_name)) { module::set_var("gallery", "active_site_theme", "wind"); theme::load_themes(); - Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme."); + Kohana_Log::add("error", "Unable to locate theme '$theme_name', switching to default theme."); } parent::__construct($name); diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index 7e2aeabc..d27bcc32 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -20,22 +20,10 @@ /* * Based on the Cache_Sqlite_Driver developed by the Kohana Team */ -class Cache_Database_Driver implements Cache_Driver { +class Cache_Database_Driver extends Cache_Driver { // Kohana database instance protected $db; - /** - * Tests that the storage location is a directory and is writable. - */ - public function __construct() { - // Open up an instance of the database - $this->db = Database::instance(); - - if (!$this->db->table_exists("caches")) { - throw new Exception("@todo Cache table is not defined"); - } - } - /** * Checks if a cache id is already set. * @@ -43,20 +31,22 @@ class Cache_Database_Driver implements Cache_Driver { * @return boolean */ public function exists($id) { - $count = $this->db->count_records("caches", array("key" => $id, "expiration >=" => time())); + $count = db::build() + ->where("key", "=", $id) + ->where("expiration", ">=", "time()") + ->count_records("caches"); return $count > 0; } /** * Sets a cache item to the given data, tags, and lifetime. * - * @param string cache id to set - * @param string data in the cache + * @param array assoc array of key => value pairs * @param array cache tags * @param integer lifetime * @return bool */ - public function set($id, $data, array $tags = NULL, $lifetime) { + public function set($items, $tags=null, $lifetime=null) { if (!empty($tags)) { // Escape the tags, adding brackets so the tag can be explicitly matched $tags = "<" . implode(">,<", $tags) . ">"; @@ -69,46 +59,46 @@ class Cache_Database_Driver implements Cache_Driver { $lifetime += time(); } - if ($this->exists($id)) { - $status = $this->db->update( - "caches", - array("tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data)), array("key" => $id)); - } else { - $status = $this->db->insert( - "caches", - array("key" => $id, "tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data))); + foreach ($items as $id => $data) { + if ($this->exists($id)) { + $status = db::build()->update( + "caches", + array("tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data)), + array("key", "=", $id)); + } else { + $status = db::build()->insert( + "caches", + array("key" => $id, "tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data))); + } } - return count($status) > 0; + return true; } /** - * Finds an array of ids for a given tag. - * - * @param string tag name - * @return array of ids that match the tag + * Get cache items by tag + * @param array cache tags + * @return array cached data */ - public function find($tag) { - $db_result = $this->db->from("caches") - ->like("tags", "<$tag>") - ->get() - ->result(true); + public function get_tag($tags) { + $db = db::build()->from("caches"); + foreach ($tags as $tag) { + $db->where("tags", "like", "<$tag>"); + } + $db_result = $db->execute()->as_array(); // An array will always be returned $result = array(); + // Disable notices for unserializing + $ER = error_reporting(~E_NOTICE); if ($db_result->count() > 0) { - // Disable notices for unserializing - $ER = error_reporting(~E_NOTICE); - foreach ($db_result as $row) { // Add each cache to the array $result[$row->key] = unserialize($row->cache); } - - // Turn notices back on - error_reporting($ER); } + error_reporting($ER); return $result; } @@ -120,9 +110,13 @@ class Cache_Database_Driver implements Cache_Driver { * @param string cache id * @return mixed|NULL */ - public function get($id) { + public function get($keys, $single=false) { $data = null; - $result = $this->db->getwhere("caches", array("key" => $id)); + $result = db::build() + ->from("caches") + ->where("key", "IN", $keys) + ->select() + ->execute(); if (count($result) > 0) { $cache = $result->current(); @@ -168,6 +162,13 @@ class Cache_Database_Driver implements Cache_Driver { return count($status) > 0; } + /** + * Delete cache items by tag + */ + public function delete_tag($tags) { + return $this->delete($tags, true); + } + /** * Deletes all cache files that are older than the current time. */ @@ -180,4 +181,10 @@ class Cache_Database_Driver implements Cache_Driver { return count($status) > 0; } -} // End Cache Database Driver \ No newline at end of file + /** + * Empty the cache + */ + public function delete_all() { + db::build()->query("TRUNCATE {caches}"); + } +} \ No newline at end of file diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index d27e331b..bd1f9af5 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -309,7 +309,7 @@ class Item_Model extends ORM_MPTT { * @return string */ public function relative_path() { - if (!$this->loaded) { + if (!$this->loaded()) { return; } @@ -324,7 +324,7 @@ class Item_Model extends ORM_MPTT { * @return string */ public function relative_url() { - if (!$this->loaded) { + if (!$this->loaded()) { return; } @@ -383,7 +383,7 @@ class Item_Model extends ORM_MPTT { if (!empty($this->changed) && $significant_changes) { $this->updated = time(); - if (!$this->loaded) { + if (!$this->loaded()) { $this->created = $this->updated; $this->weight = item::get_max_weight(); } else { diff --git a/modules/gallery/models/log.php b/modules/gallery/models/log.php index c816a4a7..a2044325 100644 --- a/modules/gallery/models/log.php +++ b/modules/gallery/models/log.php @@ -28,7 +28,7 @@ class Log_Model extends ORM { try { return identity::lookup_user($this->user_id); } catch (Exception $e) { - Kohana::log("alert", "Unable to load user with id $this->user_id"); + Kohana_Log::add("alert", "Unable to load user with id $this->user_id"); return null; } } else { diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index e9e5cb26..d90d7ed6 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -106,15 +106,15 @@ class Access_Helper_Test extends Unit_Test_Case { $item = album::create($root, rand(), "test album"); // New rows exist - $this->assert_true(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded); - $this->assert_true(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded); + $this->assert_true(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded()); + $this->assert_true(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded()); // Delete the item $item->delete(); // Rows are gone - $this->assert_false(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded); - $this->assert_false(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded); + $this->assert_false(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded()); + $this->assert_false(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded()); } public function new_photos_inherit_parent_permissions_test() { diff --git a/modules/gallery/views/kohana_error_page.php b/modules/gallery/views/kohana_error_page.php index 0d8801e5..b9fdcc19 100644 --- a/modules/gallery/views/kohana_error_page.php +++ b/modules/gallery/views/kohana_error_page.php @@ -120,7 +120,7 @@ getTraceAsString(); ?> - + diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 9a40b0b9..d525e03e 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -38,7 +38,7 @@ class notification { ->where("item_id", $item->id) ->where("user_id", $user->id) ->find() - ->loaded; + ->loaded(); } static function add_watch($item, $user=null) { diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index 6b2df574..e6d09d74 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -25,8 +25,8 @@ class notification_event_Core { try { notification::send_item_updated($new); } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::item_updated() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::item_updated() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -34,8 +34,8 @@ class notification_event_Core { try { notification::send_item_add($item); } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::item_created() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::item_created() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -47,8 +47,8 @@ class notification_event_Core { notification::remove_watch($item); } } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::item_deleted() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::item_deleted() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -69,8 +69,8 @@ class notification_event_Core { notification::send_comment_published($comment); } } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::comment_created() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::comment_created() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -80,8 +80,8 @@ class notification_event_Core { notification::send_comment_published($new); } } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::comment_updated() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::comment_updated() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -91,8 +91,8 @@ class notification_event_Core { ->where("user_id", $user->id) ->delete_all(); } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::user_before_delete() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::user_before_delete() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -100,8 +100,8 @@ class notification_event_Core { try { notification::send_pending_notifications(); } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::batch_complete() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::batch_complete() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 8c3bd3ab..9d732c11 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -61,7 +61,7 @@ class search_Core { static function update($item) { $data = new ArrayObject(); $record = ORM::factory("search_record")->where("item_id", $item->id)->find(); - if (!$record->loaded) { + if (!$record->loaded()) { $record->item_id = $item->id; } diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 53a3d091..25961129 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -103,7 +103,7 @@ class Server_Add_Controller extends Admin_Controller { access::verify_csrf(); $task = ORM::factory("task", $task_id); - if (!$task->loaded || $task->owner_id != identity::active_user()->id) { + if (!$task->loaded() || $task->owner_id != identity::active_user()->id) { access::forbidden(); } @@ -216,7 +216,7 @@ class Server_Add_Controller extends Admin_Controller { // Look up the parent item for this entry. By now it should exist, but if none was // specified, then this belongs as a child of the current item. $parent_entry = ORM::factory("server_add_file", $entry->parent_id); - if (!$parent_entry->loaded) { + if (!$parent_entry->loaded()) { $parent = ORM::factory("item", $task->get("item_id")); } else { $parent = ORM::factory("item", $parent_entry->item_id); diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index 67587c2e..93b51814 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -35,7 +35,7 @@ class Admin_Tags_Controller extends Admin_Controller { public function form_delete($id) { $tag = ORM::factory("tag", $id); - if ($tag->loaded) { + if ($tag->loaded()) { print tag::get_delete_form($tag); } } @@ -44,7 +44,7 @@ class Admin_Tags_Controller extends Admin_Controller { access::verify_csrf(); $tag = ORM::factory("tag", $id); - if (!$tag->loaded) { + if (!$tag->loaded()) { kohana::show_404(); } @@ -68,7 +68,7 @@ class Admin_Tags_Controller extends Admin_Controller { public function form_rename($id) { $tag = ORM::factory("tag", $id); - if ($tag->loaded) { + if ($tag->loaded()) { print InPlaceEdit::factory($tag->name) ->action("admin/tags/rename/$id") ->render(); @@ -79,7 +79,7 @@ class Admin_Tags_Controller extends Admin_Controller { access::verify_csrf(); $tag = ORM::factory("tag", $id); - if (!$tag->loaded) { + if (!$tag->loaded()) { kohana::show_404(); } diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index feaf40c5..6ce18625 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -34,7 +34,7 @@ class tag_Core { } $tag = ORM::factory("tag")->where("name", $tag_name)->find(); - if (!$tag->loaded) { + if (!$tag->loaded()) { $tag->name = $tag_name; $tag->count = 0; $tag->save(); diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index a857a99d..6ee8e708 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -51,7 +51,7 @@ class tag_event_Core { try { tag::add($photo, $tag); } catch (Exception $e) { - Kohana::log("error", "Error adding tag: $tag\n" . + Kohana_Log::add("error", "Error adding tag: $tag\n" . $e->getMessage() . "\n" . $e->getTraceAsString()); } } diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php index de5d6c72..03017dc3 100644 --- a/modules/tag/helpers/tag_rss.php +++ b/modules/tag/helpers/tag_rss.php @@ -31,7 +31,7 @@ class tag_rss_Core { static function feed($feed_id, $offset, $limit, $id) { if ($feed_id == "tag") { $tag = ORM::factory("tag", $id); - if (!$tag->loaded) { + if (!$tag->loaded()) { Kohana::show_404(); } $feed->children = $tag->items($limit, $offset, "photo"); diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index b3284385..619e6e18 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -265,7 +265,7 @@ class Admin_Users_Controller extends Admin_Controller { if ($valid) { $new_name = $form->edit_group->inputs["name"]->value; $group = group::lookup_by_name($name); - if ($group->loaded) { + if ($group->loaded()) { $form->edit_group->inputs["name"]->add_error("in_use", 1); $valid = false; } diff --git a/modules/user/controllers/password.php b/modules/user/controllers/password.php index e18e76b6..8309d2cc 100644 --- a/modules/user/controllers/password.php +++ b/modules/user/controllers/password.php @@ -47,7 +47,7 @@ class Password_Controller extends Controller { $valid = $form->validate(); if ($valid) { $user = user::lookup_by_name($form->reset->inputs["name"]->value); - if (!$user->loaded || empty($user->email)) { + if (!$user->loaded() || empty($user->email)) { $form->reset->inputs["name"]->add_error("no_email", 1); $valid = false; } diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php index 3aaf1b11..1beaa1c2 100644 --- a/modules/user/helpers/group.php +++ b/modules/user/helpers/group.php @@ -32,7 +32,7 @@ class group_Core { */ static function create($name) { $group = ORM::factory("group")->where("name", $name)->find(); - if ($group->loaded) { + if ($group->loaded()) { throw new Exception("@todo GROUP_ALREADY_EXISTS $name"); } @@ -86,7 +86,7 @@ class group_Core { private static function _lookup_by_field($field_name, $value) { try { $user = model_cache::get("group", $value, $field_name); - if ($user->loaded) { + if ($user->loaded()) { return $user; } } catch (Exception $e) { diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php index f9f16da5..4ed9daee 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -45,7 +45,7 @@ class user_Core { */ static function create($name, $full_name, $password) { $user = ORM::factory("user")->where("name", $name)->find(); - if ($user->loaded) { + if ($user->loaded()) { throw new Exception("@todo USER_ALREADY_EXISTS $name"); } @@ -163,7 +163,7 @@ class user_Core { private static function _lookup_user_by_field($field_name, $value) { try { $user = model_cache::get("user", $value, $field_name); - if ($user->loaded) { + if ($user->loaded()) { return $user; } } catch (Exception $e) { diff --git a/modules/user/models/group.php b/modules/user/models/group.php index 4432fc69..81f779cf 100644 --- a/modules/user/models/group.php +++ b/modules/user/models/group.php @@ -34,7 +34,7 @@ class Group_Model extends ORM implements Group_Definition { } public function save() { - if (!$this->loaded) { + if (!$this->loaded()) { $created = 1; } parent::save(); diff --git a/modules/user/models/user.php b/modules/user/models/user.php index bd61def8..0d5a2bcd 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -62,7 +62,7 @@ class User_Model extends ORM implements User_Definition { } public function save() { - if (!$this->loaded) { + if (!$this->loaded()) { $created = 1; } parent::save(); diff --git a/modules/user/tests/User_Groups_Test.php b/modules/user/tests/User_Groups_Test.php index 3da8dd34..6aedfde5 100644 --- a/modules/user/tests/User_Groups_Test.php +++ b/modules/user/tests/User_Groups_Test.php @@ -22,14 +22,14 @@ class User_Groups_Test extends Unit_Test_Case { public function teardown() { try { $group = ORM::factory("group")->where("name", "user_groups_test")->find(); - if ($group->loaded) { + if ($group->loaded()) { $group->delete(); } } catch (Exception $e) { } try { $user = ORM::factory("user")->where("name", "user_groups_test")->find(); - if ($user->loaded) { + if ($user->loaded()) { $user->delete(); } } catch (Exception $e) { } -- cgit v1.2.3 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/comment/controllers/admin_comments.php | 4 +- modules/comment/helpers/comment_event.php | 6 +-- modules/comment/helpers/comment_rss.php | 4 +- modules/comment/helpers/comment_theme.php | 4 +- modules/comment/tests/Comment_Model_Test.php | 4 +- modules/exif/helpers/exif.php | 14 +++---- modules/exif/helpers/exif_task.php | 10 ++--- modules/exif/helpers/exif_theme.php | 2 +- modules/g2_import/helpers/g2_import.php | 2 +- modules/g2_import/helpers/g2_import_task.php | 2 +- modules/gallery/controllers/admin_maintenance.php | 6 +-- modules/gallery/controllers/albums.php | 12 +++--- modules/gallery/controllers/file_proxy.php | 4 +- modules/gallery/controllers/l10n_client.php | 6 +-- modules/gallery/controllers/move.php | 4 +- modules/gallery/controllers/movies.php | 10 ++--- modules/gallery/controllers/photos.php | 12 +++--- modules/gallery/helpers/MY_url.php | 6 +-- modules/gallery/helpers/access.php | 46 ++++++++++---------- modules/gallery/helpers/album.php | 10 ++--- modules/gallery/helpers/gallery_block.php | 8 ++-- modules/gallery/helpers/gallery_event.php | 12 +++--- modules/gallery/helpers/gallery_rss.php | 4 +- modules/gallery/helpers/graphics.php | 10 ++--- modules/gallery/helpers/l10n_client.php | 6 ++- modules/gallery/helpers/l10n_scanner.php | 2 +- modules/gallery/helpers/module.php | 11 ++--- modules/gallery/helpers/movie.php | 10 ++--- modules/gallery/helpers/photo.php | 10 ++--- modules/gallery/helpers/site_status.php | 4 +- modules/gallery/libraries/Gallery_I18n.php | 4 +- .../gallery/libraries/drivers/Cache/Database.php | 9 ++-- modules/gallery/models/item.php | 20 ++++----- modules/gallery/tests/Access_Helper_Test.php | 16 +++---- modules/gallery/tests/Cache_Test.php | 2 +- modules/gallery/tests/Database_Test.php | 49 +++++++++++----------- modules/gallery/tests/Gallery_Installer_Test.php | 2 +- modules/gallery/tests/I18n_Test.php | 4 +- modules/gallery/tests/Item_Helper_Test.php | 4 +- .../notification/helpers/notification_event.php | 4 +- modules/search/helpers/search.php | 10 ++--- modules/search/helpers/search_event.php | 2 +- modules/search/helpers/search_task.php | 4 +- modules/server_add/controllers/server_add.php | 8 ++-- modules/tag/controllers/admin_tags.php | 2 +- modules/tag/helpers/tag.php | 4 +- modules/tag/models/tag.php | 8 ++-- modules/tag/tests/Tag_Test.php | 6 +-- modules/user/helpers/group.php | 2 +- modules/user/helpers/user.php | 2 +- modules/user/tests/User_Groups_Test.php | 4 +- 51 files changed, 208 insertions(+), 203 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php index 039956d7..271c7d51 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -49,7 +49,7 @@ class Admin_Comments_Controller extends Admin_Controller { $view->content->state = $state; $view->content->comments = ORM::factory("comment") ->order_by("created", "DESC") - ->where("state", $state) + ->where("state", "=", $state) ->limit(self::$items_per_page, ($page - 1) * self::$items_per_page) ->find_all(); $view->content->pager = new Pagination(); @@ -120,7 +120,7 @@ class Admin_Comments_Controller extends Admin_Controller { access::verify_csrf(); ORM::factory("comment") - ->where("state", "spam") + ->where("state", "=", "spam") ->delete_all(); url::redirect("admin/comments/queue/spam"); } diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index a72102b9..cf5d0a60 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -29,7 +29,7 @@ class comment_event_Core { "guest_email" => null, "guest_name" => "guest", "guest_url" => null)) - ->where(array("author_id" => $user->id)) + ->where("author_id", "=", $user->id) ->update(); } @@ -40,7 +40,7 @@ class comment_event_Core { "guest_email" => null, "guest_name" => "guest", "guest_url" => null)) - ->where("1 = 1") + ->where("1", "=", "1") // @todo: why do we do this? ->update(); } @@ -65,7 +65,7 @@ class comment_event_Core { foreach (Database::instance() ->select("text") ->from("comments") - ->where("item_id", $item->id) + ->where("item_id", "=", $item->id) ->get() ->as_array() as $row) { $data[] = $row->text; diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php index d0bb7859..77044884 100644 --- a/modules/comment/helpers/comment_rss.php +++ b/modules/comment/helpers/comment_rss.php @@ -35,11 +35,11 @@ class comment_rss_Core { $comments = ORM::factory("comment") ->viewable() - ->where("state", "published") + ->where("state", "=", "published") ->order_by("created", "DESC"); if ($feed_id == "item") { - $comments->where("item_id", $id); + $comments->where("item_id", "=", $id); } $feed->view = "comment.mrss"; diff --git a/modules/comment/helpers/comment_theme.php b/modules/comment/helpers/comment_theme.php index 2f12192b..ebcc1c42 100644 --- a/modules/comment/helpers/comment_theme.php +++ b/modules/comment/helpers/comment_theme.php @@ -37,8 +37,8 @@ class comment_theme_Core { $view = new View("comments.html"); $view->comments = ORM::factory("comment") - ->where("item_id", $theme->item()->id) - ->where("state", "published") + ->where("item_id", "=", $theme->item()->id) + ->where("state", "=", "published") ->order_by("created", "ASC") ->find_all(); diff --git a/modules/comment/tests/Comment_Model_Test.php b/modules/comment/tests/Comment_Model_Test.php index de19648d..aa91d6f2 100644 --- a/modules/comment/tests/Comment_Model_Test.php +++ b/modules/comment/tests/Comment_Model_Test.php @@ -29,12 +29,12 @@ class Comment_Model_Test extends Unit_Test_Case { access::allow(identity::everybody(), "view", $album); $this->assert_equal( 1, - ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all()); + ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all()); // We can't see the comment when permissions are denied on the album access::deny(identity::everybody(), "view", $album); $this->assert_equal( 0, - ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all()); + ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all()); } } diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index b6a55679..b4241e89 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -73,7 +73,7 @@ class exif_Core { } $item->save(); - $record = ORM::factory("exif_record")->where("item_id", $item->id)->find(); + $record = ORM::factory("exif_record")->where("item_id", "=", $item->id)->find(); if (!$record->loaded()) { $record->item_id = $item->id; } @@ -86,7 +86,7 @@ class exif_Core { static function get($item) { $exif = array(); $record = ORM::factory("exif_record") - ->where("item_id", $item->id) + ->where("item_id", "=", $item->id) ->find(); if (!$record->loaded()) { return array(); @@ -143,11 +143,11 @@ class exif_Core { ->select("items.id") ->from("items") ->join("exif_records", "items.id", "exif_records.item_id", "left") - ->where("type", "photo") - ->open_paren() - ->where("exif_records.item_id", null) - ->orwhere("exif_records.dirty", 1) - ->close_paren() + ->where("type", "=", "photo") + ->and_open() + ->where("exif_records.item_id", "=", null) + ->orwhere("exif_records.dirty", "=", 1) + ->close() ->get() ->count(); diff --git a/modules/exif/helpers/exif_task.php b/modules/exif/helpers/exif_task.php index 7c4c97c4..1a449fc7 100644 --- a/modules/exif/helpers/exif_task.php +++ b/modules/exif/helpers/exif_task.php @@ -44,11 +44,11 @@ class exif_task_Core { $start = microtime(true); foreach (ORM::factory("item") ->join("exif_records", "items.id", "exif_records.item_id", "left") - ->where("type", "photo") - ->open_paren() - ->where("exif_records.item_id", null) - ->orwhere("exif_records.dirty", 1) - ->close_paren() + ->where("type", "=", "photo") + ->and_open() + ->where("exif_records.item_id", "=", null) + ->orwhere("exif_records.dirty", "=", 1) + ->close() ->find_all() as $item) { // The query above can take a long time, so start the timer after its done // to give ourselves a little time to actually process rows. diff --git a/modules/exif/helpers/exif_theme.php b/modules/exif/helpers/exif_theme.php index bb6926d3..db51f305 100644 --- a/modules/exif/helpers/exif_theme.php +++ b/modules/exif/helpers/exif_theme.php @@ -24,7 +24,7 @@ class exif_theme_Core { $record = Database::instance() ->select("key_count") ->from("exif_records") - ->where("item_id", $item->id) + ->where("item_id", "=", $item->id) ->get() ->current(); if ($record && $record->key_count) { diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 1e835a59..3cf7eb80 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -867,7 +867,7 @@ class g2_import_Core { */ static function map($g2_id) { if (!array_key_exists($g2_id, self::$map)) { - $g2_map = ORM::factory("g2_map")->where("g2_id", $g2_id)->find(); + $g2_map = ORM::factory("g2_map")->where("g2_id", "=", $g2_id)->find(); self::$map[$g2_id] = $g2_map->loaded() ? $g2_map->g3_id : null; } diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index fef0d186..e80b88b9 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -65,7 +65,7 @@ class g2_import_task_Core { $task->set("done", $done); $root_g2_id = g2(GalleryCoreApi::getDefaultAlbumId()); - $root = ORM::factory("g2_map")->where("g2_id", $root_g2_id)->find(); + $root = ORM::factory("g2_map")->where("g2_id", "=", $root_g2_id)->find(); if (!$root->loaded()) { $root->g2_id = $root_g2_id; $root->g3_id = 1; diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 3b896553..6377f40f 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)->order_by("updated", "DESC")->find_all(); + ->where("done", "=", 0)->order_by("updated", "DESC")->find_all(); $view->content->finished_tasks = ORM::factory("task") - ->where("done", 1)->order_by("updated", "DESC")->find_all(); + ->where("done", "=", 1)->order_by("updated", "DESC")->find_all(); print $view; } @@ -164,7 +164,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { // Do it the long way so we can call delete and remove the cache. $finished = ORM::factory("task") - ->where(array("done" => 1)) + ->where("done", "=", 1) ->find_all(); foreach ($finished as $task) { task::remove($task->id); diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 19140891..431d98a0 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -126,12 +126,12 @@ class Albums_Controller extends Items_Controller { if ($row = Database::instance() ->select(array("name", "slug")) ->from("items") - ->where("parent_id", $album->parent_id) - ->where("id <>", $album->id) - ->open_paren() - ->where("name", $form->edit_item->dirname->value) - ->orwhere("slug", $form->edit_item->slug->value) - ->close_paren() + ->where("parent_id", "=", $album->parent_id) + ->where("id", "<>", $album->id) + ->and_open() + ->where("name", "=", $form->edit_item->dirname->value) + ->orwhere("slug", "=", $form->edit_item->slug->value) + ->close() ->get() ->current()) { if ($row->name == $form->edit_item->dirname->value) { diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index 11d858c0..53afe0e4 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -57,7 +57,7 @@ class File_Proxy_Controller extends Controller { $path = preg_replace("|/.album.jpg$|", "", $path); // We now have the relative path to the item. Search for it in the path cache - $item = ORM::factory("item")->where("relative_path_cache", $path)->find(); + $item = ORM::factory("item")->where("relative_path_cache", "=", $path)->find(); if (!$item->loaded()) { // We didn't turn it up. It's possible that the relative_path_cache is out of date here. // There was fallback code, but bharat deleted it in 8f1bca74. If it turns out to be @@ -69,7 +69,7 @@ class File_Proxy_Controller extends Controller { if (preg_match('/.jpg$/', $path)) { foreach (array("flv", "mp4") as $ext) { $movie_path = preg_replace('/.jpg$/', ".$ext", $path); - $item = ORM::factory("item")->where("relative_path_cache", $movie_path)->find(); + $item = ORM::factory("item")->where("relative_path_cache", "=", $movie_path)->find(); if ($item->loaded()) { break; } diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php index 2eda741c..30a18631 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -116,7 +116,7 @@ class L10n_Client_Controller extends Controller { foreach (Database::instance() ->select("key", "message") ->from("incoming_translations") - ->where(array("locale" => 'root')) + ->where("locale", "=", "root")) ->get() ->as_array() as $row) { $calls[$row->key] = array(unserialize($row->message), array()); @@ -131,7 +131,7 @@ class L10n_Client_Controller extends Controller { foreach (Database::instance() ->select("key", "translation") ->from("incoming_translations") - ->where(array("locale" => $locale)) + ->where("locale", "=", $locale) ->get() ->as_array() as $row) { $translations[$row->key] = unserialize($row->translation); @@ -140,7 +140,7 @@ class L10n_Client_Controller extends Controller { foreach (Database::instance() ->select("key", "translation") ->from("outgoing_translations") - ->where(array("locale" => $locale)) + ->where("locale", "=", $locale) ->get() ->as_array() as $row) { $translations[$row->key] = unserialize($row->translation); diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php index 87b73436..863b13bb 100644 --- a/modules/gallery/controllers/move.php +++ b/modules/gallery/controllers/move.php @@ -64,8 +64,8 @@ class Move_Controller extends Controller { $view->parent = $target; $view->children = ORM::factory("item") ->viewable() - ->where("type", "album") - ->where("parent_id", $target->id) + ->where("type", "=", "album") + ->where("parent_id", "=", $target->id) ->find_all(); return $view; } diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 3d5eac32..7ceeefdf 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -74,12 +74,12 @@ class Movies_Controller extends Items_Controller { if ($row = Database::instance() ->select(array("name", "slug")) ->from("items") - ->where("parent_id", $movie->parent_id) + ->where("parent_id", "=", $movie->parent_id) ->where("id <>", $movie->id) - ->open_paren() - ->where("name", $form->edit_item->filename->value) - ->orwhere("slug", $form->edit_item->slug->value) - ->close_paren() + ->and_open() + ->where("name", "=", $form->edit_item->filename->value) + ->orwhere("slug", "=", $form->edit_item->slug->value) + ->close() ->get() ->current()) { if ($row->name == $form->edit_item->filename->value) { diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index f052eccd..0d7daac4 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -74,12 +74,12 @@ class Photos_Controller extends Items_Controller { if ($row = Database::instance() ->select(array("name", "slug")) ->from("items") - ->where("parent_id", $photo->parent_id) - ->where("id <>", $photo->id) - ->open_paren() - ->where("name", $form->edit_item->filename->value) - ->orwhere("slug", $form->edit_item->slug->value) - ->close_paren() + ->where("parent_id", "=", $photo->parent_id) + ->where("id", "<>", $photo->id) + ->and_open() + ->where("name", "=", $form->edit_item->filename->value) + ->orwhere("slug", "=", $form->edit_item->slug->value) + ->close() ->get() ->current()) { if ($row->name == $form->edit_item->filename->value) { diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php index e5eefad7..a2b2e461 100644 --- a/modules/gallery/helpers/MY_url.php +++ b/modules/gallery/helpers/MY_url.php @@ -50,12 +50,12 @@ class url extends url_Core { // In most cases, we'll have an exact match in the relative_url_cache item field. // but failing that, walk down the tree until we find it. The fallback code will fix caches // as it goes, so it'll never be run frequently. - $item = ORM::factory("item")->where("relative_url_cache", $current_uri)->find(); + $item = ORM::factory("item")->where("relative_url_cache", "=", $current_uri)->find(); if (!$item->loaded()) { $count = count(Router::$segments); foreach (ORM::factory("item") - ->where("slug", html_entity_decode(Router::$segments[$count - 1], ENT_QUOTES)) - ->where("level", $count + 1) + ->where("slug", "=", html_entity_decode(Router::$segments[$count - 1], ENT_QUOTES)) + ->where("level", "=", $count + 1) ->find_all() as $match) { if ($match->relative_url() == $current_uri) { $item = $match; diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index d0200a73..445f9b86 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -166,11 +166,11 @@ class access_Core { // For view permissions, if any parent is self::DENY, then those parents lock this one. // Return $lock = ORM::factory("item") - ->where("`left_ptr` <= $item->left_ptr") - ->where("`right_ptr` >= $item->right_ptr") - ->where("items.id <> $item->id") + ->where("left_ptr", "<=", $item->left_ptr) + ->where("right_ptr", ">=", $item->right_ptr) + ->where("items.id", "<>", $item->id) ->join("access_intents", "items.id", "access_intents.item_id") - ->where("access_intents.view_$group->id", self::DENY) + ->where("access_intents.view_$group->id", "=", self::DENY) ->order_by("level", "DESC") ->limit(1) ->find(); @@ -304,7 +304,7 @@ class access_Core { foreach (self::_get_all_groups() as $group) { self::_drop_columns($name, $group); } - $permission = ORM::factory("permission")->where("name", $name)->find(); + $permission = ORM::factory("permission")->where("name", "=", $name)->find(); if ($permission->loaded()) { $permission->delete(); } @@ -354,7 +354,7 @@ class access_Core { $access_cache->item_id = $item->id; if ($item->id != 1) { $parent_access_cache = - ORM::factory("access_cache")->where("item_id", $item->parent()->id)->find(); + ORM::factory("access_cache")->where("item_id", "=", $item->parent()->id)->find(); foreach (self::_get_all_groups() as $group) { foreach (ORM::factory("permission")->find_all() as $perm) { $field = "{$perm->name}_{$group->id}"; @@ -377,8 +377,8 @@ class access_Core { * @return void */ static function delete_item($item) { - ORM::factory("access_intent")->where("item_id", $item->id)->find()->delete(); - ORM::factory("access_cache")->where("item_id", $item->id)->find()->delete(); + ORM::factory("access_intent")->where("item_id", "=", $item->id)->find()->delete(); + ORM::factory("access_cache")->where("item_id", "=", $item->id)->find()->delete(); } /** @@ -475,7 +475,7 @@ class access_Core { * @return void */ private static function _update_access_view_cache($group, $item) { - $access = ORM::factory("access_intent")->where("item_id", $item->id)->find(); + $access = ORM::factory("access_intent")->where("item_id", "=", $item->id)->find(); $db = Database::instance(); $field = "view_{$group->id}"; @@ -490,10 +490,10 @@ class access_Core { // item, then its safe to propagate from here. if ($access->$field !== self::DENY) { $tmp_item = ORM::factory("item") - ->where("left_ptr <", $item->left_ptr) - ->where("right_ptr >", $item->right_ptr) + ->where("left_ptr", "<", $item->left_ptr) + ->where("right_ptr", ">", $item->right_ptr) ->join("access_intents", "access_intents.item_id", "items.id") - ->where("access_intents.$field", self::DENY) + ->where("access_intents.$field", "=", self::DENY) ->order_by("left_ptr", "DESC") ->limit(1) ->find(); @@ -512,10 +512,10 @@ class access_Core { $query = ORM::factory("access_intent") ->select(array("access_intents.$field", "items.left_ptr", "items.right_ptr", "items.id")) ->join("items", "items.id", "access_intents.item_id") - ->where("left_ptr >=", $item->left_ptr) - ->where("right_ptr <=", $item->right_ptr) - ->where("type", "album") - ->where("access_intents.$field IS NOT", self::INHERIT) + ->where("left_ptr", ">=", $item->left_ptr) + ->where("right_ptr", "<=", $item->right_ptr) + ->where("type", "=", "album") + ->where("access_intents.$field", "IS NOT", self::INHERIT) ->order_by("level", "DESC") ->find_all(); foreach ($query as $row) { @@ -549,7 +549,7 @@ class access_Core { * @return void */ private static function _update_access_non_view_cache($group, $perm_name, $item) { - $access = ORM::factory("access_intent")->where("item_id", $item->id)->find(); + $access = ORM::factory("access_intent")->where("item_id", "=", $item->id)->find(); $db = Database::instance(); $field = "{$perm_name}_{$group->id}"; @@ -562,9 +562,9 @@ class access_Core { if ($access->$field === self::INHERIT) { $tmp_item = ORM::factory("item") ->join("access_intents", "items.id", "access_intents.item_id") - ->where("left_ptr <", $item->left_ptr) - ->where("right_ptr >", $item->right_ptr) - ->where("$field IS NOT", self::UNKNOWN) + ->where("left_ptr", "<", $item->left_ptr) + ->where("right_ptr", ">", $item->right_ptr) + ->where($field, "IS NOT", self::UNKNOWN) ->order_by("left_ptr", "DESC") ->limit(1) ->find(); @@ -578,9 +578,9 @@ class access_Core { $query = ORM::factory("access_intent") ->select(array("access_intents.$field", "items.left_ptr", "items.right_ptr")) ->join("items", "items.id", "access_intents.item_id") - ->where("left_ptr >=", $item->left_ptr) - ->where("right_ptr <=", $item->right_ptr) - ->where("$field IS NOT", self::INHERIT) + ->where("left_ptr", ">=", $item->left_ptr) + ->where("right_ptr", "<=", $item->right_ptr) + ->where($field, "IS NOT", self::INHERIT) ->order_by("level", "ASC") ->find_all(); foreach ($query as $row) { diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index 84a60f83..cd8777e2 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -68,11 +68,11 @@ class album_Core { // Randomize the name or slug if there's a conflict // @todo Improve this. Random numbers are not user friendly while (ORM::factory("item") - ->where("parent_id", $parent->id) - ->open_paren() - ->where("name", $album->name) - ->orwhere("slug", $album->slug) - ->close_paren() + ->where("parent_id", "=", $parent->id) + ->and_open() + ->where("name", "=", $album->name) + ->orwhere("slug", "=", $album->slug) + ->close() ->find()->id) { $rand = rand(); $album->name = "{$name}-$rand"; diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index d09f1c80..40660874 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -45,8 +45,8 @@ class gallery_block_Core { $block->css_id = "g-photo-stream"; $block->title = t("Photo stream"); $block->content = new View("admin_block_photo_stream.html"); - $block->content->photos = - ORM::factory("item")->where("type", "photo")->order_by("created", "DESC")->find_all(10); + $block->content->photos = ORM::factory("item") + ->where("type", "=", "photo")->order_by("created", "DESC")->find_all(10); break; case "log_entries": @@ -62,8 +62,8 @@ class gallery_block_Core { $block->title = t("Gallery stats"); $block->content = new View("admin_block_stats.html"); $block->content->album_count = - ORM::factory("item")->where("type", "album")->where("id <>", 1)->count_all(); - $block->content->photo_count = ORM::factory("item")->where("type", "photo")->count_all(); + ORM::factory("item")->where("type", "=", "album")->where("id", "<>", 1)->count_all(); + $block->content->photo_count = ORM::factory("item")->where("type", "=", "photo")->count_all(); break; case "platform_info": 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(); } diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index e195be8d..93ace10b 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -29,13 +29,13 @@ class gallery_rss_Core { case "latest": $feed->children = ORM::factory("item") ->viewable() - ->where("type !=", "album") + ->where("type", "<>", "album") ->order_by("created", "DESC") ->find_all($limit, $offset); $all_children = ORM::factory("item") ->viewable() - ->where("type !=", "album") + ->where("type", "<>", "album") ->order_by("created", "DESC"); $feed->max_pages = ceil($all_children->find_all()->count() / $limit); diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index aef09003..e45a5125 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -61,9 +61,9 @@ class graphics_Core { */ static function remove_rule($module_name, $target, $operation) { ORM::factory("graphics_rule") - ->where("module_name", $module_name) - ->where("target", $target) - ->where("operation", $operation) + ->where("module_name", "=", $module_name) + ->where("target", "=", $target) + ->where("operation", "=", $operation) ->delete_all(); self::mark_dirty($target == "thumb", $target == "resize"); @@ -181,8 +181,8 @@ class graphics_Core { if (empty(self::$_rules_cache[$target])) { $rules = array(); foreach (ORM::factory("graphics_rule") - ->where("target", $target) - ->where("active", true) + ->where("target", "=", $target) + ->where("active", "=", true) ->order_by("priority", "asc") ->find_all() as $rule) { $rules[] = (object)$rule->as_array(); diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index aaf6ff46..14ab5a85 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -134,12 +134,14 @@ class l10n_client_Core { // incoming_translations.message to be NULL? $locale = $message_data->locale; $entry = ORM::factory("incoming_translation") - ->where(array("key" => $key, "locale" => $locale)) + ->where("key", "=", $key) + ->where("locale", "=", $locale) ->find(); if (!$entry->loaded()) { // @todo Load a message key -> message (text) dict into memory outside of this loop $root_entry = ORM::factory("incoming_translation") - ->where(array("key" => $key, "locale" => "root")) + ->where("key", "=", $key) + ->where("locale", "=", "root") ->find(); $entry->key = $key; $entry->message = $root_entry->message; diff --git a/modules/gallery/helpers/l10n_scanner.php b/modules/gallery/helpers/l10n_scanner.php index 6c09a686..a7ce2c59 100644 --- a/modules/gallery/helpers/l10n_scanner.php +++ b/modules/gallery/helpers/l10n_scanner.php @@ -31,7 +31,7 @@ class l10n_scanner_Core { foreach (Database::instance() ->select("key") ->from("incoming_translations") - ->where("locale", "root") + ->where("locale", "=", "root") ->get() as $row) { $cache[$row->key] = true; } diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index b7e13b9a..d89b8401 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -354,7 +354,8 @@ class module_Core { $row = db::build() ->select("value") ->from("vars") - ->where(array("module_name" => "gallery", "name" => "_cache")) + ->where("module_name", "=", "gallery") + ->where("name", "=", "_cache") ->execute() ->current(); if ($row) { @@ -395,8 +396,8 @@ class module_Core { */ static function set_var($module_name, $name, $value) { $var = ORM::factory("var") - ->where("module_name", $module_name) - ->where("name", $name) + ->where("module_name", "=", $module_name) + ->where("name", "=", $name) ->find(); if (!$var->loaded()) { $var->module_name = $module_name; @@ -432,8 +433,8 @@ class module_Core { */ static function clear_var($module_name, $name) { $var = ORM::factory("var") - ->where("module_name", $module_name) - ->where("name", $name) + ->where("module_name", "=", $module_name) + ->where("name", "=", $name) ->find(); if ($var->loaded()) { $var->delete(); diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index ff86403a..82247eb0 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -90,11 +90,11 @@ class movie_Core { // Randomize the name if there's a conflict // @todo Improve this. Random numbers are not user friendly while (ORM::factory("item") - ->where("parent_id", $parent->id) - ->open_paren() - ->where("name", $movie->name) - ->orwhere("slug", $movie->slug) - ->close_paren() + ->where("parent_id", "=", $parent->id) + ->and_open() + ->where("name", "=", $movie->name) + ->orwhere("slug", "=", $movie->slug) + ->close() ->find()->id) { $rand = rand(); $movie->name = "{$name}.$rand.{$pi['extension']}"; diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 21cb13a0..2a563043 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -89,11 +89,11 @@ class photo_Core { // Randomize the name or slug if there's a conflict // @todo Improve this. Random numbers are not user friendly while (ORM::factory("item") - ->where("parent_id", $parent->id) - ->open_paren() - ->where("name", $photo->name) - ->orwhere("slug", $photo->slug) - ->close_paren() + ->where("parent_id", "=", $parent->id) + ->and_open() + ->where("name", "=", $photo->name) + ->orwhere("slug", "=", $photo->slug) + ->close() ->find()->id) { $rand = rand(); $photo->name = "{$name}.$rand.{$pi['extension']}"; diff --git a/modules/gallery/helpers/site_status.php b/modules/gallery/helpers/site_status.php index d58b935d..04316fff 100644 --- a/modules/gallery/helpers/site_status.php +++ b/modules/gallery/helpers/site_status.php @@ -67,7 +67,7 @@ class site_status_Core { */ private static function _add($msg, $severity, $permanent_key) { $message = ORM::factory("message") - ->where("key", $permanent_key) + ->where("key", "=", $permanent_key) ->find(); if (!$message->loaded()) { $message->key = $permanent_key; @@ -82,7 +82,7 @@ class site_status_Core { * @param string $permanent_key */ static function clear($permanent_key) { - $message = ORM::factory("message")->where("key", $permanent_key)->find(); + $message = ORM::factory("message")->where("key", "=", $permanent_key)->find(); if ($message->loaded()) { $message->delete(); } diff --git a/modules/gallery/libraries/Gallery_I18n.php b/modules/gallery/libraries/Gallery_I18n.php index 42fae266..9a5e7dc1 100644 --- a/modules/gallery/libraries/Gallery_I18n.php +++ b/modules/gallery/libraries/Gallery_I18n.php @@ -131,7 +131,7 @@ class Gallery_I18n_Core { foreach (db::build() ->select("key", "translation") ->from("incoming_translations") - ->where(array("locale" => $locale)) + ->where("locale", "=", $locale) ->execute() ->as_array() as $row) { $this->_cache[$locale][$row->key] = unserialize($row->translation); @@ -141,7 +141,7 @@ class Gallery_I18n_Core { foreach (db::build() ->select("key", "translation") ->from("outgoing_translations") - ->where(array("locale" => $locale)) + ->where("locale", "=", $locale) ->execute() ->as_array() as $row) { $this->_cache[$locale][$row->key] = unserialize($row->translation); diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index eda445b6..a317798e 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -86,7 +86,7 @@ class Cache_Database_Driver extends Cache_Driver { public function get_tag($tags) { $db = db::build()->from("caches"); foreach ($tags as $tag) { - $db->where("tags", "like", "<$tag>"); + $db->where("tags", "LIKE", "<$tag>"); } $db_result = $db->execute()->as_array(); @@ -152,12 +152,12 @@ class Cache_Database_Driver extends Cache_Driver { public function delete($id, $tag = false) { $this->db->from("caches"); if ($id === true) { - $this->db->where(1); // Delete all caches + $this->db->where("1", "=", "1"); } else if ($tag === true) { $this->db->like("tags", "<$id>"); } else { - $this->db->where("key", $id); + $this->db->where("key", "=", $id); } $status = $this->db->delete(); @@ -178,7 +178,8 @@ class Cache_Database_Driver extends Cache_Driver { public function delete_expired() { // Delete all expired caches $status = $this->db->from("caches") - ->where(array("expiration !=" => 0, "expiration <=" => time())) + ->where("expiration", "<>", 0) + ->where("expiration", "<=", time()) ->delete(); return count($status) > 0; diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index c8386b1c..c8d25cc5 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -288,9 +288,9 @@ class Item_Model extends ORM_MPTT { foreach (Database::instance() ->select(array("name", "slug")) ->from("items") - ->where("left_ptr <=", $this->left_ptr) - ->where("right_ptr >=", $this->right_ptr) - ->where("id <>", 1) + ->where("left_ptr", "<=", $this->left_ptr) + ->where("right_ptr", ">=", $this->right_ptr) + ->where("id", "<>", 1) ->order_by("left_ptr", "ASC") ->get() as $row) { // Don't encode the names segment @@ -433,8 +433,8 @@ class Item_Model extends ORM_MPTT { // If the comparison column has NULLs in it, we can't use comparators on it and will have to // deal with it the hard way. $count = $db->from("items") - ->where("parent_id", $this->id) - ->where($this->sort_column, NULL) + ->where("parent_id", "=", $this->id) + ->where($this->sort_column, "=", NULL) ->where($where) ->count_records(); @@ -443,8 +443,8 @@ class Item_Model extends ORM_MPTT { $sort_column = $this->sort_column; $position = $db->from("items") - ->where("parent_id", $this->id) - ->where("$sort_column $comp ", $child->$sort_column) + ->where("parent_id", "=", $this->id) + ->where($sort_column, $comp, $child->$sort_column) ->where($where) ->count_records(); @@ -457,8 +457,8 @@ class Item_Model extends ORM_MPTT { // Fix this by doing a 2nd query where we iterate over the equivalent columns and add them to // our base value. foreach ($db->from("items") - ->where("parent_id", $this->id) - ->where($sort_column, $child->$sort_column) + ->where("parent_id", "=", $this->id) + ->where($sort_column, "=", $child->$sort_column) ->where($where) ->order_by(array("id" => "ASC")) ->get() as $row) { @@ -484,7 +484,7 @@ class Item_Model extends ORM_MPTT { $position = 0; foreach ($db->select("id") ->from("items") - ->where("parent_id", $this->id) + ->where("parent_id", "=", $this->id) ->where($where) ->order_by($order_by) ->get() as $row) { diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index d90d7ed6..771c6a85 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -106,15 +106,15 @@ class Access_Helper_Test extends Unit_Test_Case { $item = album::create($root, rand(), "test album"); // New rows exist - $this->assert_true(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded()); - $this->assert_true(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded()); + $this->assert_true(ORM::factory("access_cache")->where("item_id", "=", $item->id)->find()->loaded()); + $this->assert_true(ORM::factory("access_intent")->where("item_id", "=", $item->id)->find()->loaded()); // Delete the item $item->delete(); // Rows are gone - $this->assert_false(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded()); - $this->assert_false(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded()); + $this->assert_false(ORM::factory("access_cache")->where("item_id", "=", $item->id)->find()->loaded()); + $this->assert_false(ORM::factory("access_intent")->where("item_id", "=", $item->id)->find()->loaded()); } public function new_photos_inherit_parent_permissions_test() { @@ -131,7 +131,7 @@ class Access_Helper_Test extends Unit_Test_Case { public function can_allow_deny_and_reset_intent_test() { $root = ORM::factory("item", 1); $album = album::create($root, rand(), "test album"); - $intent = ORM::factory("access_intent")->where("item_id", $album)->find(); + $intent = ORM::factory("access_intent")->where("item_id", "=", $album)->find(); // Allow access::allow(identity::everybody(), "view", $album); @@ -141,19 +141,19 @@ class Access_Helper_Test extends Unit_Test_Case { access::deny(identity::everybody(), "view", $album); $this->assert_same( access::DENY, - ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); // Allow again. If the initial value was allow, then the first Allow clause above may not // have actually changed any values. access::allow(identity::everybody(), "view", $album); $this->assert_same( access::ALLOW, - ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); access::reset(identity::everybody(), "view", $album); $this->assert_same( null, - ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); } public function cant_reset_root_item_test() { diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php index 6b525265..776c6625 100644 --- a/modules/gallery/tests/Cache_Test.php +++ b/modules/gallery/tests/Cache_Test.php @@ -20,7 +20,7 @@ class Cache_Test extends Unit_Test_Case { private $_driver; public function setup() { - Database::instance()->from("caches")->where(1)->delete(); + Database::instance()->from("caches")->where("1", "=", "1")->delete(); $this->_driver = new Cache_Database_Driver(); } diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index 98bd4046..4f5a1da2 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -20,8 +20,8 @@ class Database_Test extends Unit_Test_Case { function simple_where_test() { $sql = Database::instance() - ->where("a", 1) - ->where("b", 2) + ->where("a", "=", 1) + ->where("b", "=", 2) ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same("SELECT * WHERE `a` = 1 AND `b` = 2", $sql); @@ -29,12 +29,12 @@ class Database_Test extends Unit_Test_Case { function compound_where_test() { $sql = Database::instance() - ->where("outer1", 1) - ->open_paren() - ->where("inner1", 1) - ->orwhere("inner2", 2) - ->close_paren() - ->where("outer2", 2) + ->where("outer1", "=", 1) + ->and_open() + ->where("inner1", "=", 1) + ->orwhere("inner2", "=", 2) + ->close() + ->where("outer2", "=", 2) ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( @@ -44,12 +44,12 @@ class Database_Test extends Unit_Test_Case { function group_first_test() { $sql = Database::instance() - ->open_paren() - ->where("inner1", 1) - ->orwhere("inner2", 2) - ->close_paren() - ->where("outer1", 1) - ->where("outer2", 2) + ->and_open() + ->where("inner1", "=", 1) + ->orwhere("inner2", "=", 2) + ->close() + ->where("outer1", "=", 1) + ->where("outer2", "=", 2) ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( @@ -59,11 +59,12 @@ class Database_Test extends Unit_Test_Case { function where_array_test() { $sql = Database::instance() - ->where("outer1", 1) - ->open_paren() - ->where("inner1", 1) - ->orwhere(array("inner2" => 2, "inner3" => 3)) - ->close_paren() + ->where("outer1", "=", 1) + ->and_open() + ->where("inner1", "=", 1) + ->orwhere("inner2", "=", 2) + ->orwhere("inner3", "=", 3)) + ->close() ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( @@ -73,10 +74,10 @@ class Database_Test extends Unit_Test_Case { function notlike_test() { $sql = Database::instance() - ->where("outer1", 1) - ->open_paren() - ->ornotlike("inner1", 1) - ->close_paren() + ->where("outer1", "=", 1) + ->or_open() + ->where("inner1", "NOT LIKE", 1) + ->close() ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( @@ -118,7 +119,7 @@ class Database_Test extends Unit_Test_Case { function prefix_no_replacement_test() { $update = Database_For_Test::instance()->from("test_tables") - ->where("1 = 1") + ->where("1", "=", "1") ->set(array("name" => "Test Name")) ->update(); diff --git a/modules/gallery/tests/Gallery_Installer_Test.php b/modules/gallery/tests/Gallery_Installer_Test.php index 36ced2bb..f36f638f 100644 --- a/modules/gallery/tests/Gallery_Installer_Test.php +++ b/modules/gallery/tests/Gallery_Installer_Test.php @@ -29,7 +29,7 @@ class Gallery_Installer_Test extends Unit_Test_Case { } public function install_registers_gallery_module_test() { - $gallery = ORM::factory("module")->where("name", "gallery")->find(); + $gallery = ORM::factory("module")->where("name", "=", "gallery")->find(); $this->assert_equal("gallery", $gallery->name); } diff --git a/modules/gallery/tests/I18n_Test.php b/modules/gallery/tests/I18n_Test.php index d0555cbf..895e3051 100644 --- a/modules/gallery/tests/I18n_Test.php +++ b/modules/gallery/tests/I18n_Test.php @@ -29,7 +29,7 @@ class Gallery_I18n_Test extends Unit_Test_Case { $this->i18n = Gallery_I18n::instance($config); ORM::factory("incoming_translation") - ->where("locale", "te_ST") + ->where("locale", "=", "te_ST") ->delete_all(); $messages_te_ST = array( @@ -62,7 +62,7 @@ class Gallery_I18n_Test extends Unit_Test_Case { $locale = $this->i18n->locale(); $this->assert_equal("de_DE", $locale); } - + public function translate_simple_test() { $result = $this->i18n->translate('Hello world'); $this->assert_equal('Hallo Welt', $result); diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index a364423a..f0c653c0 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -29,13 +29,13 @@ class Item_Helper_Test extends Unit_Test_Case { access::allow(identity::everybody(), "view", $album); $this->assert_equal( 1, - ORM::factory("item")->viewable()->where("id", $item->id)->count_all()); + ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all()); // We can't see the item when permissions are denied access::deny(identity::everybody(), "view", $album); $this->assert_equal( 0, - ORM::factory("item")->viewable()->where("id", $item->id)->count_all()); + ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all()); } public function validate_url_safe_test() { diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index e6d09d74..951e6e52 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -54,7 +54,7 @@ class notification_event_Core { static function user_deleted($user) { ORM::factory("subscriptions") - ->where(array("user_id", $user->id)) + ->where("user_id", "=", $user->id) ->delete_all(); } @@ -88,7 +88,7 @@ class notification_event_Core { static function user_before_delete($user) { try { ORM::factory("subscription") - ->where("user_id", $user->id) + ->where("user_id", "=", $user->id) ->delete_all(); } catch (Exception $e) { Kohana_Log::add("error", "@todo notification_event::user_before_delete() failed"); diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 9d732c11..c0bb1b32 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -60,7 +60,7 @@ class search_Core { static function update($item) { $data = new ArrayObject(); - $record = ORM::factory("search_record")->where("item_id", $item->id)->find(); + $record = ORM::factory("search_record")->where("item_id", "=", $item->id)->find(); if (!$record->loaded()) { $record->item_id = $item->id; } @@ -76,10 +76,10 @@ class search_Core { ->select("items.id") ->from("items") ->join("search_records", "items.id", "search_records.item_id", "left") - ->open_paren() - ->where("search_records.item_id", null) - ->orwhere("search_records.dirty", 1) - ->close_paren() + ->and_open() + ->where("search_records.item_id", "=", null) + ->orwhere("search_records.dirty", "=", 1) + ->close() ->get() ->count(); diff --git a/modules/search/helpers/search_event.php b/modules/search/helpers/search_event.php index 836bbe15..1add6e5f 100644 --- a/modules/search/helpers/search_event.php +++ b/modules/search/helpers/search_event.php @@ -28,7 +28,7 @@ class search_event_Core { static function item_deleted($item) { ORM::factory("search_record") - ->where("item_id", $item->id) + ->where("item_id", "=", $item->id) ->delete_all(); } diff --git a/modules/search/helpers/search_task.php b/modules/search/helpers/search_task.php index 9508f420..061f4084 100644 --- a/modules/search/helpers/search_task.php +++ b/modules/search/helpers/search_task.php @@ -45,8 +45,8 @@ class search_task_Core { $start = microtime(true); foreach (ORM::factory("item") ->join("search_records", "items.id", "search_records.item_id", "left") - ->where("search_records.item_id", null) - ->orwhere("search_records.dirty", 1) + ->where("search_records.item_id", "=", null) + ->orwhere("search_records.dirty", "=", 1) ->find_all() as $item) { // The query above can take a long time, so start the timer after its done // to give ourselves a little time to actually process rows. diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 053a1891..3c3a6c2b 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -177,7 +177,7 @@ class Server_Add_Controller extends Admin_Controller { $task->percent_complete = min($task->percent_complete + 0.1, 10); $task->status = t2("Found one file", "Found %count files", Database::instance() - ->where("task_id", $task->id) + ->where("task_id", "=", $task->id) ->count_records("server_add_files")); if (!$queue) { @@ -197,8 +197,8 @@ class Server_Add_Controller extends Admin_Controller { // will create albums first. Ignore entries which already have an Item_Model attached, // they're done. $entries = ORM::factory("server_add_file") - ->where("task_id", $task->id) - ->where("item_id", null) + ->where("task_id", "=", $task->id) + ->where("item_id", "=", null) ->order_by("id", "ASC") ->limit(10) ->find_all(); @@ -265,7 +265,7 @@ class Server_Add_Controller extends Admin_Controller { $task->done = true; $task->state = "success"; $task->percent_complete = 100; - ORM::factory("server_add_file")->where("task_id", $task->id)->delete_all(); + ORM::factory("server_add_file")->where("task_id", "=", $task->id)->delete_all(); message::info(t2("Successfully added one photo / album", "Successfully added %count photos / albums", $task->get("completed_files"))); diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index aff44803..6cd2f337 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -106,7 +106,7 @@ class Admin_Tags_Controller extends Admin_Controller { } public function check_for_duplicate(Validation $post_data, $field) { - $tag_exists = ORM::factory("tag")->where("name", $post_data[$field])->count_all(); + $tag_exists = ORM::factory("tag")->where("name", "=", $post_data[$field])->count_all(); if ($tag_exists) { $post_data->add_error($field, "in_use"); } diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 8694bcec..c4c4ba15 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -33,7 +33,7 @@ class tag_Core { throw new exception("@todo MISSING_TAG_NAME"); } - $tag = ORM::factory("tag")->where("name", $tag_name)->find(); + $tag = ORM::factory("tag")->where("name", "=", $tag_name)->find(); if (!$tag->loaded()) { $tag->name = $tag_name; $tag->count = 0; @@ -93,7 +93,7 @@ class tag_Core { ->select("name") ->from("tags") ->join("items_tags", "tags.id", "items_tags.tag_id", "left") - ->where("items_tags.item_id", $item->id) + ->where("items_tags.item_id", "=", $item->id) ->get() as $row) { $tags[] = $row->name; } diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index be020f5f..f9a453be 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -31,9 +31,9 @@ class Tag_Model extends ORM { $model = ORM::factory("item") ->viewable() ->join("items_tags", "items.id", "items_tags.item_id") - ->where("items_tags.tag_id", $this->id); + ->where("items_tags.tag_id", "=", $this->id); if ($type) { - $model->where("items.type", $type); + $model->where("items.type", "=", $type); } return $model->find_all($limit, $offset); } @@ -47,10 +47,10 @@ class Tag_Model extends ORM { $model = ORM::factory("item") ->viewable() ->join("items_tags", "items.id", "items_tags.item_id") - ->where("items_tags.tag_id", $this->id); + ->where("items_tags.tag_id", "=", $this->id); if ($type) { - $model->where("items.type", $type); + $model->where("items.type", "=", $type); } return $model->count_all(); } diff --git a/modules/tag/tests/Tag_Test.php b/modules/tag/tests/Tag_Test.php index c9a96286..c96e7f2b 100644 --- a/modules/tag/tests/Tag_Test.php +++ b/modules/tag/tests/Tag_Test.php @@ -25,18 +25,18 @@ class Tag_Test extends Unit_Test_Case { $tag1 = "tag1"; tag::add($album, $tag1); - $tag = ORM::factory("tag")->where("name", $tag1)->find(); + $tag = ORM::factory("tag")->where("name", "=", $tag1)->find(); $this->assert_true(1, $tag->count); // Make sure adding the tag again doesn't increase the count tag::add($album, $tag1); - $tag = ORM::factory("tag")->where("name", $tag1)->find(); + $tag = ORM::factory("tag")->where("name", "=", $tag1)->find(); $this->assert_true(1, $tag->count); $rand = rand(); $album = album::create($root, $rand, $rand, $rand); tag::add($album, $tag1); - $tag = ORM::factory("tag")->where("name", $tag1)->find(); + $tag = ORM::factory("tag")->where("name", "=", $tag1)->find(); $this->assert_true(2, $tag->count); } } \ No newline at end of file diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php index 1beaa1c2..2ada0ac1 100644 --- a/modules/user/helpers/group.php +++ b/modules/user/helpers/group.php @@ -31,7 +31,7 @@ class group_Core { * @return Group_Definition the group object */ static function create($name) { - $group = ORM::factory("group")->where("name", $name)->find(); + $group = ORM::factory("group")->where("name", "=", $name)->find(); if ($group->loaded()) { throw new Exception("@todo GROUP_ALREADY_EXISTS $name"); } diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php index 4ed9daee..5027580c 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -44,7 +44,7 @@ class user_Core { * @return User_Model */ static function create($name, $full_name, $password) { - $user = ORM::factory("user")->where("name", $name)->find(); + $user = ORM::factory("user")->where("name", "=", $name)->find(); if ($user->loaded()) { throw new Exception("@todo USER_ALREADY_EXISTS $name"); } diff --git a/modules/user/tests/User_Groups_Test.php b/modules/user/tests/User_Groups_Test.php index 6aedfde5..163b7d79 100644 --- a/modules/user/tests/User_Groups_Test.php +++ b/modules/user/tests/User_Groups_Test.php @@ -21,14 +21,14 @@ class User_Groups_Test extends Unit_Test_Case { public function teardown() { try { - $group = ORM::factory("group")->where("name", "user_groups_test")->find(); + $group = ORM::factory("group")->where("name", "=", "user_groups_test")->find(); if ($group->loaded()) { $group->delete(); } } catch (Exception $e) { } try { - $user = ORM::factory("user")->where("name", "user_groups_test")->find(); + $user = ORM::factory("user")->where("name", "=", "user_groups_test")->find(); if ($user->loaded()) { $user->delete(); } -- cgit v1.2.3 From e8fb773b68335e955602c0d912e13c0f5ba23d58 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 19:33:03 -0800 Subject: Update all portable where clauses to the new Kohana 2.4 format. --- modules/gallery/helpers/gallery_rss.php | 4 ++-- modules/gallery/tests/ORM_MPTT_Test.php | 4 ++-- modules/organize/views/organize_tree.html.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index 93ace10b..4aef27ad 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -49,9 +49,9 @@ class gallery_rss_Core { $feed->children = $item ->viewable() - ->descendants($limit, $offset, array("type" => "photo")); + ->descendants($limit, $offset, array(array("type", "=", "photo"))); $feed->max_pages = ceil( - $item->viewable()->descendants_count(array("type" => "photo")) / $limit); + $item->viewable()->descendants_count(array("type", "=", "photo")) / $limit); $feed->title = html::purify($item->title); $feed->description = nl2br(html::purify($item->description)); diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php index a749542b..36a81d2c 100644 --- a/modules/gallery/tests/ORM_MPTT_Test.php +++ b/modules/gallery/tests/ORM_MPTT_Test.php @@ -228,7 +228,7 @@ class ORM_MPTT_Test extends Unit_Test_Case { $parent->reload(); $this->assert_equal(3, $parent->descendants_count()); - $this->assert_equal(2, $parent->descendants_count(array("type" => "photo"))); - $this->assert_equal(1, $parent->descendants_count(array("type" => "album"))); + $this->assert_equal(2, $parent->descendants_count(array(array("type", "=", "photo")))); + $this->assert_equal(1, $parent->descendants_count(array(array("type", "=", "album")))); } } diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 740c2521..1ccb942c 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -8,7 +8,7 @@ title) ?>
    - children(null, 0, array("type" => "album")) as $child): ?> + children(null, 0, array(array("type", "=", "album"))) as $child): ?> contains($selected)): ?> $selected, "album" => $child)); ?> -- cgit v1.2.3 From dee3ee81e2013f0b38e0f84123dec2ce12574bd7 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 20:25:32 -0800 Subject: Database::orwhere() is now Database_Builder::or_where() --- modules/exif/helpers/exif.php | 2 +- modules/exif/helpers/exif_task.php | 2 +- modules/gallery/controllers/albums.php | 2 +- modules/gallery/controllers/movies.php | 2 +- modules/gallery/controllers/photos.php | 2 +- modules/gallery/helpers/album.php | 2 +- modules/gallery/helpers/movie.php | 2 +- modules/gallery/helpers/photo.php | 2 +- modules/gallery/tests/Database_Test.php | 8 ++++---- modules/search/helpers/search.php | 2 +- modules/search/helpers/search_task.php | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index b4241e89..a8b12a8b 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -146,7 +146,7 @@ class exif_Core { ->where("type", "=", "photo") ->and_open() ->where("exif_records.item_id", "=", null) - ->orwhere("exif_records.dirty", "=", 1) + ->or_where("exif_records.dirty", "=", 1) ->close() ->get() ->count(); diff --git a/modules/exif/helpers/exif_task.php b/modules/exif/helpers/exif_task.php index 1a449fc7..66f69790 100644 --- a/modules/exif/helpers/exif_task.php +++ b/modules/exif/helpers/exif_task.php @@ -47,7 +47,7 @@ class exif_task_Core { ->where("type", "=", "photo") ->and_open() ->where("exif_records.item_id", "=", null) - ->orwhere("exif_records.dirty", "=", 1) + ->or_where("exif_records.dirty", "=", 1) ->close() ->find_all() as $item) { // The query above can take a long time, so start the timer after its done diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 431d98a0..32db48d4 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -130,7 +130,7 @@ class Albums_Controller extends Items_Controller { ->where("id", "<>", $album->id) ->and_open() ->where("name", "=", $form->edit_item->dirname->value) - ->orwhere("slug", "=", $form->edit_item->slug->value) + ->or_where("slug", "=", $form->edit_item->slug->value) ->close() ->get() ->current()) { diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 157c388f..e017b8c8 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -78,7 +78,7 @@ class Movies_Controller extends Items_Controller { ->where("id <>", $movie->id) ->and_open() ->where("name", "=", $form->edit_item->filename->value) - ->orwhere("slug", "=", $form->edit_item->slug->value) + ->or_where("slug", "=", $form->edit_item->slug->value) ->close() ->get() ->current()) { diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 478447b1..5431fcfe 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -78,7 +78,7 @@ class Photos_Controller extends Items_Controller { ->where("id", "<>", $photo->id) ->and_open() ->where("name", "=", $form->edit_item->filename->value) - ->orwhere("slug", "=", $form->edit_item->slug->value) + ->or_where("slug", "=", $form->edit_item->slug->value) ->close() ->get() ->current()) { diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index cd8777e2..0ffb0fc6 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -71,7 +71,7 @@ class album_Core { ->where("parent_id", "=", $parent->id) ->and_open() ->where("name", "=", $album->name) - ->orwhere("slug", "=", $album->slug) + ->or_where("slug", "=", $album->slug) ->close() ->find()->id) { $rand = rand(); diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 82247eb0..96dafe11 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -93,7 +93,7 @@ class movie_Core { ->where("parent_id", "=", $parent->id) ->and_open() ->where("name", "=", $movie->name) - ->orwhere("slug", "=", $movie->slug) + ->or_where("slug", "=", $movie->slug) ->close() ->find()->id) { $rand = rand(); diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 2a563043..cc309e28 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -92,7 +92,7 @@ class photo_Core { ->where("parent_id", "=", $parent->id) ->and_open() ->where("name", "=", $photo->name) - ->orwhere("slug", "=", $photo->slug) + ->or_where("slug", "=", $photo->slug) ->close() ->find()->id) { $rand = rand(); diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index 4f5a1da2..9b428379 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -32,7 +32,7 @@ class Database_Test extends Unit_Test_Case { ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) - ->orwhere("inner2", "=", 2) + ->or_where("inner2", "=", 2) ->close() ->where("outer2", "=", 2) ->compile(); @@ -46,7 +46,7 @@ class Database_Test extends Unit_Test_Case { $sql = Database::instance() ->and_open() ->where("inner1", "=", 1) - ->orwhere("inner2", "=", 2) + ->or_where("inner2", "=", 2) ->close() ->where("outer1", "=", 1) ->where("outer2", "=", 2) @@ -62,8 +62,8 @@ class Database_Test extends Unit_Test_Case { ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) - ->orwhere("inner2", "=", 2) - ->orwhere("inner3", "=", 3)) + ->or_where("inner2", "=", 2) + ->or_where("inner3", "=", 3)) ->close() ->compile(); $sql = str_replace("\n", " ", $sql); diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index c0bb1b32..1fd5175f 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -78,7 +78,7 @@ class search_Core { ->join("search_records", "items.id", "search_records.item_id", "left") ->and_open() ->where("search_records.item_id", "=", null) - ->orwhere("search_records.dirty", "=", 1) + ->or_where("search_records.dirty", "=", 1) ->close() ->get() ->count(); diff --git a/modules/search/helpers/search_task.php b/modules/search/helpers/search_task.php index 061f4084..6b35cabc 100644 --- a/modules/search/helpers/search_task.php +++ b/modules/search/helpers/search_task.php @@ -46,7 +46,7 @@ class search_task_Core { foreach (ORM::factory("item") ->join("search_records", "items.id", "search_records.item_id", "left") ->where("search_records.item_id", "=", null) - ->orwhere("search_records.dirty", "=", 1) + ->or_where("search_records.dirty", "=", 1) ->find_all() as $item) { // The query above can take a long time, so start the timer after its done // to give ourselves a little time to actually process rows. -- cgit v1.2.3 From 0736cf203b37534848482e47c3afde9b58d6ce27 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 17 Dec 2009 21:32:53 -0800 Subject: In Kohana 2.4, ORM no longer does the find_all() call for us when we retrieve related ORMs. If we tack a find_all() on the end, it breaks the User_Definition interface so create User_Model::groups() and Groups_Model::users() as glue. --- modules/gallery/helpers/access.php | 2 +- modules/gallery/helpers/identity.php | 2 +- modules/gallery/tests/Access_Helper_Test.php | 6 +++--- modules/user/models/group.php | 4 ++++ modules/user/models/user.php | 4 ++++ 5 files changed, 13 insertions(+), 5 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index 85410085..8ce7e436 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -101,7 +101,7 @@ class access_Core { $resource = $perm_name == "view" ? $item : model_cache::get("access_cache", $item->id, "item_id"); - foreach ($user->groups->find_all() as $group) { + foreach ($user->groups() as $group) { if ($resource->__get("{$perm_name}_{$group->id}") === self::ALLOW) { return true; } diff --git a/modules/gallery/helpers/identity.php b/modules/gallery/helpers/identity.php index 707d1830..eae0ea3e 100644 --- a/modules/gallery/helpers/identity.php +++ b/modules/gallery/helpers/identity.php @@ -75,7 +75,7 @@ class identity_Core { if (!$session->get("group_ids")) { $ids = array(); - foreach ($user->groups->find_all() as $group) { + foreach ($user->groups() as $group) { $ids[] = $group->id; } $session->set("group_ids", $ids); diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index 771c6a85..799d5e44 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -76,7 +76,7 @@ class Access_Helper_Test extends Unit_Test_Case { access::deny(identity::registered_users(), "view", $item); $user = identity::create_user("access_test", "Access Test", ""); - foreach ($user->groups as $group) { + foreach ($user->groups() as $group) { $user->remove($group); } $user->add($access_test); @@ -93,7 +93,7 @@ class Access_Helper_Test extends Unit_Test_Case { access::deny(identity::registered_users(), "view", $item); $user = identity::create_user("access_test", "Access Test", ""); - foreach ($user->groups as $group) { + foreach ($user->groups() as $group) { $user->remove($group); } $user->save(); @@ -288,7 +288,7 @@ class Access_Helper_Test extends Unit_Test_Case { public function i_can_edit_test() { // Create a new user that belongs to no groups $user = identity::create_user("access_test", "Access Test", ""); - foreach ($user->groups as $group) { + foreach ($user->groups() as $group) { $user->remove($group); } $user->save(); diff --git a/modules/user/models/group.php b/modules/user/models/group.php index 3a084684..515788a3 100644 --- a/modules/user/models/group.php +++ b/modules/user/models/group.php @@ -33,6 +33,10 @@ class Group_Model extends ORM implements Group_Definition { module::event("group_deleted", $old); } + public function users() { + return $this->users->find_all(); + } + public function save() { if (!$this->loaded()) { $created = 1; diff --git a/modules/user/models/user.php b/modules/user/models/user.php index e14d9b31..7d5bf413 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -61,6 +61,10 @@ class User_Model extends ORM implements User_Definition { md5($this->email), $size, $default ? "&d=" . urlencode($default) : ""); } + public function groups() { + return $this->groups->find_all(); + } + public function save() { if (!$this->loaded()) { $created = 1; -- cgit v1.2.3 From a22aa4ab05e50bb0bdd5e59a27b5f1867323f7a2 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 11:29:28 -0800 Subject: Forgot to rename the file when I renamed the class. --- modules/gallery/tests/Gallery_I18n_Test.php | 108 ++++++++++++++++++++++++++++ modules/gallery/tests/I18n_Test.php | 108 ---------------------------- 2 files changed, 108 insertions(+), 108 deletions(-) create mode 100644 modules/gallery/tests/Gallery_I18n_Test.php delete mode 100644 modules/gallery/tests/I18n_Test.php (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Gallery_I18n_Test.php b/modules/gallery/tests/Gallery_I18n_Test.php new file mode 100644 index 00000000..895e3051 --- /dev/null +++ b/modules/gallery/tests/Gallery_I18n_Test.php @@ -0,0 +1,108 @@ + 'en', + 'default_locale' => 'te_ST', + 'locale_dir' => VARPATH . 'locale/'); + $this->i18n = Gallery_I18n::instance($config); + + ORM::factory("incoming_translation") + ->where("locale", "=", "te_ST") + ->delete_all(); + + $messages_te_ST = array( + array('Hello world', 'Hallo Welt'), + array(array('one' => 'One item has been added', + 'other' => '%count elements have been added'), + array('one' => 'Ein Element wurde hinzugefuegt.', + 'other' => '%count Elemente wurden hinzugefuegt.')), + array('Hello %name, how are you today?', 'Hallo %name, wie geht es Dir heute?')); + + foreach ($messages_te_ST as $data) { + list ($message, $translation) = $data; + $entry = ORM::factory("incoming_translation"); + $entry->key = Gallery_I18n::get_message_key($message); + $entry->message = serialize($message); + $entry->translation = serialize($translation); + $entry->locale = 'te_ST'; + $entry->revision = null; + $entry->save(); + } + } + + public function get_locale_test() { + $locale = $this->i18n->locale(); + $this->assert_equal("te_ST", $locale); + } + + public function set_locale_test() { + $this->i18n->locale("de_DE"); + $locale = $this->i18n->locale(); + $this->assert_equal("de_DE", $locale); + } + + public function translate_simple_test() { + $result = $this->i18n->translate('Hello world'); + $this->assert_equal('Hallo Welt', $result); + } + + public function translate_simple_root_fallback_test() { + $result = $this->i18n->translate('Hello world zzz'); + $this->assert_equal('Hello world zzz', $result); + } + + public function translate_plural_other_test() { + $result = $this->i18n->translate(array('one' => 'One item has been added', + 'other' => '%count elements have been added'), + array('count' => 5)); + $this->assert_equal('5 Elemente wurden hinzugefuegt.', $result); + } + + public function translate_plural_one_test() { + $result = $this->i18n->translate(array('one' => 'One item has been added', + 'other' => '%count elements have been added'), + array('count' => 1)); + $this->assert_equal('Ein Element wurde hinzugefuegt.', $result); + } + + public function translate_interpolate_test() { + $result = $this->i18n->translate('Hello %name, how are you today?', array('name' => 'John')); + $this->assert_equal('Hallo John, wie geht es Dir heute?', $result); + } + + public function translate_interpolate_missing_value_test() { + $result = $this->i18n->translate('Hello %name, how are you today?', array('foo' => 'bar')); + $this->assert_equal('Hallo %name, wie geht es Dir heute?', $result); + } + + public function translate_plural_zero_test() { + // te_ST has the same plural rules as en and de. + // For count 0, plural form "other" should be used. + $result = $this->i18n->translate(array('one' => 'One item has been added', + 'other' => '%count elements have been added'), + array('count' => 0)); + $this->assert_equal('0 Elemente wurden hinzugefuegt.', $result); + } +} \ No newline at end of file diff --git a/modules/gallery/tests/I18n_Test.php b/modules/gallery/tests/I18n_Test.php deleted file mode 100644 index 895e3051..00000000 --- a/modules/gallery/tests/I18n_Test.php +++ /dev/null @@ -1,108 +0,0 @@ - 'en', - 'default_locale' => 'te_ST', - 'locale_dir' => VARPATH . 'locale/'); - $this->i18n = Gallery_I18n::instance($config); - - ORM::factory("incoming_translation") - ->where("locale", "=", "te_ST") - ->delete_all(); - - $messages_te_ST = array( - array('Hello world', 'Hallo Welt'), - array(array('one' => 'One item has been added', - 'other' => '%count elements have been added'), - array('one' => 'Ein Element wurde hinzugefuegt.', - 'other' => '%count Elemente wurden hinzugefuegt.')), - array('Hello %name, how are you today?', 'Hallo %name, wie geht es Dir heute?')); - - foreach ($messages_te_ST as $data) { - list ($message, $translation) = $data; - $entry = ORM::factory("incoming_translation"); - $entry->key = Gallery_I18n::get_message_key($message); - $entry->message = serialize($message); - $entry->translation = serialize($translation); - $entry->locale = 'te_ST'; - $entry->revision = null; - $entry->save(); - } - } - - public function get_locale_test() { - $locale = $this->i18n->locale(); - $this->assert_equal("te_ST", $locale); - } - - public function set_locale_test() { - $this->i18n->locale("de_DE"); - $locale = $this->i18n->locale(); - $this->assert_equal("de_DE", $locale); - } - - public function translate_simple_test() { - $result = $this->i18n->translate('Hello world'); - $this->assert_equal('Hallo Welt', $result); - } - - public function translate_simple_root_fallback_test() { - $result = $this->i18n->translate('Hello world zzz'); - $this->assert_equal('Hello world zzz', $result); - } - - public function translate_plural_other_test() { - $result = $this->i18n->translate(array('one' => 'One item has been added', - 'other' => '%count elements have been added'), - array('count' => 5)); - $this->assert_equal('5 Elemente wurden hinzugefuegt.', $result); - } - - public function translate_plural_one_test() { - $result = $this->i18n->translate(array('one' => 'One item has been added', - 'other' => '%count elements have been added'), - array('count' => 1)); - $this->assert_equal('Ein Element wurde hinzugefuegt.', $result); - } - - public function translate_interpolate_test() { - $result = $this->i18n->translate('Hello %name, how are you today?', array('name' => 'John')); - $this->assert_equal('Hallo John, wie geht es Dir heute?', $result); - } - - public function translate_interpolate_missing_value_test() { - $result = $this->i18n->translate('Hello %name, how are you today?', array('foo' => 'bar')); - $this->assert_equal('Hallo %name, wie geht es Dir heute?', $result); - } - - public function translate_plural_zero_test() { - // te_ST has the same plural rules as en and de. - // For count 0, plural form "other" should be used. - $result = $this->i18n->translate(array('one' => 'One item has been added', - 'other' => '%count elements have been added'), - array('count' => 0)); - $this->assert_equal('0 Elemente wurden hinzugefuegt.', $result); - } -} \ No newline at end of file -- cgit v1.2.3 From bfcd99f3f2a7d1b2c5ed0b6593c202ff07058b68 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 11:30:34 -0800 Subject: Updated for K24 --- modules/akismet/tests/Akismet_Helper_Test.php | 2 +- modules/comment/tests/Comment_Helper_Test.php | 7 ++++--- modules/gallery/tests/Database_Test.php | 25 +++++++++++++++---------- modules/gallery/tests/Item_Model_Test.php | 15 +++++++++++---- 4 files changed, 31 insertions(+), 18 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/akismet/tests/Akismet_Helper_Test.php b/modules/akismet/tests/Akismet_Helper_Test.php index 745b455c..d8605d5c 100644 --- a/modules/akismet/tests/Akismet_Helper_Test.php +++ b/modules/akismet/tests/Akismet_Helper_Test.php @@ -22,7 +22,7 @@ class Akismet_Helper_Test extends Unit_Test_Case { public function setup() { Input::instance()->ip_address = "1.1.1.1"; - Kohana::$user_agent = "Akismet_Helper_Test"; + request::set_user_agent("Akismet_Helper_Test"); $root = ORM::factory("item", 1); $this->_comment = comment::create( diff --git a/modules/comment/tests/Comment_Helper_Test.php b/modules/comment/tests/Comment_Helper_Test.php index 82b7ebd2..8e726869 100644 --- a/modules/comment/tests/Comment_Helper_Test.php +++ b/modules/comment/tests/Comment_Helper_Test.php @@ -23,7 +23,7 @@ class Comment_Helper_Test extends Unit_Test_Case { public function setup() { $this->_ip_address = Input::instance()->ip_address; - $this->_user_agent = Kohana::$user_agent; + $this->_user_agent = request::user_agent(); $this->_save = $_SERVER; $_SERVER["HTTP_ACCEPT"] = "HTTP_ACCEPT"; @@ -33,16 +33,17 @@ class Comment_Helper_Test extends Unit_Test_Case { $_SERVER["HTTP_CONNECTION"] = "HTTP_CONNECTION"; $_SERVER["HTTP_HOST"] = "HTTP_HOST"; $_SERVER["HTTP_REFERER"] = "HTTP_REFERER"; - $_SERVER["HTTP_USER_AGENT"] = "HTTP_USER_AGENT"; $_SERVER["QUERY_STRING"] = "QUERY_STRING"; $_SERVER["REMOTE_ADDR"] = "REMOTE_ADDR"; $_SERVER["REMOTE_HOST"] = "REMOTE_HOST"; $_SERVER["REMOTE_PORT"] = "REMOTE_PORT"; + + request::set_user_agent("HTTP_USER_AGENT"); } public function teardown() { Input::instance()->ip_address = $this->_ip_address; - Kohana::$user_agent = $this->_user_agent; + request::set_user_agent($this->_user_agent); $_SERVER = $this->_save; } diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index 9b428379..4259961e 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -19,7 +19,7 @@ */ class Database_Test extends Unit_Test_Case { function simple_where_test() { - $sql = Database::instance() + $sql = Database_Builder_For_Test::instance() ->where("a", "=", 1) ->where("b", "=", 2) ->compile(); @@ -28,7 +28,7 @@ class Database_Test extends Unit_Test_Case { } function compound_where_test() { - $sql = Database::instance() + $sql = Database_Builder_For_Test::instance() ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) @@ -43,7 +43,7 @@ class Database_Test extends Unit_Test_Case { } function group_first_test() { - $sql = Database::instance() + $sql = Database_Builder_For_Test::instance() ->and_open() ->where("inner1", "=", 1) ->or_where("inner2", "=", 2) @@ -58,12 +58,12 @@ class Database_Test extends Unit_Test_Case { } function where_array_test() { - $sql = Database::instance() + $sql = Database_Builder_For_Test::instance() ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) ->or_where("inner2", "=", 2) - ->or_where("inner3", "=", 3)) + ->or_where("inner3", "=", 3) ->close() ->compile(); $sql = str_replace("\n", " ", $sql); @@ -73,7 +73,7 @@ class Database_Test extends Unit_Test_Case { } function notlike_test() { - $sql = Database::instance() + $sql = Database_Builder_For_Test::instance() ->where("outer1", "=", 1) ->or_open() ->where("inner1", "NOT LIKE", 1) @@ -86,7 +86,7 @@ class Database_Test extends Unit_Test_Case { } function prefix_replacement_test() { - $db = Database_For_Test::instance(); + $db = Database::instance(); $converted = $db->add_table_prefixes("CREATE TABLE IF NOT EXISTS {test_tables} ( `id` int(9) NOT NULL auto_increment, `name` varchar(32) NOT NULL, @@ -118,7 +118,8 @@ class Database_Test extends Unit_Test_Case { } function prefix_no_replacement_test() { - $update = Database_For_Test::instance()->from("test_tables") + $update = Database_Builder_For_Test::instance() + ->from("test_tables") ->where("1", "=", "1") ->set(array("name" => "Test Name")) ->update(); @@ -129,9 +130,9 @@ class Database_Test extends Unit_Test_Case { } } -class Database_For_Test extends Database { +class Database_Builder_For_Test extends Database_Builder { static function instance() { - $db = new Database_For_Test(); + $db = new Database_Builder_For_Test(); $db->_table_names["{items}"] = "g3test_items"; $db->config["table_prefix"] = "g3test_"; return $db; @@ -143,4 +144,8 @@ class Database_For_Test extends Database { } return $sql; } + + public function compile() { + return parent::compile(); + } } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index e7dce893..bf5fca1a 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -35,8 +35,12 @@ class Item_Model_Test extends Unit_Test_Case { $item = self::_create_random_item(); // Force the creation date to something well known - $db = Database::instance(); - $db->update("items", array("created" => 0, "updated" => 0), array("id" => $item->id)); + db::build() + ->update("items") + ->set("created", 0) + ->set("updated", 0) + ->where("id", "=", $item->id) + ->execute(); $item->reload(); $item->title = "foo"; // force a change $item->save(); @@ -51,8 +55,11 @@ class Item_Model_Test extends Unit_Test_Case { $this->assert_same(0, $item->view_count); // Force the updated date to something well known - $db = Database::instance(); - $db->update("items", array("updated" => 0), array("id" => $item->id)); + db::build() + ->update("items") + ->set("updated", 0) + ->where("id", "=", $item->id) + ->execute(); $item->reload(); $item->view_count++; $item->save(); -- cgit v1.2.3 From 5df1dc135b6b1fad77a23cd604f008e0784bdd73 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 12:13:25 -0800 Subject: Fix some bugs in the cache database driver, and update the tests for K24. --- .../gallery/libraries/drivers/Cache/Database.php | 7 +- modules/gallery/tests/Cache_Test.php | 79 ++++++++++------------ 2 files changed, 37 insertions(+), 49 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index 5c453f28..82a09ab9 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -90,7 +90,7 @@ class Cache_Database_Driver extends Cache_Driver { ->select() ->from("caches"); foreach ($tags as $tag) { - $db->where("tags", "LIKE", "<$tag>"); + $db->where("tags", "LIKE", "%<$tag>%"); } $db_result = $db->execute(); @@ -153,14 +153,13 @@ class Cache_Database_Driver extends Cache_Driver { * @param bool delete a tag * @return bool */ - public function delete($id, $tag = false) { + public function delete($id, $tag=false) { $db = db::build() ->delete("caches"); if ($id === true) { // Delete all caches - $db->where("1", "=", "1"); } else if ($tag === true) { - $db->where("tags", "LIKE", "<$id>"); + $db->where("tags", "LIKE", "%<$id>%"); } else { $db->where("key", "=", $id); } diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php index 776c6625..d5bf37cc 100644 --- a/modules/gallery/tests/Cache_Test.php +++ b/modules/gallery/tests/Cache_Test.php @@ -20,88 +20,83 @@ class Cache_Test extends Unit_Test_Case { private $_driver; public function setup() { - Database::instance()->from("caches")->where("1", "=", "1")->delete(); + db::build()->delete("caches")->execute(); $this->_driver = new Cache_Database_Driver(); } public function cache_exists_test() { - $db = Database::instance(); - $this->assert_false($this->_driver->exists("test_key"), "test_key should not be defined"); $id = md5(rand()); - $db->insert("caches", array("key" => $id, "tags" => ", ", - "expiration" => 84600 + time(), - "cache" => serialize("some test data"))); + db::build() + ->insert("caches") + ->columns("key", "tags", "expiration", "cache") + ->values($id, ", ", 84600 + time(), serialize("some test data")) + ->execute(); $this->assert_true($this->_driver->exists($id), "test_key should be defined"); } public function cache_get_test() { - $db = Database::instance(); - $id = md5(rand()); - $db->insert("caches", array("key" => $id, "tags" => ", ", - "expiration" => 84600 + time(), - "cache" => serialize("some test data"))); - $data = $this->_driver->get($id); + db::build() + ->insert("caches") + ->columns("key", "tags", "expiration", "cache") + ->values($id, ", ", 84600 + time(), serialize("some test data")) + ->execute(); + + $data = $this->_driver->get(array($id)); $this->assert_equal("some test data", $data, "cached data should match"); - $data = $this->_driver->get(""); + $data = $this->_driver->get(array("")); $this->assert_equal(null, $data, "cached data should not be found"); } public function cache_set_test() { - $db = Database::instance(); - $id = md5(rand()); $original_data = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id, $original_data, array("tag1", "tag2"), 84600); + $this->_driver->set(array($id => $original_data), array("tag1", "tag2"), 84600); - $data = $this->_driver->get($id); + $data = $this->_driver->get(array($id)); $this->assert_equal($original_data, $data, "cached data should match"); } - public function cache_find_test() { - $db = Database::instance(); - + public function cache_get_tag_test() { $id1 = md5(rand()); $value1 = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id1, $value1, array("tag1", "tag2"), 84600); + $this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600); $id2 = md5(rand()); $value2 = array("field3" => "value3", "field4" => "value4"); - $this->_driver->set($id2, $value2, array("tag2", "tag3"), 84600); + $this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 84600); $id3 = md5(rand()); $value3 = array("field5" => "value5", "field6" => "value6"); - $this->_driver->set($id3, $value3, array("tag3", "tag4"), 84600); + $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600); - $data = $this->_driver->find("tag2"); + $data = $this->_driver->get_tag(array("tag2")); $expected = array($id1 => $value1, $id2 => $value2); ksort($expected); $this->assert_equal($expected, $data, "Expected id1 & id2"); - $data = $this->_driver->find("tag4"); + $data = $this->_driver->get_tag(array("tag4")); $this->assert_equal(array($id3 => $value3), $data, "Expected id3"); } public function cache_delete_expired_test() { - $db = Database::instance(); - $id1 = md5(rand()); $value1 = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id1, $value1, array("tag1", "tag2"), -84600); + $this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), -84600); $id2 = md5(rand()); $value2 = array("field3" => "value3", "field4" => "value4"); - $this->_driver->set($id2, $value2, array("tag2", "tag3"), -846000); + $this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), -846000); $id3 = md5(rand()); $value3 = array("field5" => "value5", "field6" => "value6"); - $this->_driver->set($id3, $value3, array("tag3", "tag4"), -84600); + $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), -84600); $data = $this->_driver->delete_expired(); @@ -111,19 +106,17 @@ class Cache_Test extends Unit_Test_Case { } public function cache_delete_id_test() { - $db = Database::instance(); - $id1 = md5(rand()); $value1 = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id1, $value1, array("tag1", "tag2"), 84600); + $this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600); $id2 = md5(rand()); $value2 = array("field3" => "value3", "field4" => "value4"); - $this->_driver->set($id2, $value2, array("tag2", "tag3"), 846000); + $this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 846000); $id3 = md5(rand()); $value3 = array("field5" => "value5", "field6" => "value6"); - $this->_driver->set($id3, $value3, array("tag3", "tag4"), 84600); + $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600); $this->_driver->delete($id1); @@ -133,19 +126,17 @@ class Cache_Test extends Unit_Test_Case { } public function cache_delete_tag_test() { - $db = Database::instance(); - $id1 = md5(rand()); $value1 = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id1, $value1, array("tag1", "tag2"), 84600); + $this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600); $id2 = md5(rand()); $value2 = array("field3" => "value3", "field4" => "value4"); - $this->_driver->set($id2, $value2, array("tag2", "tag3"), 846000); + $this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 846000); $id3 = md5(rand()); $value3 = array("field5" => "value5", "field6" => "value6"); - $this->_driver->set($id3, $value3, array("tag3", "tag4"), 84600); + $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600); $data = $this->_driver->delete("tag3", true); @@ -155,19 +146,17 @@ class Cache_Test extends Unit_Test_Case { } public function cache_delete_all_test() { - $db = Database::instance(); - $id1 = md5(rand()); $value1 = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id1, $value1, array("tag1", "tag2"), 84600); + $this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600); $id2 = md5(rand()); $value2 = array("field3" => "value3", "field4" => "value4"); - $this->_driver->set($id2, $value2, array("tag2", "tag3"), 846000); + $this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 846000); $id3 = md5(rand()); $value3 = array("field5" => "value5", "field6" => "value6"); - $this->_driver->set($id3, $value3, array("tag3", "tag4"), 84600); + $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600); $data = $this->_driver->delete(true); -- cgit v1.2.3 From e1f43ad403ac3deba8ac19d3d748500bba608395 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 12:22:19 -0800 Subject: Updated for K24 --- modules/gallery/tests/Sendmail_Test.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Sendmail_Test.php b/modules/gallery/tests/Sendmail_Test.php index 64c1fff0..f3a8d897 100644 --- a/modules/gallery/tests/Sendmail_Test.php +++ b/modules/gallery/tests/Sendmail_Test.php @@ -19,9 +19,7 @@ */ class Sendmail_Test extends Unit_Test_Case { public function setup() { - $config = Kohana::config("sendmail"); - $config["from"] = "from@gallery3.com"; - Kohana::config_set("sendmail", $config); + Kohana_Config::instance()->set("sendmail.from", "from@gallery3.com"); } public function sendmail_test() { -- cgit v1.2.3 From cc4d7c672c863185bab5d654222e205d6517e98a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 15:40:28 -0800 Subject: Update database tests for K24. Use a mock database that we load through the framework so that we're properly testing the Database_Builder, it's a lot cleaner than what we had before. --- modules/gallery/tests/Database_Test.php | 105 +++++++++++++-------- .../libraries/MY_Database_Builder.php | 4 + 2 files changed, 72 insertions(+), 37 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index 4259961e..6aa186e5 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -18,17 +18,27 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Database_Test extends Unit_Test_Case { + function setup() { + $config = Kohana_Config::instance(); + $config->set("database.mock.connection.type", "mock"); + $config->set("database.mock.cache", false); + $config->set("database.mock.table_prefix", "g_"); + } + function simple_where_test() { - $sql = Database_Builder_For_Test::instance() + $sql = db::build("mock") + ->select("some_column") + ->from("some_table") ->where("a", "=", 1) ->where("b", "=", 2) ->compile(); $sql = str_replace("\n", " ", $sql); - $this->assert_same("SELECT * WHERE `a` = 1 AND `b` = 2", $sql); + $this->assert_same("SELECT [some_column] FROM [some_table] WHERE [a] = [1] AND [b] = [2]", $sql); } function compound_where_test() { - $sql = Database_Builder_For_Test::instance() + $sql = db::build("mock") + ->select() ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) @@ -38,12 +48,13 @@ class Database_Test extends Unit_Test_Case { ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( - "SELECT * WHERE `outer1` = 1 AND (`inner1` = 1 OR `inner2` = 2) AND `outer2` = 2", + "SELECT [*] WHERE [outer1] = [1] AND ([inner1] = [1] OR [inner2] = [2]) AND [outer2] = [2]", $sql); } function group_first_test() { - $sql = Database_Builder_For_Test::instance() + $sql = db::build("mock") + ->select() ->and_open() ->where("inner1", "=", 1) ->or_where("inner2", "=", 2) @@ -53,12 +64,13 @@ class Database_Test extends Unit_Test_Case { ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( - "SELECT * WHERE (`inner1` = 1 OR `inner2` = 2) AND `outer1` = 1 AND `outer2` = 2", + "SELECT [*] WHERE ([inner1] = [1] OR [inner2] = [2]) AND [outer1] = [1] AND [outer2] = [2]", $sql); } function where_array_test() { - $sql = Database_Builder_For_Test::instance() + $sql = db::build("mock") + ->select() ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) @@ -68,32 +80,33 @@ class Database_Test extends Unit_Test_Case { ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( - "SELECT * WHERE `outer1` = 1 AND (`inner1` = 1 OR `inner2` = 2 OR `inner3` = 3)", + "SELECT [*] WHERE [outer1] = [1] AND ([inner1] = [1] OR [inner2] = [2] OR [inner3] = [3])", $sql); } function notlike_test() { - $sql = Database_Builder_For_Test::instance() + $sql = db::build("mock") + ->select() ->where("outer1", "=", 1) ->or_open() - ->where("inner1", "NOT LIKE", 1) + ->where("inner1", "NOT LIKE", "%1%") ->close() ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( - "SELECT * WHERE `outer1` = 1 OR ( `inner1` NOT LIKE '%1%')", + "SELECT [*] WHERE [outer1] = [1] OR ([inner1] NOT LIKE [%1%])", $sql); } function prefix_replacement_test() { - $db = Database::instance(); - $converted = $db->add_table_prefixes("CREATE TABLE IF NOT EXISTS {test_tables} ( + $db = Database::instance("mock"); + $converted = $db->add_table_prefixes("CREATE TABLE IF NOT EXISTS {test} ( `id` int(9) NOT NULL auto_increment, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); - $expected = "CREATE TABLE IF NOT EXISTS g3test_test_tables ( + $expected = "CREATE TABLE IF NOT EXISTS g_test ( `id` int(9) NOT NULL auto_increment, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), @@ -101,16 +114,16 @@ class Database_Test extends Unit_Test_Case { ENGINE=InnoDB DEFAULT CHARSET=utf8"; $this->assert_same($expected, $converted); - $sql = "UPDATE {test_tables} SET `name` = '{test string}' " . + $sql = "UPDATE {test} SET `name` = '{test string}' " . "WHERE `item_id` IN " . - " (SELECT `id` FROM {items} " . + " (SELECT `id` FROM {test} " . " WHERE `left_ptr` >= 1 " . " AND `right_ptr` <= 6)"; $sql = $db->add_table_prefixes($sql); - $expected = "UPDATE g3test_test_tables SET `name` = '{test string}' " . + $expected = "UPDATE g_test SET `name` = '{test string}' " . "WHERE `item_id` IN " . - " (SELECT `id` FROM g3test_items " . + " (SELECT `id` FROM g_test " . " WHERE `left_ptr` >= 1 " . " AND `right_ptr` <= 6)"; @@ -118,34 +131,52 @@ class Database_Test extends Unit_Test_Case { } function prefix_no_replacement_test() { - $update = Database_Builder_For_Test::instance() + $sql = db::build("mock") ->from("test_tables") ->where("1", "=", "1") ->set(array("name" => "Test Name")) - ->update(); + ->update() + ->compile(); + $sql = str_replace("\n", " ", $sql); + $this->assert_same("UPDATE [test_tables] SET [name] = [Test Name] WHERE [1] = [1]", $sql); + } +} - $expected = "UPDATE `g3test_test_tables` SET `name` = 'Test Name' WHERE 1 = 1"; +class Database_Mock extends Database { + public function connect() { + } - $this->assert_same($expected, $update); + public function disconnect() { } -} -class Database_Builder_For_Test extends Database_Builder { - static function instance() { - $db = new Database_Builder_For_Test(); - $db->_table_names["{items}"] = "g3test_items"; - $db->config["table_prefix"] = "g3test_"; - return $db; + public function set_charset($charset) { } - public function query($sql = '') { - if (!empty($sql)) { - $sql = $this->add_table_prefixes($sql); - } - return $sql; + public function query_execute($sql) { } - public function compile() { - return parent::compile(); + public function escape($val) { } -} + + public function list_constraints($table) { + } + + public function list_fields($table) { + } + + public function list_tables() { + return array("test"); + } + + public function quote_column($val) { + return "[$val]"; + } + + public function quote_table($val) { + return "[$val]"; + } + + public function quote($val) { + return "[$val]"; + } +} \ No newline at end of file diff --git a/modules/kohana23_compat/libraries/MY_Database_Builder.php b/modules/kohana23_compat/libraries/MY_Database_Builder.php index 974f9c6d..54a10860 100644 --- a/modules/kohana23_compat/libraries/MY_Database_Builder.php +++ b/modules/kohana23_compat/libraries/MY_Database_Builder.php @@ -28,4 +28,8 @@ class Database_Builder extends Database_Builder_Core { } return $this; } + + public function compile() { + return parent::compile(); + } } \ No newline at end of file -- cgit v1.2.3 From e0dc5206486dc6370b102fb80b050b7c81bf2420 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 17:26:24 -0800 Subject: Updated for recent K24 Forge changes. --- modules/gallery/tests/DrawForm_Test.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/DrawForm_Test.php b/modules/gallery/tests/DrawForm_Test.php index 7ee80ca2..baded8de 100644 --- a/modules/gallery/tests/DrawForm_Test.php +++ b/modules/gallery/tests/DrawForm_Test.php @@ -25,9 +25,10 @@ class DrawForm_Test extends Unit_Test_Case { $form->submit("")->value(t("Submit")); $rendered = $form->__toString(); + $csrf = access::csrf_token(); $expected = "
    \n" . - "\n" . + "" . "
      \n" . "
    • \n" . " \n" . @@ -36,14 +37,14 @@ class DrawForm_Test extends Unit_Test_Case { "
    • \n" . "
    • \n" . " \n" . - " \n" . "
    • \n" . "
    • \n" . " \n" . "
    • \n" . "
    \n" . - "
    \n"; + ""; $this->assert_same($expected, $rendered); } @@ -55,9 +56,10 @@ class DrawForm_Test extends Unit_Test_Case { $group->submit("")->value(t("Submit")); $rendered = $form->__toString(); + $csrf = access::csrf_token(); $expected = "
    \n" . - "\n" . + "" . "
    \n" . " Test Group\n" . "
      \n" . @@ -68,7 +70,7 @@ class DrawForm_Test extends Unit_Test_Case { " \n" . "
    • \n" . " \n" . - " \n" . "
    • \n" . "
    • \n" . @@ -76,7 +78,7 @@ class DrawForm_Test extends Unit_Test_Case { "
    • \n" . "
    \n" . "
    \n" . - "
    \n"; + ""; $this->assert_same($expected, $rendered); } @@ -91,9 +93,10 @@ class DrawForm_Test extends Unit_Test_Case { $group->submit("")->value(t("Submit")); $rendered = $form->__toString(); + $csrf = access::csrf_token(); $expected = "
    \n" . - "\n" . + "" . "
    \n" . " Test Group\n" . "
      \n" . @@ -104,7 +107,7 @@ class DrawForm_Test extends Unit_Test_Case { " \n" . "
    • \n" . " \n" . - " \n" . "
    • \n" . "
    • \n" . @@ -116,7 +119,7 @@ class DrawForm_Test extends Unit_Test_Case { "\n" . - "
    • \n"; + ""; $this->assert_same($expected, $rendered); } } -- cgit v1.2.3 From 9c5df1d31bd214fab051b71d092c751a1da20ecc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 19:59:44 -0800 Subject: Fix preambles, and fix the File_Structure_Test to be more lenient because of preamble variation in K24. --- application/Bootstrap.php | 22 +++++++++---- modules/gallery/config/log_file.php | 20 ++++++++++- modules/gallery/tests/File_Structure_Test.php | 16 ++++++--- modules/kohana23_compat/config/pagination.php | 42 +++++++++++++----------- modules/kohana23_compat/libraries/Pagination.php | 20 ++++++++++- 5 files changed, 87 insertions(+), 33 deletions(-) (limited to 'modules/gallery/tests') diff --git a/application/Bootstrap.php b/application/Bootstrap.php index f36fac14..95f7b8d2 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -1,13 +1,21 @@ -\n"; + $expected_2 = " 'pagination', - 'style' => 'classic', - 'uri_segment' => 3, - 'query_string' => '', - 'items_per_page' => 20, - 'auto_hide' => FALSE, +$config["default"] = array( + "directory" => "pagination", + "style" => "classic", + "uri_segment" => 3, + "query_string" => "", + "items_per_page" => 20, + "auto_hide" => FALSE ); diff --git a/modules/kohana23_compat/libraries/Pagination.php b/modules/kohana23_compat/libraries/Pagination.php index 8ff8bf94..012bc484 100644 --- a/modules/kohana23_compat/libraries/Pagination.php +++ b/modules/kohana23_compat/libraries/Pagination.php @@ -1,4 +1,22 @@ - Date: Tue, 22 Dec 2009 13:57:49 -0800 Subject: Don't rely on implicit object -> id conversion, that doesn't work with K24's Database_Builder::where() --- modules/gallery/tests/Access_Helper_Test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index 799d5e44..084bfb47 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -131,7 +131,7 @@ class Access_Helper_Test extends Unit_Test_Case { public function can_allow_deny_and_reset_intent_test() { $root = ORM::factory("item", 1); $album = album::create($root, rand(), "test album"); - $intent = ORM::factory("access_intent")->where("item_id", "=", $album)->find(); + $intent = ORM::factory("access_intent")->where("item_id", "=", $album->id)->find(); // Allow access::allow(identity::everybody(), "view", $album); @@ -141,19 +141,19 @@ class Access_Helper_Test extends Unit_Test_Case { access::deny(identity::everybody(), "view", $album); $this->assert_same( access::DENY, - ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album->id)->find()->view_1); // Allow again. If the initial value was allow, then the first Allow clause above may not // have actually changed any values. access::allow(identity::everybody(), "view", $album); $this->assert_same( access::ALLOW, - ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album->id)->find()->view_1); access::reset(identity::everybody(), "view", $album); $this->assert_same( null, - ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album->id)->find()->view_1); } public function cant_reset_root_item_test() { -- cgit v1.2.3 From fda4227bb10d7c9ae4de5f16e59890bf7cf3b83b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 14:00:52 -0800 Subject: Latest K24 does not automatically add an id attribute to every form element with the same value as the name. Yay! That was a weird and unexpected behavior. --- modules/gallery/tests/DrawForm_Test.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/DrawForm_Test.php b/modules/gallery/tests/DrawForm_Test.php index baded8de..90361d06 100644 --- a/modules/gallery/tests/DrawForm_Test.php +++ b/modules/gallery/tests/DrawForm_Test.php @@ -28,16 +28,16 @@ class DrawForm_Test extends Unit_Test_Case { $csrf = access::csrf_token(); $expected = "
      \n" . - "" . + "" . "
        \n" . "
      • \n" . " \n" . - " \n" . "
      • \n" . "
      • \n" . " \n" . - " \n" . "
      • \n" . "
      • \n" . @@ -59,18 +59,18 @@ class DrawForm_Test extends Unit_Test_Case { $csrf = access::csrf_token(); $expected = "\n" . - "" . + "" . "
        \n" . " Test Group\n" . "
          \n" . "
        • \n" . " \n" . - " \n" . "
        • \n" . "
        • \n" . " \n" . - " \n" . "
        • \n" . "
        • \n" . @@ -96,18 +96,18 @@ class DrawForm_Test extends Unit_Test_Case { $csrf = access::csrf_token(); $expected = "\n" . - "" . + "" . "
          \n" . " Test Group\n" . "
            \n" . "
          • \n" . " \n" . - " \n" . "
          • \n" . "
          • \n" . " \n" . - " \n" . "
          • \n" . "
          • \n" . -- cgit v1.2.3 From 71e154b6748a2bedd2289133c6b4c6f3f58d3603 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 16:13:08 -0800 Subject: Use a Database_Expression to handle the MAX() function. --- modules/gallery/tests/Gallery_Installer_Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Gallery_Installer_Test.php b/modules/gallery/tests/Gallery_Installer_Test.php index f36f638f..43399fb4 100644 --- a/modules/gallery/tests/Gallery_Installer_Test.php +++ b/modules/gallery/tests/Gallery_Installer_Test.php @@ -35,7 +35,7 @@ class Gallery_Installer_Test extends Unit_Test_Case { public function install_creates_root_item_test() { $max_right_ptr = ORM::factory("item") - ->select("MAX(`right_ptr`) AS `right_ptr`") + ->select(new Database_Expression("MAX(`right_ptr`) AS `right_ptr`")) ->find()->right_ptr; $root = ORM::factory('item')->find(1); $this->assert_equal("Gallery", $root->title); -- cgit v1.2.3 From a6da027aad5072a85719fc9e201ee946963e74f0 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 16:22:24 -0800 Subject: The default value for $offset should always be null (according to the new K24 ORM). Fix up a bad where tuple in the test. --- modules/gallery/libraries/ORM_MPTT.php | 2 +- modules/gallery/models/item.php | 2 +- modules/gallery/tests/ORM_MPTT_Test.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index 949ca48c..0ea519c9 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -201,7 +201,7 @@ class ORM_MPTT_Core extends ORM { * @param array order_by * @return object ORM_Iterator */ - function descendants($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) { + function descendants($limit=null, $offset=null, $where=null, $order_by=array("id" => "ASC")) { if ($where) { $this->merge_where($where); } diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index e2208b73..e3d27b6d 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -634,7 +634,7 @@ class Item_Model extends ORM_MPTT { * @param array additional where clauses * @return object ORM_Iterator */ - function descendants($limit=null, $offset=0, $where=array(), $order_by=null) { + function descendants($limit=null, $offset=null, $where=array(), $order_by=null) { if (empty($order_by)) { $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php index 36a81d2c..69b6bea9 100644 --- a/modules/gallery/tests/ORM_MPTT_Test.php +++ b/modules/gallery/tests/ORM_MPTT_Test.php @@ -190,8 +190,8 @@ class ORM_MPTT_Test extends Unit_Test_Case { $parent->reload(); $this->assert_equal(3, $parent->descendants()->count()); - $this->assert_equal(2, $parent->descendants(null, 0, array("type" => "photo"))->count()); - $this->assert_equal(1, $parent->descendants(null, 0, array("type" => "album"))->count()); + $this->assert_equal(2, $parent->descendants(null, null, array(array("type", "=", "photo")))->count()); + $this->assert_equal(1, $parent->descendants(null, null, array(array("type", "=", "album")))->count()); } public function descendant_limit_test() { -- cgit v1.2.3 From 6601bb29d90ebe0b6f6df0b27616d2804783e447 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 16:25:31 -0800 Subject: Update. --- modules/gallery/tests/xss_data.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 3708bc6d..5a15d2ac 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -121,6 +121,7 @@ modules/gallery/views/admin_themes_preview.html.php 7 DIRTY_ATTR $url modules/gallery/views/form_uploadify.html.php 20 DIRTY_JS url::file("lib/uploadify/uploadify.swf") modules/gallery/views/form_uploadify.html.php 21 DIRTY_JS url::site("simple_uploader/add_photo/{$album->id}") modules/gallery/views/form_uploadify.html.php 25 DIRTY_JS url::file("lib/uploadify/cancel.png") +modules/gallery/views/form_uploadify.html.php 27 DIRTY_JS $simultaneous_upload_limit modules/gallery/views/form_uploadify.html.php 52 DIRTY_JS t("Completed") modules/gallery/views/in_place_edit.html.php 2 DIRTY form::open($action,array("method"=>"post","id"=>"g-in-place-edit-form","class"=>"g-short-form"),$hidden) modules/gallery/views/in_place_edit.html.php 5 DIRTY form::input("input",$form["input"]," class=\"textbox\"") @@ -274,11 +275,11 @@ modules/rss/views/feed.mrss.php 55 DIRTY_ATTR @fil modules/rss/views/feed.mrss.php 56 DIRTY_ATTR $child->mime_type modules/rss/views/feed.mrss.php 57 DIRTY_ATTR $child->resize_height modules/rss/views/feed.mrss.php 58 DIRTY_ATTR $child->resize_width -modules/rss/views/feed.mrss.php 62 DIRTY_ATTR $child->file_url(true) -modules/rss/views/feed.mrss.php 63 DIRTY_ATTR @filesize($child->file_path()) -modules/rss/views/feed.mrss.php 64 DIRTY_ATTR $child->mime_type -modules/rss/views/feed.mrss.php 65 DIRTY_ATTR $child->height -modules/rss/views/feed.mrss.php 66 DIRTY_ATTR $child->width +modules/rss/views/feed.mrss.php 61 DIRTY_ATTR $child->file_url(true) +modules/rss/views/feed.mrss.php 62 DIRTY_ATTR @filesize($child->file_path()) +modules/rss/views/feed.mrss.php 63 DIRTY_ATTR $child->mime_type +modules/rss/views/feed.mrss.php 64 DIRTY_ATTR $child->height +modules/rss/views/feed.mrss.php 65 DIRTY_ATTR $child->width modules/rss/views/feed.mrss.php 70 DIRTY_ATTR $child->file_url(true) modules/rss/views/feed.mrss.php 71 DIRTY_ATTR @filesize($child->file_path()) modules/rss/views/feed.mrss.php 72 DIRTY_ATTR $child->height -- cgit v1.2.3 From 0bc92614d37e08ab5f85c83cf4317132d4c6b99c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 16:48:18 -0800 Subject: Checkpoint --- modules/gallery/tests/controller_auth_data.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index 1fe29ffb..044a8f22 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -3,7 +3,8 @@ modules/comment/helpers/comment_rss.php feed modules/digibug/controllers/digibug.php print_proxy DIRTY_CSRF|DIRTY_AUTH modules/digibug/controllers/digibug.php close_window DIRTY_AUTH modules/gallery/controllers/admin.php __call DIRTY_AUTH -modules/gallery/controllers/albums.php _show DIRTY_CSRF +modules/gallery/controllers/albums.php index DIRTY_AUTH +modules/gallery/controllers/albums.php show DIRTY_CSRF modules/gallery/controllers/combined.php javascript DIRTY_AUTH modules/gallery/controllers/combined.php css DIRTY_AUTH modules/gallery/controllers/file_proxy.php __call DIRTY_CSRF|DIRTY_AUTH -- cgit v1.2.3