From f2477703faa7cd05ff1aa16da3ecef7b666bef40 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Fri, 7 Jan 2011 17:33:37 +0100 Subject: Fix against ticket #1581 - based on https://github.com/Joe7/gallery3/commit/0d36b97aca3b5ed53ea3ea398ce28b0f6198e577 --- modules/g2_import/helpers/g2_import.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 8de5ce44..b2e3836a 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -499,6 +499,9 @@ class g2_import_Core { static function set_album_highlight(&$queue) { // Dequeue the current album and enqueue its children list($g2_album_id, $children) = each($queue); + if (empty($children)) { + return; + } unset($queue[$g2_album_id]); foreach ($children as $key => $value) { $queue[$key] = $value; -- cgit v1.2.3 From c338d3138e2c93bfb219a8d32ba9110138fcf9c2 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Thu, 6 Jan 2011 02:31:50 +0100 Subject: Importing Gallery2 users in batches Fixes Ticket #1554 --- modules/g2_import/helpers/g2_import.php | 22 +++++++++++++++++++++- modules/g2_import/helpers/g2_import_task.php | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index b2e3836a..5e2a61e8 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -1155,7 +1155,7 @@ class g2_import_Core { "SELECT [GalleryComment::id] " . "FROM [GalleryComment] " . "WHERE [GalleryComment::publishStatus] = 0 " . // 0 == COMMENT_PUBLISH_STATUS_PUBLISHED - "AND [GalleryComment::id] > ?", + "AND [GalleryComment::id] > ?", array($min_id), array("limit" => array("count" => 100)))); while ($result = $results->nextResult()) { @@ -1183,6 +1183,26 @@ class g2_import_Core { return $ids; } + /** + * Get a set of user ids from Gallery 2 greater than $min_id. We use this to get the + * next chunk of users to import. + */ + static function get_user_ids($min_id) { + global $gallery; + + $ids = array(); + $results = g2($gallery->search( + "SELECT [GalleryUser::id] " . + "FROM [GalleryUser] " . + "WHERE [GalleryUser::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. */ diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index f2a13291..dbfe5f77 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -109,8 +109,8 @@ class g2_import_task_Core { case "users": if (empty($queue)) { - $task->set( - "queue", $queue = array_keys(g2(GalleryCoreApi::fetchUsersForGroup(GROUP_EVERYBODY)))); + $task->set("queue", $queue = g2_import::get_user_ids($task->get("last_id", 0))); + $task->set("last_id", end($queue)); } $log_message = g2_import::import_user($queue); if ($log_message) { -- cgit v1.2.3 From 5bfb7fb96a5dc2e0bc511c998a7c055b83b2915a Mon Sep 17 00:00:00 2001 From: Joe7 Date: Thu, 6 Jan 2011 04:49:50 +0100 Subject: Added batch importer for groups Added missing ordering for comments and tags retrieving queries (One might gets the same output without ordering especially if column is the primary key, but the only way to go for sure it by setting it) --- modules/g2_import/helpers/g2_import.php | 30 +++++++++++++++++++++++++--- modules/g2_import/helpers/g2_import_task.php | 4 ++-- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 5e2a61e8..c3d774ea 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -1155,7 +1155,8 @@ class g2_import_Core { "SELECT [GalleryComment::id] " . "FROM [GalleryComment] " . "WHERE [GalleryComment::publishStatus] = 0 " . // 0 == COMMENT_PUBLISH_STATUS_PUBLISHED - "AND [GalleryComment::id] > ?", + "AND [GalleryComment::id] > ?" . + "ORDER BY [GalleryComment::id] ASC", array($min_id), array("limit" => array("count" => 100)))); while ($result = $results->nextResult()) { @@ -1174,7 +1175,8 @@ class g2_import_Core { $ids = array(); $results = g2($gallery->search( "SELECT DISTINCT([TagItemMap::itemId]) FROM [TagItemMap] " . - "WHERE [TagItemMap::itemId] > ?", + "WHERE [TagItemMap::itemId] > ?" . + "ORDER BY [TagItemMap::itemId] ASC", array($min_id), array("limit" => array("count" => 100)))); while ($result = $results->nextResult()) { @@ -1194,7 +1196,29 @@ class g2_import_Core { $results = g2($gallery->search( "SELECT [GalleryUser::id] " . "FROM [GalleryUser] " . - "WHERE [GalleryUser::id] > ?", + "WHERE [GalleryUser::id] > ?" . + "ORDER BY [GalleryUser::id] ASC", + array($min_id), + array("limit" => array("count" => 100)))); + while ($result = $results->nextResult()) { + $ids[] = $result[0]; + } + return $ids; + } + + /** + * Get a set of group ids from Gallery 2 greater than $min_id. We use this to get the + * next chunk of groups to import. + */ + static function get_group_ids($min_id) { + global $gallery; + + $ids = array(); + $results = g2($gallery->search( + "SELECT [GalleryGroup::id] " . + "FROM [GalleryGroup] " . + "WHERE [GalleryGroup::id] > ?" . + "ORDER BY [GalleryGroup::id] ASC", array($min_id), array("limit" => array("count" => 100)))); while ($result = $results->nextResult()) { diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index dbfe5f77..a90b1fc3 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -96,7 +96,8 @@ class g2_import_task_Core { switch($modes[$mode]) { case "groups": if (empty($queue)) { - $task->set("queue", $queue = array_keys(g2(GalleryCoreApi::fetchGroupNames()))); + $task->set("queue", $queue = g2_import::get_group_ids($task->get("last_id", 0))); + $task->set("last_id", end($queue)); } $log_message = g2_import::import_group($queue); if ($log_message) { @@ -141,7 +142,6 @@ class g2_import_task_Core { $task->set("queue", $queue = g2_import::get_item_ids($task->get("last_id", 0))); $task->set("last_id", end($queue)); } - $log_message = g2_import::import_item($queue); if ($log_message) { $task->log($log_message); -- cgit v1.2.3 From e86e8b8bd1d828d81080c63f9a063254145115e4 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Fri, 7 Jan 2011 17:53:37 +0100 Subject: Added missing spaces (manual merging from 0d36b97aca3b5ed53ea3ea398ce28b0f6198e577) --- modules/g2_import/helpers/g2_import.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index c3d774ea..162aa67b 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -1155,7 +1155,7 @@ class g2_import_Core { "SELECT [GalleryComment::id] " . "FROM [GalleryComment] " . "WHERE [GalleryComment::publishStatus] = 0 " . // 0 == COMMENT_PUBLISH_STATUS_PUBLISHED - "AND [GalleryComment::id] > ?" . + "AND [GalleryComment::id] > ? " . "ORDER BY [GalleryComment::id] ASC", array($min_id), array("limit" => array("count" => 100)))); @@ -1175,7 +1175,7 @@ class g2_import_Core { $ids = array(); $results = g2($gallery->search( "SELECT DISTINCT([TagItemMap::itemId]) FROM [TagItemMap] " . - "WHERE [TagItemMap::itemId] > ?" . + "WHERE [TagItemMap::itemId] > ? " . "ORDER BY [TagItemMap::itemId] ASC", array($min_id), array("limit" => array("count" => 100)))); @@ -1196,7 +1196,7 @@ class g2_import_Core { $results = g2($gallery->search( "SELECT [GalleryUser::id] " . "FROM [GalleryUser] " . - "WHERE [GalleryUser::id] > ?" . + "WHERE [GalleryUser::id] > ? " . "ORDER BY [GalleryUser::id] ASC", array($min_id), array("limit" => array("count" => 100)))); @@ -1217,7 +1217,7 @@ class g2_import_Core { $results = g2($gallery->search( "SELECT [GalleryGroup::id] " . "FROM [GalleryGroup] " . - "WHERE [GalleryGroup::id] > ?" . + "WHERE [GalleryGroup::id] > ? " . "ORDER BY [GalleryGroup::id] ASC", array($min_id), array("limit" => array("count" => 100)))); -- cgit v1.2.3