From 5ce85636329b14673718836b3631a3e46efdc3bb Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 23 Apr 2011 13:20:22 -0700 Subject: 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. --- modules/tag/models/tag.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'modules/tag') 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)) { -- cgit v1.2.3