From 512f22a600362415f58197842248acc2f2f68be8 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 9 Jul 2009 17:18:58 -0700 Subject: Change the tag importer to convert spaces to a dot in multi word tags. --- modules/g2_import/helpers/g2_import.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'modules/g2_import/helpers/g2_import.php') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index d67d4c04..66787467 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -623,8 +623,10 @@ class g2_import_Core { } $tags = ""; + // Multiword tags have the space changed to dots.s foreach ($tag_names as $tag_name) { - $tags .= (strlen($tags) ? ", " : "") . tag::add($g3_item, $tag_name); + $tags .= (strlen($tags) ? ", " : "") . + tag::add($g3_item, preg_replace('/\s\s+/', '.', $tag_name)); } // Tag operations are idempotent so we don't need to map them. Which is good because we don't -- cgit v1.2.3 From 67d78e8d58fa5060e42fcef73d3c6de19209c216 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 9 Jul 2009 21:41:59 -0700 Subject: Correct the pattern match to compress multiple spaces into a single dot. --- modules/g2_import/helpers/g2_import.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/g2_import/helpers/g2_import.php') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 66787467..7dd799c8 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -626,7 +626,7 @@ class g2_import_Core { // Multiword tags have the space changed to dots.s foreach ($tag_names as $tag_name) { $tags .= (strlen($tags) ? ", " : "") . - tag::add($g3_item, preg_replace('/\s\s+/', '.', $tag_name)); + tag::add($g3_item, preg_replace('/\s+/', '.', $tag_name)); } // Tag operations are idempotent so we don't need to map them. Which is good because we don't -- cgit v1.2.3 From 7de339a676f32ed445f3e4215c994a5fe16c1188 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 14 Jul 2009 16:10:37 -0700 Subject: Remove extra debug statements. --- modules/g2_import/helpers/g2_import.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'modules/g2_import/helpers/g2_import.php') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 7dd799c8..8b4169dd 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -471,8 +471,6 @@ class g2_import_Core { $corrupt = 1; } try { - Kohana::log("error", "description: " . self::extract_description($g2_item)); - Kohana::log("error", "title: " . $g2_item->getTitle()); $item = photo::create( $parent, $g2_path, -- cgit v1.2.3 From 3b7855010f3b3ef84fc7a3b8889f58edaab9c5cc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 18 Jul 2009 16:07:28 -0700 Subject: Reduce import logging to errors only to reduce the size of the logs. Excessive logging results in a very slow import. --- modules/g2_import/helpers/g2_import.php | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'modules/g2_import/helpers/g2_import.php') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 8b4169dd..134edcff 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -376,12 +376,10 @@ class g2_import_Core { } $album->save(); - $message[] = t("Album '%name' imported.", array("name" => $album->name)); - $message[] = self::import_keywords_as_tags($g2_album->getKeywords(), $album); + self::import_keywords_as_tags($g2_album->getKeywords(), $album); self::set_map($g2_album_id, $album->id); // @todo import album highlights - return $message; } /** @@ -401,7 +399,6 @@ class g2_import_Core { } $table = g2(GalleryCoreApi::fetchThumbnailsByItemIds(array($g2_album_id))); - $message = ""; if (isset($table[$g2_album_id])) { // Backtrack the source id to an item $g2_source = $table[$g2_album_id]; @@ -417,10 +414,8 @@ class g2_import_Core { $g2_album->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_album_id)); $g2_album->save(); graphics::generate($g2_album); - $message = t("Highlight created for album '%name'", array("name" => $g2_album->name)); } } - return $message; } /** @@ -478,7 +473,6 @@ class g2_import_Core { self::_decode_html_special_chars($g2_item->getTitle()), self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); - $message[].= t("Imported photo: '%title'", array("title" => p::purify($item->title))); } catch (Exception $e) { Kohana::log( "alert", "Corrupt image $g2_path\n" . $e->__toString()); @@ -499,7 +493,6 @@ class g2_import_Core { self::_decode_html_special_chars($g2_item->getTitle()), self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); - $message[] = t("Imported movie: '%title'", array("title" => p::purify($item->title))); } catch (Exception $e) { Kohana::log("alert", "Corrupt movie $g2_path\n" . $e->__toString()); $message[] = t("Corrupt movie '%path'", array("path" => $g2_path)); @@ -520,14 +513,13 @@ class g2_import_Core { } if (!empty($item)) { - $message[] = self::import_keywords_as_tags($g2_item->getKeywords(), $item); + self::import_keywords_as_tags($g2_item->getKeywords(), $item); } if (isset($item)) { self::set_map($g2_item_id, $item->id); $item->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_item_id)); $item->save(); - $message[] = t("View count updated: %count", array("count" => $item->view_count)); } if ($corrupt) { @@ -629,15 +621,9 @@ class g2_import_Core { // Tag operations are idempotent so we don't need to map them. Which is good because we don't // have an id for each individual tag mapping anyway so it'd be hard to set up the mapping. - return t("Added '%tags' to '%title'", array("tags" => $tags, - "title" => p::purify($item->title))); } static function import_keywords_as_tags($keywords, $item) { - if (!module::is_active("tag")) { - return t("Gallery 3 tag module is inactive, no keywords will be imported"); - } - // Keywords in G2 are free form. So we don't know what our user used as a separator. Try to // be smart about it. If we see a comma or a semicolon, expect the keywords to be separated // by that delimeter. Otherwise, use space as the delimiter. @@ -656,8 +642,6 @@ class g2_import_Core { $tags .= (strlen($tags) ? ", " : "") . tag::add($item, $keyword); } } - return strlen($tags) ? t("Added '%keywords' to '%title'", - array("keywords" => $tags, "title" => p::purify($item->title))) : ""; } /** -- cgit v1.2.3 From ecc9203c2352bdfa3738998f27268293345ec0e9 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 28 Jul 2009 04:54:20 +0800 Subject: Standardize the specification of tags. With this patch a comma(,) is the only valid tag separator. Spaces are allowed in tags and phrases no longer need to be specified with a dot. Signed-off-by: Tim Almdal --- modules/g2_import/helpers/g2_import.php | 2 +- modules/tag/controllers/tags.php | 6 +++--- modules/tag/helpers/tag_event.php | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'modules/g2_import/helpers/g2_import.php') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 134edcff..436cef52 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -616,7 +616,7 @@ class g2_import_Core { // Multiword tags have the space changed to dots.s foreach ($tag_names as $tag_name) { $tags .= (strlen($tags) ? ", " : "") . - tag::add($g3_item, preg_replace('/\s+/', '.', $tag_name)); + tag::add($g3_item, $tag_name); } // Tag operations are idempotent so we don't need to map them. Which is good because we don't diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index a600ea1a..69178925 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -53,10 +53,10 @@ class Tags_Controller extends REST_Controller { $form = tag::get_add_form($item); if ($form->validate()) { - foreach (split("[\,\;]", $form->add_tag->inputs["name"]->value) as $tag_name) { + foreach (split(",", $form->add_tag->inputs["name"]->value) as $tag_name) { $tag_name = trim($tag_name); if ($tag_name) { - $tag = tag::add($item, str_replace(" ", ".", $tag_name)); + $tag = tag::add($item, $tag_name); } } @@ -81,7 +81,7 @@ class Tags_Controller extends REST_Controller { public function autocomplete() { $tags = array(); - $tag_parts = preg_split("#[,\s;]+# ", $this->input->get("q")); + $tag_parts = preg_split("#[,\s]+# ", $this->input->get("q")); $limit = $this->input->get("limit"); $tag_part = end($tag_parts); $tag_list = ORM::factory("tag") diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index bf60978d..7becf36f 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -34,8 +34,8 @@ class tag_event_Core { if (!empty($iptc["2#025"])) { foreach($iptc["2#025"] as $tag) { $tag = str_replace("\0", "", $tag); - foreach (preg_split("/[,;]/", $tag) as $word) { - $word = preg_replace('/\s+/', '.', trim($word)); + foreach (preg_split("/,/", $tag) as $word) { + $word = trim($word); if (function_exists("mb_detect_encoding") && mb_detect_encoding($word) != "UTF-8") { $word = utf8_encode($word); } @@ -71,16 +71,16 @@ class tag_event_Core { '$url', {max: 30, formatResult: formatTagAutoCompleteResult} ); });"; - $tag_value = implode("; ", tag::item_tags($item)); - $view->form->edit_item->input("tags")->label(t("Tags (comma or semicolon separated)")) + $tag_value = implode(", ", tag::item_tags($item)); + $view->form->edit_item->input("tags")->label(t("Tags (comma separated)")) ->value($tag_value); } static function item_edit_form_completed($item, $form) { tag::clear_all($item); - foreach (preg_split("/[,;]/", $form->edit_item->tags->value) as $tag_name) { + foreach (preg_split("/,/", $form->edit_item->tags->value) as $tag_name) { if ($tag_name) { - tag::add($item, str_replace(" ", ".", $tag_name)); + tag::add($item, trim($tag_name)); } } tag::compact(); -- cgit v1.2.3