Skip to content

Commit

Permalink
Preliminary work to cut over to Kohana 2.4
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
bharat committed Nov 25, 2009
1 parent e201536 commit 2e42052
Show file tree
Hide file tree
Showing 63 changed files with 257 additions and 225 deletions.
4 changes: 2 additions & 2 deletions modules/akismet/helpers/akismet.php
Expand Up @@ -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) ) {
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/comment/controllers/admin_comments.php
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion modules/comment/models/comment.php
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/comment/tests/Comment_Event_Test.php
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion modules/digibug/controllers/digibug.php
Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions modules/exif/helpers/exif.php
Expand Up @@ -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);
Expand All @@ -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();
}

Expand Down
14 changes: 7 additions & 7 deletions modules/g2_import/helpers/g2_import.php
Expand Up @@ -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";
Expand All @@ -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();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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];
Expand All @@ -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);
}
}

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion modules/g2_import/helpers/g2_import_task.php
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions modules/gallery/controllers/admin_maintenance.php
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
}

Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion modules/gallery/controllers/albums.php
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions modules/gallery/controllers/file_proxy.php
Expand Up @@ -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.
Expand All @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions modules/gallery/controllers/l10n_client.php
Expand Up @@ -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));
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/controllers/permissions.php
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions modules/gallery/controllers/rest.php
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/controllers/simple_uploader.php
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/gallery/helpers/MY_url.php
Expand Up @@ -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;
Expand All @@ -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))
Expand Down
18 changes: 9 additions & 9 deletions modules/gallery/helpers/access.php
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/helpers/album.php
Expand Up @@ -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");
}

Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/helpers/auth.php
Expand Up @@ -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);
}
Expand Down

0 comments on commit 2e42052

Please sign in to comment.