diff options
author | Nathan Kinkade <nath@nkinka.de> | 2011-05-12 23:48:54 +0000 |
---|---|---|
committer | Nathan Kinkade <nath@nkinka.de> | 2011-05-12 23:48:54 +0000 |
commit | 2ad445441974c64599df496ba4a585415aa41169 (patch) | |
tree | 49b2860fdac2d2ff16134bfa2aa8d8a972b93301 /modules/tag | |
parent | 1f7c1f18c651c58048e92d615c71ac0fe6691c10 (diff) | |
parent | 9aeb824aa1d15bd94bd7cef0a322c4e8a667e67b (diff) |
Manually merged a conflict after pulling from upstream.
Diffstat (limited to 'modules/tag')
-rw-r--r-- | modules/tag/controllers/admin_tags.php | 31 | ||||
-rw-r--r-- | modules/tag/controllers/tags.php | 3 | ||||
-rw-r--r-- | modules/tag/helpers/tag.php | 1 | ||||
-rw-r--r-- | modules/tag/helpers/tag_block.php | 2 | ||||
-rw-r--r-- | modules/tag/helpers/tag_installer.php | 7 | ||||
-rw-r--r-- | modules/tag/models/tag.php | 24 | ||||
-rw-r--r-- | modules/tag/module.info | 6 | ||||
-rw-r--r-- | modules/tag/tests/Tag_Test.php | 50 |
8 files changed, 97 insertions, 27 deletions
diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index 73042a55..77b5f20a 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -81,17 +81,25 @@ class Admin_Tags_Controller extends Admin_Controller { $in_place_edit = InPlaceEdit::factory($tag->name) ->action("admin/tags/rename/$tag->id") - ->rules(array("required", "length[1,64]")) - ->messages(array("in_use" => t("There is already a tag with that name"))) - ->callback(array($this, "check_for_duplicate")); + ->rules(array("required", "length[1,64]")); if ($in_place_edit->validate()) { $old_name = $tag->name; - $tag->name = $in_place_edit->value(); + $new_name_or_list = $in_place_edit->value(); + $tag_list = explode(",", $new_name_or_list); + + $tag->name = array_shift($tag_list); $tag->save(); - $message = t("Renamed tag <b>%old_name</b> to <b>%new_name</b>", - array("old_name" => $old_name, "new_name" => $tag->name)); + if (!empty($tag_list)) { + $this->_copy_items_for_tags($tag, $tag_list); + $message = t("Split tag <i>%old_name</i> into <i>%tag_list</i>", + array("old_name" => $old_name, "tag_list" => $new_name_or_list)); + } else { + $message = t("Renamed tag <i>%old_name</i> to <i>%new_name</i>", + array("old_name" => $old_name, "new_name" => $tag->name)); + } + message::success($message); log::success("tags", $message); @@ -101,12 +109,11 @@ class Admin_Tags_Controller extends Admin_Controller { } } - public function check_for_duplicate(Validation $post_data, $field) { - $tag_exists = ORM::factory("tag")->where("name", "=", $post_data[$field])->count_all(); - if ($tag_exists) { - $post_data->add_error($field, "in_use"); + private function _copy_items_for_tags($tag, $tag_list) { + foreach ($tag->items() as $item) { + foreach ($tag_list as $new_tag_name) { + tag::add($item, trim($new_tag_name)); + } } } - } - diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index fe6d747b..bf41c4df 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -22,7 +22,8 @@ class Tags_Controller extends Controller { // Far from perfection, but at least require view permission for the root album $album = ORM::factory("item", 1); access::required("view", $album); - print tag::cloud(30); + + print tag::cloud(module::get_var("tag", "tag_cloud_size", 30)); } public function create($item_id) { diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 733215b3..c21104ee 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -48,6 +48,7 @@ class tag_Core { * @return ORM_Iterator of Tag_Model in descending tag count order */ static function popular_tags($count) { + $count = max($count, 1); return ORM::factory("tag") ->order_by("count", "DESC") ->limit($count) diff --git a/modules/tag/helpers/tag_block.php b/modules/tag/helpers/tag_block.php index 0ee0f5f5..74656a0a 100644 --- a/modules/tag/helpers/tag_block.php +++ b/modules/tag/helpers/tag_block.php @@ -30,7 +30,7 @@ class tag_block_Core { $block->css_id = "g-tag"; $block->title = t("Tags"); $block->content = new View("tag_block.html"); - $block->content->cloud = tag::cloud(250); + $block->content->cloud = tag::cloud(module::get_var("tag", "tag_cloud_size", 250)); if ($theme->item() && $theme->page_subtype() != "tag" && access::can("edit", $theme->item())) { $controller = new Tags_Controller(); diff --git a/modules/tag/helpers/tag_installer.php b/modules/tag/helpers/tag_installer.php index 16ad1239..66a78b91 100644 --- a/modules/tag/helpers/tag_installer.php +++ b/modules/tag/helpers/tag_installer.php @@ -36,7 +36,8 @@ class tag_installer { KEY(`tag_id`, `id`), KEY(`item_id`, `id`)) DEFAULT CHARSET=utf8;"); - module::set_version("tag", 2); + module::set_var("tag", "tag_cloud_size", 30); + module::set_version("tag", 3); } static function upgrade($version) { @@ -45,6 +46,10 @@ class tag_installer { $db->query("ALTER TABLE {tags} MODIFY COLUMN `name` VARCHAR(128)"); module::set_version("tag", $version = 2); } + if ($version == 2) { + module::set_var("tag", "tag_cloud_size", 30); + module::set_version("tag", $version = 3); + } } static function uninstall() { 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"])) { diff --git a/modules/tag/module.info b/modules/tag/module.info index 8851d119..75d16bf0 100644 --- a/modules/tag/module.info +++ b/modules/tag/module.info @@ -1,3 +1,7 @@ name = "Tags" description = "Allows users to tag photos and albums" -version = 2 +version = 3 +author_name = "Gallery Team" +author_url = "http://codex.gallery2.org/Gallery:Team" +info_url = "http://codex.gallery2.org/Gallery3:Modules:tag" +discuss_url = "http://gallery.menalto.com/forum_module_tag" diff --git a/modules/tag/tests/Tag_Test.php b/modules/tag/tests/Tag_Test.php index f5ccb3a2..9e10fa4a 100644 --- a/modules/tag/tests/Tag_Test.php +++ b/modules/tag/tests/Tag_Test.php @@ -18,18 +18,60 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Tag_Test extends Gallery_Unit_Test_Case { + public function teardown() { + ORM::factory("tag")->delete_all(); + } + public function create_tag_test() { $album = test::random_album(); tag::add($album, "tag1"); $tag = ORM::factory("tag")->where("name", "=", "tag1")->find(); - $this->assert_true(1, $tag->count); + $this->assert_equal(1, $tag->count); // Make sure adding the tag again doesn't increase the count tag::add($album, "tag1"); - $this->assert_true(1, $tag->reload()->count); + $this->assert_equal(1, $tag->reload()->count); tag::add(test::random_album(), "tag1"); - $this->assert_true(2, $tag->reload()->count); + $this->assert_equal(2, $tag->reload()->count); + } + + public function rename_merge_tag_test() { + $album1 = test::random_album(); + $album2 = test::random_album(); + + tag::add($album1, "tag1"); + tag::add($album2, "tag2"); + + $tag1 = ORM::factory("tag")->where("name", "=", "tag1")->find(); + $tag1->name = "tag2"; + $tag1->save(); + + // Tags should be merged; $tag2 should be deleted + $tag1->reload(); + + $this->assert_equal(2, $tag1->count); + $this->assert_true($tag1->has($album1)); + $this->assert_true($tag1->has($album2)); + $this->assert_equal(1, ORM::factory("tag")->count_all()); + } + + public function rename_merge_tag_with_same_items_test() { + $album = test::random_album(); + + tag::add($album, "tag1"); + tag::add($album, "tag2"); + + $tag1 = ORM::factory("tag")->where("name", "=", "tag1")->find(); + $tag1->name = "tag2"; + $tag1->save(); + + // Tags should be merged + $tag1->reload(); + + $this->assert_equal(1, $tag1->count); + $this->assert_true($tag1->has($album)); + $this->assert_equal(1, ORM::factory("tag")->count_all()); } -}
\ No newline at end of file +} |