diff options
-rw-r--r-- | modules/g2_import/helpers/g2_import.php | 33 | ||||
-rw-r--r-- | modules/g2_import/helpers/g2_import_task.php | 14 |
2 files changed, 43 insertions, 4 deletions
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index e4fc9642..ee3dd61e 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -106,7 +106,7 @@ class g2_import_Core { $stats["photos"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryPhotoItem")); $stats["movies"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryMovieItem")); - if (g2_import::g2_module_active("comment")) { + if (g2_import::g2_module_active("comment") && module::is_installed("comment")) { list (, $stats["comments"]) = g2(GalleryCommentHelper::fetchAllComments($root_album_id, 1)); } else { $stats["comments"] = 0; @@ -301,6 +301,14 @@ class g2_import_Core { } /** + * Import a single comment. + */ + static function import_comment(&$queue) { + $g2_comment_id = array_shift($queue); + $g2_comment = g2(GalleryCoreApi::loadEntitiesById($g2_comment_id)); + } + + /** * 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. */ @@ -432,7 +440,7 @@ class g2_import_Core { /** * Get a set of photo and movie ids from Gallery 2 greater than $min_id. We use this to get the - * next chunk of photo/movie ids to import. + * next chunk of photos/movies to import. */ static function get_item_ids($min_id) { global $gallery; @@ -454,6 +462,27 @@ 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_comment_ids($min_id) { + global $gallery; + + $ids = array(); + $results = g2($gallery->search( + "SELECT [GalleryComment::id] " . + "FROM [GalleryComment] " . + "WHERE [GalleryComment::publishStatus] = 0 " . // 0 == COMMENT_PUBLISH_STATUS_PUBLISHED + "AND [GalleryComment::id] > ?", + 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 8fd8f72b..32d39da4 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -58,11 +58,16 @@ class g2_import_task_Core { } } - $modes = array("groups", "users", "albums", "photos", "comments", "done"); + $modes = array("groups", "users", "albums", "photos"); + if (g2_import::g2_module_active("comment") && module::is_installed("comment")) { + $modes[] = "comments"; + } + $modes[] = "done"; while (!$task->done && microtime(true) - $start < 1.5) { if ($i >= ($stats[$modes[$mode]] - 1)) { $i = 0; $mode++; + $task->set("last_id", 0); $queue = array(); } @@ -91,7 +96,6 @@ class g2_import_task_Core { $task->set("queue", $queue = g2(GalleryCoreApi::fetchAlbumTree())); } g2_import::import_album($queue); - $task->set("queue", $queue); $task->status = t( "Importing albums %count / %total", array("count" => $i, "total" => $stats["albums"])); break; @@ -108,8 +112,14 @@ class g2_import_task_Core { break; case "comments": + if (empty($queue)) { + $task->set("queue", $queue = g2_import::get_comment_ids($task->get("last_id", 0))); + $task->set("last_id", end($queue)); + } + g2_import::import_comment($queue); $task->status = t("Importing comments %count / %total", array("count" => $i, "total" => $stats["comments"])); + break; case "done": |