diff options
| author | Chad Parry <github@chad.parry.org> | 2011-04-24 08:28:39 -0600 |
|---|---|---|
| committer | Chad Parry <github@chad.parry.org> | 2011-04-24 08:28:39 -0600 |
| commit | 26585fed03236f0f70a75959e1d3002025f4e15e (patch) | |
| tree | 33a89567f40dbbdb8affcbe76baa27b242bc6d75 /modules/tag/models | |
| parent | 809567f12850f59bdeb47a2963f6968b99b5a201 (diff) | |
| parent | c8f90e861b866d0caa86343a6c7213e923023d39 (diff) | |
Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto
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"]); |
