mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-05-04 03:59:09 -04:00
Change the API for getting to the original state of an ORM.
Old API: $obj->original("field_name")
New API: $obj->original()->field_name
This allows us to revert the varous xxx_updated events back to passing
an original ORM as well as the the updated one. This makes for a
cleaner event API.
Old API: comment_updated($comment) { $comment->original("field_name") }
Old API: comment_updated($old, $new) { $old->field_name }
This commit is contained in:
@@ -40,14 +40,14 @@ class akismet_event_Core {
|
||||
$comment->save();
|
||||
}
|
||||
|
||||
static function comment_updated($comment) {
|
||||
static function comment_updated($original, $new) {
|
||||
if (!module::get_var("akismet", "api_key")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($comment->original("state") != "spam" && $comment->state == "spam") {
|
||||
if ($original->state != "spam" && $new->state == "spam") {
|
||||
akismet::submit_spam($new);
|
||||
} else if ($comment->original("state") == "spam" && $comment->state != "spam") {
|
||||
} else if ($original->state == "spam" && $new->state != "spam") {
|
||||
akismet::submit_ham($new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,17 +64,17 @@ class Comment_Model extends ORM {
|
||||
$created = true;
|
||||
}
|
||||
}
|
||||
$visible_change = $this->original()->state == "published" || $this->state == "published";
|
||||
parent::save();
|
||||
|
||||
if (isset($created)) {
|
||||
module::event("comment_created", $this);
|
||||
} else {
|
||||
module::event("comment_updated", $this);
|
||||
module::event("comment_updated", $this->original(), $this);
|
||||
}
|
||||
|
||||
// We only notify on the related items if we're making a visible change, which means moving in
|
||||
// or out of a published state
|
||||
if ($this->original("state") == "published" || $this->state == "published") {
|
||||
// We only notify on the related items if we're making a visible change.
|
||||
if ($visible_change) {
|
||||
module::event("item_related_update", $this->item());
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class ORM extends ORM_Core {
|
||||
// Track the original value of this ORM instance so that we can look it up in ORM::original()
|
||||
// Track the original value of this ORM so that we can look it up in ORM::original()
|
||||
protected $original = null;
|
||||
|
||||
public function open_paren() {
|
||||
@@ -34,13 +34,13 @@ class ORM extends ORM_Core {
|
||||
public function save() {
|
||||
model_cache::clear();
|
||||
$result = parent::save();
|
||||
$this->original = $this->object;
|
||||
$this->original = clone $this;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function __set($column, $value) {
|
||||
if (!isset($this->original)) {
|
||||
$this->original = $this->object;
|
||||
$this->original = clone $this;
|
||||
}
|
||||
|
||||
return parent::__set($column, $value);
|
||||
@@ -48,14 +48,14 @@ class ORM extends ORM_Core {
|
||||
|
||||
public function __unset($column) {
|
||||
if (!isset($this->original)) {
|
||||
$this->original = $this->object;
|
||||
$this->original = clone $this;
|
||||
}
|
||||
|
||||
return parent::__unset($column);
|
||||
}
|
||||
|
||||
public function original($column) {
|
||||
return $this->original[$column];
|
||||
public function original() {
|
||||
return $this->original;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ class Item_Model extends ORM_MPTT {
|
||||
}
|
||||
parent::save();
|
||||
if (isset($send_event)) {
|
||||
module::event("item_updated", $this);
|
||||
module::event("item_updated", $this->original(), $this);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ class Item_Model_Test extends Unit_Test_Case {
|
||||
$item->save();
|
||||
$item->title = "NEW_VALUE";
|
||||
|
||||
$this->assert_same("ORIGINAL_VALUE", $item->original("title"));
|
||||
$this->assert_same("ORIGINAL_VALUE", $item->original()->title);
|
||||
$this->assert_same("NEW_VALUE", $item->title);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class notification_event_Core {
|
||||
static function item_updated($item) {
|
||||
notification::send_item_updated($item);
|
||||
static function item_updated($original, $new) {
|
||||
notification::send_item_updated($new);
|
||||
}
|
||||
|
||||
static function item_created($item) {
|
||||
@@ -40,8 +40,8 @@ class notification_event_Core {
|
||||
}
|
||||
}
|
||||
|
||||
static function comment_updated($item) {
|
||||
if ($item->state == "published" && $item->original("state") != "published") {
|
||||
static function comment_updated($original, $new) {
|
||||
if ($new->state == "published" && $original->state != "published") {
|
||||
notification::send_comment_published($new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ class search_event_Core {
|
||||
search::update($item);
|
||||
}
|
||||
|
||||
static function item_updated($item) {
|
||||
search::update($item);
|
||||
static function item_updated($original, $new) {
|
||||
search::update($new);
|
||||
}
|
||||
|
||||
static function item_deleted($item) {
|
||||
|
||||
@@ -41,7 +41,7 @@ class Group_Model extends ORM {
|
||||
if (isset($created)) {
|
||||
module::event("group_created", $this);
|
||||
} else {
|
||||
module::event("group_updated", $this);
|
||||
module::event("group_updated", $this->original(), $this);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class User_Model extends ORM {
|
||||
if (isset($created)) {
|
||||
module::event("user_created", $this);
|
||||
} else {
|
||||
module::event("user_updated", $this);
|
||||
module::event("user_updated", $this->original(), $this);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user