summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-05-12 04:04:26 +0000
committerBharat Mediratta <bharat@menalto.com>2009-05-12 04:04:26 +0000
commit8ae6a7a1448c411a9c1cd07dc3a45a6ec8924a32 (patch)
treeb5952699c8c69e2c0d4d3efc30d1af224b782aa8
parent61ad68f1e6e77196ac28bca0c57441f0c38ef90b (diff)
Import tags.
-rw-r--r--modules/g2_import/helpers/g2_import.php47
-rw-r--r--modules/g2_import/helpers/g2_import_task.php14
-rw-r--r--modules/g2_import/views/admin_g2_import.html.php4
3 files changed, 65 insertions, 0 deletions
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php
index c6ea2cc8..bea0328e 100644
--- a/modules/g2_import/helpers/g2_import.php
+++ b/modules/g2_import/helpers/g2_import.php
@@ -97,6 +97,7 @@ class g2_import_Core {
* comments available for import from the Gallery 2 instance.
*/
static function stats() {
+ global $gallery;
GalleryCoreApi::requireOnce("modules/comment/classes/GalleryCommentHelper.class");
$root_album_id = g2(GalleryCoreApi::getDefaultAlbumId());
@@ -111,6 +112,16 @@ class g2_import_Core {
} else {
$stats["comments"] = 0;
}
+
+ if (g2_import::g2_module_active("tags") && module::is_installed("tag")) {
+ $result =
+ g2($gallery->search("SELECT COUNT(DISTINCT([TagItemMap::itemId])) FROM [TagItemMap]"))
+ ->nextResult();
+ $stats["tags"] = $result[0];
+ } else {
+ $stats["tags"] = 0;
+ }
+
return $stats;
}
@@ -328,6 +339,23 @@ class g2_import_Core {
}
/**
+ * 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));
+ $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id)));
+
+ 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.
+ }
+
+ /**
* 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.
*/
@@ -502,6 +530,25 @@ class g2_import_Core {
}
/**
+ * Get a set of comment ids from Gallery 2 greater than $min_id. We use this to get the
+ * next chunk of comments to import.
+ */
+ static function get_tag_item_ids($min_id) {
+ global $gallery;
+
+ $ids = array();
+ $results = g2($gallery->search(
+ "SELECT DISTINCT([TagItemMap::itemId]) FROM [TagItemMap] " .
+ "WHERE [TagItemMap::itemId] > ?",
+ array($min_id),
+ array("limit" => array("count" => 100))));
+ while ($result = $results->nextResult()) {
+ $ids[] = $result[0];
+ }
+ return $ids;
+ }
+
+ /**
* Look in our map to find the corresponding Gallery 3 id for the given Gallery 2 id.
*/
static function map($g2_id) {
diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php
index 32d39da4..7185d694 100644
--- a/modules/g2_import/helpers/g2_import_task.php
+++ b/modules/g2_import/helpers/g2_import_task.php
@@ -62,6 +62,9 @@ class g2_import_task_Core {
if (g2_import::g2_module_active("comment") && module::is_installed("comment")) {
$modes[] = "comments";
}
+ if (g2_import::g2_module_active("tags") && module::is_installed("tag")) {
+ $modes[] = "tags";
+ }
$modes[] = "done";
while (!$task->done && microtime(true) - $start < 1.5) {
if ($i >= ($stats[$modes[$mode]] - 1)) {
@@ -122,6 +125,17 @@ class g2_import_task_Core {
break;
+ case "tags":
+ if (empty($queue)) {
+ $task->set("queue", $queue = g2_import::get_tag_item_ids($task->get("last_id", 0)));
+ $task->set("last_id", end($queue));
+ }
+ g2_import::import_tags_for_item($queue);
+ $task->status = t("Importing tags %count / %total",
+ array("count" => $i, "total" => $stats["tags"]));
+
+ break;
+
case "done":
$task->status = t("Import complete");
$task->done = true;
diff --git a/modules/g2_import/views/admin_g2_import.html.php b/modules/g2_import/views/admin_g2_import.html.php
index 8b6d069e..42c422c7 100644
--- a/modules/g2_import/views/admin_g2_import.html.php
+++ b/modules/g2_import/views/admin_g2_import.html.php
@@ -40,6 +40,10 @@
<li>
<?= t2("1 comment", "%count comments", $g2_stats["comments"]) ?>
</li>
+ <li>
+ <?= t2("1 tagged photo/movie/album",
+ "%count tagged photos/movies/albums", $g2_stats["tags"]) ?>
+ </li>
</ul>
</div>