summaryrefslogtreecommitdiff
path: root/modules/tag/models
diff options
context:
space:
mode:
authorNathan Kinkade <nath@nkinka.de>2011-05-12 23:48:54 +0000
committerNathan Kinkade <nath@nkinka.de>2011-05-12 23:48:54 +0000
commit2ad445441974c64599df496ba4a585415aa41169 (patch)
tree49b2860fdac2d2ff16134bfa2aa8d8a972b93301 /modules/tag/models
parent1f7c1f18c651c58048e92d615c71ac0fe6691c10 (diff)
parent9aeb824aa1d15bd94bd7cef0a322c4e8a667e67b (diff)
Manually merged a conflict after pulling from upstream.
Diffstat (limited to 'modules/tag/models')
-rw-r--r--modules/tag/models/tag.php24
1 files changed, 17 insertions, 7 deletions
diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php
index 6bc5350a..3dd71d8d 100644
--- a/modules/tag/models/tag.php
+++ b/modules/tag/models/tag.php
@@ -70,13 +70,23 @@ class Tag_Model_Core extends ORM {
* to this tag.
*/
public function save() {
- $related_item_ids = array();
- foreach (db::build()
- ->select("item_id")
- ->from("items_tags")
- ->where("tag_id", "=", $this->id)
- ->execute() as $row) {
- $related_item_ids[$row->item_id] = 1;
+ // 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
+ $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) {
+ $this->add($item);
+ }
+
+ // ... and remove the duplicate tag
+ $duplicate_tag->delete();
}
if (isset($this->object_relations["items"])) {