/** * Import all the tags for a single item */ static function import_tags_for_item(&$queue) { if (!module::is_active("tag")) { return t("Gallery 3 tag module is inactive, no tags will be imported"); } GalleryCoreApi::requireOnce("modules/tags/classes/TagsHelper.class"); $g2_item_id = array_shift($queue); $g3_item = ORM::factory("item", self::map($g2_item_id)); if (!$g3_item->loaded()) { return; } try { $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); } catch (Exception $e) { return t("Failed to import Gallery 2 tags for item with id: %id\n%exception", array("id" => $g2_item_id, "exception" => (string) $e)); } foreach ($tag_names as $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 // have an id for each individual tag mapping anyway so it'd be hard to set up the mapping. }
/** * Import all the tags for a single item */ static function import_tags_for_item(&$queue) { if (!module::is_active("tag")) { return t("Gallery 3 tag module is inactive, no tags will be imported"); } GalleryCoreApi::requireOnce("modules/tags/classes/TagsHelper.class"); $g2_item_id = array_shift($queue); $g3_item = ORM::factory("item", self::map($g2_item_id)); try { $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); } catch (Exception $e) { return t("Failed to import Gallery 2 tags for item with id: %id\n%exception", array("id" => $g2_item_id, "exception" => $e->__toString())); } $tags = ""; // 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 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. }
/** * Import all the tags for a single item */ static function import_tags_for_item(&$queue) { GalleryCoreApi::requireOnce("modules/tags/classes/TagsHelper.class"); $g2_item_id = array_shift($queue); $g3_item = ORM::factory("item", self::map($g2_item_id)); try { $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); } catch (Exception $e) { g2_import::log("Failed to import tags for Gallery 2 item with id: %id", array("id" => $g2_item_id)); return; } foreach ($tag_names as $tag_name) { $tag = 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 // have an id for each individual tag mapping anyway so it'd be hard to set up the mapping. }