From 67d2e8081c6e5f0b679881bca3fdc81fe1e78ccc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 23 Apr 2011 16:12:10 -0700 Subject: Undo the change made in 5ce85636329b14673718836b3631a3e46efdc3bb because it messes up tag counts (and makes the test fail-- I should have run that!). Also, use Tag_Model::items() in save() to avoid code duplication. Follow-on for #1628. --- modules/tag/models/tag.php | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'modules/tag/models') diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index d4e385a2..13e253ba 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -69,29 +69,14 @@ 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. 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) - ->find_all(); - foreach ($duplicate_tag_items as $item) { + // If so, tag its items with this tag so as to merge it. + foreach ($duplicate_tag->items() as $item) { $this->add($item); } @@ -99,6 +84,16 @@ class Tag_Model_Core extends ORM { $duplicate_tag->delete(); } + // 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); + } + $result = parent::save(); if (!empty($changed)) { -- cgit v1.2.3