diff options
author | Bharat Mediratta <bharat@menalto.com> | 2011-04-23 13:20:22 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2011-04-23 13:20:22 -0700 |
commit | 5ce85636329b14673718836b3631a3e46efdc3bb (patch) | |
tree | 8734458a25d01980940e2b1be47b066844db8b49 | |
parent | b57b229543aeab096e8574e9f27cff5d6a9ed07c (diff) |
Move the calculation for item_related_update ahead of the duplicate
tag merge so that we don't trigger an item_related_update on items
who semantically have the same tag after the merge. Follow-on for #1628.
-rw-r--r-- | modules/tag/models/tag.php | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index bb79e707..d4e385a2 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -69,13 +69,24 @@ class Tag_Model_Core extends ORM { * to this tag. */ public function save() { + // Figure out what items have changed in this tag for our item_related_update event below + if (isset($this->object_relations["items"])) { + $added = array_diff($this->changed_relations["items"], $this->object_relations["items"]); + $removed = array_diff($this->object_relations["items"], $this->changed_relations["items"]); + if (isset($this->changed_relations["items"])) { + $changed = array_merge($added, $removed); + } + $this->count = count($this->object_relations["items"]) + count($added) - count($removed); + } + // Check to see if another tag exists with the same name $duplicate_tag = ORM::factory("tag") ->where("name", "=", $this->name) ->where("id", "!=", $this->id) ->find(); if ($duplicate_tag->loaded()) { - // If so, tag its items with this tag so as to merge it + // If so, tag its items with this tag so as to merge it. Do this after we figure out what's + // changed so that we don't notify on this change to keep churn down. $duplicate_tag_items = ORM::factory("item") ->join("items_tags", "items.id", "items_tags.item_id") ->where("items_tags.tag_id", "=", $duplicate_tag->id) @@ -88,15 +99,6 @@ class Tag_Model_Core extends ORM { $duplicate_tag->delete(); } - if (isset($this->object_relations["items"])) { - $added = array_diff($this->changed_relations["items"], $this->object_relations["items"]); - $removed = array_diff($this->object_relations["items"], $this->changed_relations["items"]); - if (isset($this->changed_relations["items"])) { - $changed = array_merge($added, $removed); - } - $this->count = count($this->object_relations["items"]) + count($added) - count($removed); - } - $result = parent::save(); if (!empty($changed)) { |