diff options
| author | Chad Kieffer <ckieffer@gmail.com> | 2011-04-23 23:26:40 -0400 |
|---|---|---|
| committer | Chad Kieffer <ckieffer@gmail.com> | 2011-04-23 23:26:40 -0400 |
| commit | bbb2a3a30c57592b1baed17533bc3a2e7edb2e8a (patch) | |
| tree | 8cac738aace3d4ae1d237fcd619a5e2e33275948 /modules/tag/models | |
| parent | 342be9818f8c35dd13c8159960a9f71ae33d4c72 (diff) | |
| parent | 4c7f27a1a6a4fc71873093dd787de05a8ee6c079 (diff) | |
Merge branch 'master' of git://github.com/gallery/gallery3
Diffstat (limited to 'modules/tag/models')
| -rw-r--r-- | modules/tag/models/tag.php | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index bd665667..13e253ba 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -69,15 +69,22 @@ 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. + foreach ($duplicate_tag->items() as $item) { + $this->add($item); + } + + // ... and remove the duplicate tag + $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"]); |
