From 99073c3e201c0d2770909781ad0afefdd9d44931 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 15 Jan 2010 23:53:35 -0800 Subject: Revert "Did the old commit then save trick" This reverts commit e41ad23a8ea05d28a99d12c01d8f317455b1d361. --- modules/gallery/libraries/MY_ORM.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php index 1bf5dd13..95fa9006 100644 --- a/modules/gallery/libraries/MY_ORM.php +++ b/modules/gallery/libraries/MY_ORM.php @@ -47,8 +47,8 @@ class ORM extends ORM_Core { return parent::__unset($column); } - public function reload($reload_all=true) { - if ($reload_all) { + public function reload($original_only=false) { + if (!$original_only) { parent::reload(); } $this->original = clone $this; -- cgit v1.2.3 From 00c73a4b072d2ad4e45323234b847da4f69d99a3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 15 Jan 2010 23:53:43 -0800 Subject: Revert "Fix for ticket #978. Don't reset the original property as part of the save processing, because that will overwrite the original values with all the new values. The problem with the original approach is that when changed event handlers used ->original(), it had already been reset as part of the save processing. Went back and forth on either leaving this alone and forcing callers to save the original prior to calling the save function, but there were a few event handlers that used ->original(). This seemed the easier change. So to reset the original you need to call reload() or clear(). There is now an optional parameter on the reload to only reload the original." This reverts commit daeaca110d16128040c86727c65df225e957f7c6. --- modules/gallery/libraries/MY_ORM.php | 20 ++------------------ modules/gallery/tests/Item_Model_Test.php | 1 - 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php index 95fa9006..56c776aa 100644 --- a/modules/gallery/libraries/MY_ORM.php +++ b/modules/gallery/libraries/MY_ORM.php @@ -19,11 +19,12 @@ */ class ORM extends ORM_Core { // Track the original value of this ORM so that we can look it up in ORM::original() - protected $original; + protected $original = null; public function save() { model_cache::clear(); $result = parent::save(); + $this->original = clone $this; return $result; } @@ -47,24 +48,7 @@ class ORM extends ORM_Core { return parent::__unset($column); } - public function reload($original_only=false) { - if (!$original_only) { - parent::reload(); - } - $this->original = clone $this; - return $this; - } - - public function clear() { - parent::clear(); - $this->original = clone $this; - return $this; - } - public function original() { - if (!isset($this->original)) { - $this->original = clone $this; - } return $this->original; } } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index c0ac4436..bf5fca1a 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -166,7 +166,6 @@ class Item_Model_Test extends Unit_Test_Case { $item = self::_create_random_item(); $item->title = "ORIGINAL_VALUE"; $item->save(); - $item->reload(false); $item->title = "NEW_VALUE"; $this->assert_same("ORIGINAL_VALUE", $item->original()->title); -- cgit v1.2.3 From 9f03d36d6ee5358b3081f64fc7ef0b0ae42d97db Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 16 Jan 2010 00:10:55 -0800 Subject: Don't use MY_ORM::original() here since the values may not have changed since the last save. Instead, use the original ORM passed in. --- modules/notification/helpers/notification.php | 11 +++++++---- modules/notification/helpers/notification_event.php | 3 ++- modules/notification/views/item_updated.html.php | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index a2271b59..dfeab9fc 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -92,19 +92,22 @@ class notification { return array_keys($subscribers); } - static function send_item_updated($item) { + static function send_item_updated($original, $item) { $subscribers = self::get_subscribers($item); if (!$subscribers) { return; } $v = new View("item_updated.html"); + $v->original = $original; $v->item = $item; $v->subject = $item->is_album() ? - t("Album \"%title\" updated", array("title" => $item->original()->title)) : + t("Album \"%title\" updated", array("title" => $original->title)) : ($item->is_photo() ? - t("Photo \"%title\" updated", array("title" => $item->original()->title)) - : t("Movie \"%title\" updated", array("title" => $item->original()->title))); + t("Photo \"%title\" updated", array("title" => $original->title)) + : t("Movie \"%title\" updated", array("title" => $original->title))); + + Kohana_Log::add("error",print_r($v->render(),1)); self::_notify($subscribers, $item, $v->render(), $v->subject); } diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index bc1303f5..76afac9c 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -22,8 +22,9 @@ class notification_event_Core { // don't want to screw up the processing that was generating the notification // so we don't pass the exception up the call stack static function item_updated($original, $new) { + Kohana_Log::add("error",print_r("item_updated({$original->title}, {$new->title})",1)); try { - notification::send_item_updated($new); + notification::send_item_updated($original, $new); } catch (Exception $e) { Kohana_Log::add("error", "@todo notification_event::item_updated() failed"); Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); diff --git a/modules/notification/views/item_updated.html.php b/modules/notification/views/item_updated.html.php index 47856cab..7020fd53 100644 --- a/modules/notification/views/item_updated.html.php +++ b/modules/notification/views/item_updated.html.php @@ -7,7 +7,7 @@

- original("title") != $item->title): ?> + title != $item->title): ?> @@ -19,7 +19,7 @@ - original("description") != $item->description): ?> + description != $item->description): ?> -- cgit v1.2.3 From dcf4b5e71ae8a097f133a06485d60c5fb3400824 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 16 Jan 2010 00:13:28 -0800 Subject: Don't pass MY_ORM::original() to update event handlers, since after parent::save() it'll be reset. Clone it first. This is an alternate fix for #978. --- modules/comment/models/comment.php | 4 +++- modules/gallery/models/item.php | 4 +++- modules/user/models/group.php | 4 +++- modules/user/models/user.php | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index 59b85233..e0b82039 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -65,12 +65,14 @@ class Comment_Model extends ORM { } } $visible_change = $this->original()->state == "published" || $this->state == "published"; + + $original = clone $this->original(); parent::save(); if (isset($created)) { module::event("comment_created", $this); } else { - module::event("comment_updated", $this->original(), $this); + module::event("comment_updated", $original, $this); } // We only notify on the related items if we're making a visible change. diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 4a3d26e9..6851e1a3 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -416,9 +416,11 @@ class Item_Model extends ORM_MPTT { $send_event = 1; } } + + $original = clone $this->original(); parent::save(); if (isset($send_event)) { - module::event("item_updated", $this->original(), $this); + module::event("item_updated", $original, $this); } return $this; } diff --git a/modules/user/models/group.php b/modules/user/models/group.php index 515788a3..10f6f4b3 100644 --- a/modules/user/models/group.php +++ b/modules/user/models/group.php @@ -41,11 +41,13 @@ class Group_Model extends ORM implements Group_Definition { if (!$this->loaded()) { $created = 1; } + + $original = clone $this->original(); parent::save(); if (isset($created)) { module::event("group_created", $this); } else { - module::event("group_updated", $this->original(), $this); + module::event("group_updated", $original, $this); } return $this; } diff --git a/modules/user/models/user.php b/modules/user/models/user.php index 7d5bf413..edba2a2c 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -69,11 +69,13 @@ class User_Model extends ORM implements User_Definition { if (!$this->loaded()) { $created = 1; } + + $original = clone $this->original(); parent::save(); if (isset($created)) { module::event("user_created", $this); } else { - module::event("user_updated", $this->original(), $this); + module::event("user_updated", $original, $this); } return $this; } -- cgit v1.2.3
title) ?> abs_url() ?>
description) ?>