From fdb17d75cebed56be0011eea2abba237320ceddf Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 12 May 2009 05:48:15 +0000 Subject: Import keywords as tags. Refactor the general flow of g2_import_task::import() to simplify it and make it more sensible. It had gotten a little overgrown. It's still a little overgrown, but I don't see an easy way to simplify it from here. --- modules/g2_import/helpers/g2_import.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 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 bea0328e..482f4089 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -236,7 +236,6 @@ class g2_import_Core { $album->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_album_id)); $album->created = $g2_album->getCreationTimestamp(); - // @todo support "keywords", "originationTimestamp", and "random" sort orders. $order_map = array( "originationTimestamp" => "captured", "creationTimestamp" => "created", @@ -256,9 +255,9 @@ class g2_import_Core { } $album->save(); + self::import_keywords_as_tags($g2_album->getKeywords(), $album); self::set_map($g2_album_id, $album->id); - // @todo import keywords as tags // @todo import album highlights } @@ -304,6 +303,10 @@ class g2_import_Core { break; } + if (!empty($item)) { + self::import_keywords_as_tags($g2_item->getKeywords(), $item); + } + if (isset($item)) { self::set_map($g2_item_id, $item->id); } @@ -355,6 +358,19 @@ class g2_import_Core { // have an id for each individual tag mapping anyway so it'd be hard to set up the mapping. } + static function import_keywords_as_tags($keywords, $item) { + if (!module::is_installed("tag")) { + return; + } + + foreach (preg_split("/[,;]/", $keywords) as $keyword) { + $keyword = trim($keyword); + if ($keyword) { + tag::add($item, $keyword); + } + } + } + /** * If the thumbnails and resizes created for the Gallery2 photo match the dimensions of the * ones we expect to create for Gallery3, then copy the files over instead of recreating them. -- cgit v1.2.3