summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/comment/models/comment.php4
-rw-r--r--modules/gallery/libraries/MY_ORM.php20
-rw-r--r--modules/gallery/models/item.php3
-rw-r--r--modules/gallery/tests/Item_Model_Test.php1
-rw-r--r--modules/notification/helpers/notification.php11
-rw-r--r--modules/notification/helpers/notification_event.php3
-rw-r--r--modules/notification/views/item_updated.html.php4
-rw-r--r--modules/user/models/group.php4
-rw-r--r--modules/user/models/user.php4
9 files changed, 24 insertions, 30 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/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php
index 1bf5dd13..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($reload_all=true) {
- if ($reload_all) {
- 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/models/item.php b/modules/gallery/models/item.php
index 395ba52c..46b0304e 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -442,8 +442,9 @@ class Item_Model extends ORM_MPTT {
->where("right_ptr", "<", $this->right_ptr)
->execute();
}
+ $original = clone $this->original();
parent::save();
- module::event("item_updated", $this->original(), $this);
+ module::event("item_updated", $original, $this);
}
}
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);
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 @@
<h2> <?= html::clean($subject) ?> </h2>
<table>
<tr>
- <? if ($item->original("title") != $item->title): ?>
+ <? if ($original->title != $item->title): ?>
<td><?= t("New title:") ?></td>
<td><?= html::clean($item->title) ?></td>
<? else: ?>
@@ -19,7 +19,7 @@
<td><?= t("Url:") ?></td>
<td><a href="<?= $item->abs_url() ?>"><?= $item->abs_url() ?></a></td>
</tr>
- <? if ($item->original("description") != $item->description): ?>
+ <? if ($original->description != $item->description): ?>
<tr>
<td><?= t("New description:") ?></td>
<td><?= html::clean($item->description) ?></td>
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;
}