summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/g2_import/helpers/g2_import.php40
-rw-r--r--modules/g2_import/helpers/g2_import_task.php16
2 files changed, 52 insertions, 4 deletions
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php
index 13a9666c..bf7a1a8c 100644
--- a/modules/g2_import/helpers/g2_import.php
+++ b/modules/g2_import/helpers/g2_import.php
@@ -97,7 +97,7 @@ class g2_import_Core {
}
static function import_group($i) {
- $map = g2(GalleryCoreApi::fetchGroupNames(1, $i - 1));
+ $map = g2(GalleryCoreApi::fetchGroupNames(1, $i));
$g2_group_id = current(array_keys($map));
$g2_group = g2(GalleryCoreApi::loadEntitiesById($g2_group_id));
if ($g2_group->getGroupType() != GROUP_NORMAL) {
@@ -113,7 +113,7 @@ class g2_import_Core {
}
static function import_user($i) {
- $map = g2(GalleryCoreApi::fetchUsersForGroup(GROUP_EVERYBODY, 1, $i - 1));
+ $map = g2(GalleryCoreApi::fetchUsersForGroup(GROUP_EVERYBODY, 1, $i));
$g2_user_id = current(array_keys($map));
if (g2(GalleryCoreApi::isAnonymousUser($g2_user_id))) {
return;
@@ -126,9 +126,45 @@ class g2_import_Core {
$user->email = $g2_user->getEmail();
$user->language = $g2_user->getLanguage();
$user->save();
+
+ // @todo put the user into the appropriate groups
} catch (Exception $e) {
// @todo For now we assume this is a "duplicate user" exception
// which we will ignore.
}
}
+
+ static function import_album(&$queue, &$album_map) {
+ // The queue is a set of nested associative arrays where the key is the album id and the
+ // value is an array of similar arrays. We'll do a breadth first tree traversal using the
+ // queue to keep our state. Doing it breadth first means that the parent will be created by
+ // the time we get to the child.
+
+ // Grab the current album off the queue and enqueue its children at the end of the line
+ list($g2_id, $children) = each($queue);
+ unset($queue[$g2_id]);
+ foreach ($children as $key => $value) {
+ $queue[$key] = $value;
+ }
+
+ // Load the G2 album item, and figure out its parent in G3.
+ $g2_album = g2(GalleryCoreApi::loadEntitiesById($g2_id));
+ if ($g2_album->getParentId() == null) {
+ return;
+ }
+
+ $g3_parent_album = ORM::factory("item", $album_map[$g2_album->getParentId()]);
+ $g3_album = album::create(
+ $g3_parent_album,
+ $g2_album->getPathComponent(),
+ $g2_album->getTitle(),
+ $g2_album->getDescription());
+ $album_map[$g2_album->getId()] = $g3_album->id;
+
+ // @todo import owners
+ // @todo figure out how to import summary vs. description
+ // @todo import view counts
+ // @todo import origination timestamp
+ // @todo import keywords as tags
+ }
}
diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php
index 1ddc95d6..964150be 100644
--- a/modules/g2_import/helpers/g2_import_task.php
+++ b/modules/g2_import/helpers/g2_import_task.php
@@ -48,11 +48,10 @@ class g2_import_task_Core {
$modes = array("groups", "users", "albums", "photos", "comments", "done");
while (!$task->done && microtime(true) - $start < 1) {
- if ($i >= $stats[$modes[$mode]]) {
+ if ($i >= ($stats[$modes[$mode]] - 1)) {
$i = 0;
$mode++;
}
- $i++;
switch($modes[$mode]) {
case "groups":
@@ -68,6 +67,18 @@ class g2_import_task_Core {
break;
case "albums":
+ if (!$i) {
+ $task->set("queue", $queue = g2(GalleryCoreApi::fetchAlbumTree()));
+ $task->set(
+ "album_map", $album_map = array(g2(GalleryCoreApi::getDefaultAlbumId()) => 1));
+ } else {
+ $queue = $task->get("queue");
+ $album_map = $task->get("album_map");
+ }
+
+ g2_import::import_album($queue, $album_map);
+ $task->set("queue", $queue);
+ $task->set("album_map", $album_map);
$task->status = t(
"Importing albums %count / %total", array("count" => $i, "total" => $stats["albums"]));
break;
@@ -89,6 +100,7 @@ class g2_import_task_Core {
break;
}
+ $i++;
if (!$task->done) {
$completed++;
}