From 2e420522ece22942a9b3b6ee413ca0e1dfa76148 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 13:22:24 -0800 Subject: [PATCH] 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 +- .../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 +- .../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 +- .../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 +- .../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 +- .../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 +- .../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(-) diff --git a/modules/akismet/helpers/akismet.php b/modules/akismet/helpers/akismet.php index 43549ffa8d..46a305b284 100644 --- a/modules/akismet/helpers/akismet.php +++ b/modules/akismet/helpers/akismet.php @@ -166,7 +166,7 @@ private static function _http_post($http_request, $host=null) { } $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 @@ private static function _http_post($http_request, $host=null) { } 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 13532c4e72..1a9f0e6a4d 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -110,7 +110,7 @@ public function set_state($id, $state) { $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 bb9b883306..59b8523382 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -59,7 +59,7 @@ function author_url() { 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 f650cabfdb..ff7f1c268e 100644 --- a/modules/comment/tests/Comment_Event_Test.php +++ b/modules/comment/tests/Comment_Event_Test.php @@ -27,6 +27,6 @@ public function deleting_an_item_deletes_its_comments_too_test() { $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 1bb2691b1d..cef42b2d1a 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -81,7 +81,7 @@ public function print_proxy($type, $id) { } $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 5ddd09d4da..b6a55679f9 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -74,7 +74,7 @@ static function extract($item) { $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 @@ static function get($item) { $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 202a0e92ac..1e835a59ee 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -458,7 +458,7 @@ static function import_item(&$queue) { 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 @@ static function import_item(&$queue) { 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 @@ static function import_item(&$queue) { 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 @@ static function get_tag_item_ids($min_id) { 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 @@ static function set_map($g2_id, $g3_id) { 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 47a205bd03..fef0d186e3 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -66,7 +66,7 @@ static function import($task) { $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 66bcce5524..fe5059e7d2 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -75,7 +75,7 @@ public function resume($task_id) { 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 @@ public function show_log($task_id) { 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 @@ public function save_log($task_id) { 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 @@ public function run($task_id) { 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 e67df6f64d..cc63d43fbb 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -66,6 +66,7 @@ public function _show($album) { $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 @@ public function _show($album) { // 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 acfd6eb998..11d858c03f 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -58,7 +58,7 @@ public function __call($function, $args) { // 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 @@ public function __call($function, $args) { 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 3801e6aaad..2eda741cbd 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -33,7 +33,7 @@ public function save() { "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 @@ public function save() { "locale" => $locale)) ->find(); - if (!$entry->loaded) { + if (!$entry->loaded()) { $entry->key = $key; $entry->locale = $locale; $entry->message = $root_message->message; @@ -74,7 +74,7 @@ public function save() { "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 99943fbbae..e03f41a9d9 100644 --- a/modules/gallery/controllers/permissions.php +++ b/modules/gallery/controllers/permissions.php @@ -57,7 +57,7 @@ function change($command, $group_id, $perm_id, $item_id) { 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 2edf079f8a..087f2c29fa 100644 --- a/modules/gallery/controllers/rest.php +++ b/modules/gallery/controllers/rest.php @@ -82,7 +82,7 @@ public function __call($function, $args) { } $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 @@ public function form_edit($resource_id) { } $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 37753ff372..5d32e35f88 100644 --- a/modules/gallery/controllers/simple_uploader.php +++ b/modules/gallery/controllers/simple_uploader.php @@ -72,7 +72,7 @@ public function add_photo($id) { 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 368c947e7b..e5eefad7ae 100644 --- a/modules/gallery/helpers/MY_url.php +++ b/modules/gallery/helpers/MY_url.php @@ -32,7 +32,7 @@ static function parse_url() { } $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 @@ static function get_item_from_uri($uri) { // 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 c1c1f9d126..9d27181af1 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -91,7 +91,7 @@ static function can($perm_name, $item) { * @return boolean */ static function user_can($user, $perm_name, $item) { - if (!$item->loaded) { + if (!$item->loaded()) { return false; } @@ -101,7 +101,7 @@ static function user_can($user, $perm_name, $item) { $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 @@ static function locked_by($group, $perm_name, $item) { ->limit(1) ->find(); - if ($lock->loaded) { + if ($lock->loaded()) { return $lock; } else { return null; @@ -201,7 +201,7 @@ private static function _set(Group_Definition $group, $perm_name, $album, $value 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 @@ static function recalculate_permissions($item) { */ 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 @@ static function delete_permission($name) { 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 @@ static function delete_group($group) { */ 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 @@ private static function _update_access_view_cache($group, $item) { ->orderby("left_ptr", "DESC") ->limit(1) ->find(); - if ($tmp_item->loaded) { + if ($tmp_item->loaded()) { $item = $tmp_item; } } @@ -568,7 +568,7 @@ private static function _update_access_non_view_cache($group, $perm_name, $item) ->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 72a79a7573..c82a550958 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 9c69cecd2b..21a39bfbc1 100644 --- a/modules/gallery/helpers/auth.php +++ b/modules/gallery/helpers/auth.php @@ -46,7 +46,7 @@ static function logout() { 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 c24d2bde02..ce08bbd7e0 100644 --- a/modules/gallery/helpers/gallery_graphics.php +++ b/modules/gallery/helpers/gallery_graphics.php @@ -123,7 +123,7 @@ static function composite($input_file, $output_file, $options) { 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 e0b0368264..4d6de3ba18 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -66,7 +66,7 @@ static function rebuild_dirty_images($task) { } $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 d6a2f00cca..a78cadd0b1 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -171,7 +171,7 @@ static function generate($item) { } 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 72e3312d0e..056145599e 100644 --- a/modules/gallery/helpers/identity.php +++ b/modules/gallery/helpers/identity.php @@ -75,14 +75,14 @@ static function load_user() { 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 8f96c3d9d7..109fa6f88b 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -156,13 +156,7 @@ static function viewable($model) { $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 @@ static function viewable($model) { 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 3460cc6599..aaf6ff4602 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -136,7 +136,7 @@ static function fetch_updates() { $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 e36d419dc3..6c09a686ad 100644 --- a/modules/gallery/helpers/l10n_scanner.php +++ b/modules/gallery/helpers/l10n_scanner.php @@ -43,7 +43,7 @@ static function process_message($message, &$cache) { } $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 a3e098625f..302e42d961 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 e6c196ce18..e54a4352e8 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 @@ static function active() { * @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 @@ static function install($module_name) { // 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 @@ static function upgrade($module_name) { * @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 @@ static function activate($module_name) { } $module = self::get($module_name); - if ($module->loaded) { + if ($module->loaded()) { $module->active = true; $module->save(); } @@ -230,7 +232,7 @@ static function deactivate($module_name) { } $module = self::get($module_name); - if ($module->loaded) { + if ($module->loaded()) { $module->active = false; $module->save(); } @@ -257,7 +259,7 @@ static function uninstall($module_name) { 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 @@ static function load_modules() { } } 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 @@ static function get_var($module_name, $name, $default_value=null) { // 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 @@ static function set_var($module_name, $name, $value) { ->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 @@ static function clear_var($module_name, $name) { ->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 e84e8ea66b..a319471d08 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 01cf527838..90cb108fc9 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 2b09077664..d58b935d3e 100644 --- a/modules/gallery/helpers/site_status.php +++ b/modules/gallery/helpers/site_status.php @@ -69,7 +69,7 @@ private static function _add($msg, $severity, $permanent_key) { $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 @@ private static function _add($msg, $severity, $permanent_key) { */ 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 dac5f9d334..4aa95f3323 100644 --- a/modules/gallery/helpers/task.php +++ b/modules/gallery/helpers/task.php @@ -51,7 +51,7 @@ static function create($task_def, $context) { 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 @@ static function cancel($task_id) { 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 @@ static function run($task_id) { } $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 16ed104ea4..c7a9b49aa5 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -43,7 +43,7 @@ static function load_themes() { } $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 cbb781a149..c190f110bb 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -31,7 +31,7 @@ public function __construct($name) { 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 0571fe585e..42fae26602 100644 --- a/modules/gallery/libraries/Gallery_I18n.php +++ b/modules/gallery/libraries/Gallery_I18n.php @@ -128,21 +128,21 @@ private function lookup($locale, $message) { 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 3bf56d0f87..940c53216e 100644 --- a/modules/gallery/libraries/Gallery_View.php +++ b/modules/gallery/libraries/Gallery_View.php @@ -32,7 +32,7 @@ public function script($file) { 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 @@ public function css($file) { 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 @@ private function process_css($css_file) { $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 e213ae9768..bcb3056ae1 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -54,7 +54,7 @@ static function &instance() { */ static function reset() { self::$instance = null; - Kohana::config_clear("identity"); + Kohana_Config::instance()->clear("identity"); } /** @@ -90,7 +90,7 @@ public function __construct($config=null) { 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 2c9ad1d75f..56c776aa7e 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 eb55aca6d0..0311f2dd71 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 @@ public function render($print=false, $renderer=false) { 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 83d2445c7d..01b2d7b7e5 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -133,10 +133,10 @@ function parent() { */ 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 @@ function parents() { * @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 @@ function children($limit=null, $offset=0, $where=array(), $orderby=array("id" => * @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 @@ function children_count($where=array()) { * @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 @@ function descendants($limit=null, $offset=0, $where=array(), $orderby=array("id" * @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 ba3a8ffd85..cc63f3a79b 100644 --- a/modules/gallery/libraries/SafeString.php +++ b/modules/gallery/libraries/SafeString.php @@ -146,7 +146,7 @@ function unescaped() { * 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 7bc21a67c8..aa2b51a9b5 100644 --- a/modules/gallery/libraries/Sendmail.php +++ b/modules/gallery/libraries/Sendmail.php @@ -52,7 +52,7 @@ public function __call($key, $value) { 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 @@ public function __call($key, $value) { 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 b64deab909..03f67671ef 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -33,7 +33,7 @@ public function __construct($name, $page_type, $page_subtype) { 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 7e2aeabc6d..d27bcc32f6 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 @@ public function __construct() { * @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 @@ public function set($id, $data, array $tags = NULL, $lifetime) { $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 @@ public function find($tag) { * @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 @@ public function delete($id, $tag = false) { 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 @@ public function delete_expired() { 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 d27e331b43..bd1f9af58d 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -309,7 +309,7 @@ private function _build_relative_caches() { * @return string */ public function relative_path() { - if (!$this->loaded) { + if (!$this->loaded()) { return; } @@ -324,7 +324,7 @@ public function relative_path() { * @return string */ public function relative_url() { - if (!$this->loaded) { + if (!$this->loaded()) { return; } @@ -383,7 +383,7 @@ public function save() { 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 c816a4a782..a20443258c 100644 --- a/modules/gallery/models/log.php +++ b/modules/gallery/models/log.php @@ -28,7 +28,7 @@ public function __get($column) { 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 e9e5cb2612..d90d7ed6ee 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -106,15 +106,15 @@ public function adding_and_removing_items_adds_ands_removes_rows_test() { $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 0d8801e503..b9fdcc192e 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 9a40b0b9a5..d525e03e1b 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -38,7 +38,7 @@ static function is_watching($item, $user=null) { ->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 6b2df57436..e6d09d7438 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -25,8 +25,8 @@ static function item_updated($original, $new) { 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 @@ static function item_created($item) { 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 @@ static function item_deleted($item) { 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 @@ static function comment_created($comment) { 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 @@ static function comment_updated($original, $new) { 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 @@ static function user_before_delete($user) { ->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 @@ static function batch_complete() { 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 8c3bd3ab04..9d732c11a7 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -61,7 +61,7 @@ static function check_index() { 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 53a3d09168..2596112916 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -103,7 +103,7 @@ function run($task_id) { 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 @@ static function add($task) { // 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 67587c2e58..93b5181489 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -35,7 +35,7 @@ public function index() { 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 @@ public function delete($id) { access::verify_csrf(); $tag = ORM::factory("tag", $id); - if (!$tag->loaded) { + if (!$tag->loaded()) { kohana::show_404(); } @@ -68,7 +68,7 @@ public function delete($id) { 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 @@ public function rename($id) { 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 feaf40c51b..6ce1862504 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -34,7 +34,7 @@ static function add($item, $tag_name) { } $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 a857a99d28..6ee8e708ff 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -51,7 +51,7 @@ static function item_created($photo) { 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 de5d6c72ab..03017dc390 100644 --- a/modules/tag/helpers/tag_rss.php +++ b/modules/tag/helpers/tag_rss.php @@ -31,7 +31,7 @@ static function available_feeds($item, $tag) { 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 b328438565..619e6e18fd 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -265,7 +265,7 @@ public function edit_group($id) { 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 e18e76b672..8309d2cc79 100644 --- a/modules/user/controllers/password.php +++ b/modules/user/controllers/password.php @@ -47,7 +47,7 @@ private function _send_reset() { $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 3aaf1b116c..1beaa1c248 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 @@ static function lookup_by_name($name) { 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 f9f16da5a6..4ed9daeee5 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -45,7 +45,7 @@ static function guest() { */ 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 @@ static function get_user_list($filter=array()) { 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 4432fc69fb..81f779cf7b 100644 --- a/modules/user/models/group.php +++ b/modules/user/models/group.php @@ -34,7 +34,7 @@ public function delete($id=null) { } 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 bd61def822..0d5a2bcd4b 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -62,7 +62,7 @@ public function avatar_url($size=80, $default=null) { } 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 3da8dd34a1..6aedfde584 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) { }