summaryrefslogtreecommitdiff
path: root/modules/g2_import
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-03-28 21:04:44 -0700
committerBharat Mediratta <bharat@menalto.com>2010-03-28 21:04:44 -0700
commitea43c5f06f5c7242f1d5811fe427e55c87497ecc (patch)
tree7ee253a40c57c8ea8066305e36b633fa2d7500e4 /modules/g2_import
parent2eea7b874aa06f08ed58a85197473233b54693aa (diff)
parente8eb23db42bb929548af358452f1b65e16b61913 (diff)
Merge branch 'master' of github.com:gallery/gallery3
Diffstat (limited to 'modules/g2_import')
-rw-r--r--modules/g2_import/controllers/admin_g2_import.php2
-rw-r--r--modules/g2_import/controllers/g2.php2
-rw-r--r--modules/g2_import/helpers/g2_import.php209
-rw-r--r--modules/g2_import/helpers/g2_import_event.php2
-rw-r--r--modules/g2_import/helpers/g2_import_installer.php2
-rw-r--r--modules/g2_import/helpers/g2_import_task.php2
-rw-r--r--modules/g2_import/helpers/g2_import_theme.php2
-rw-r--r--modules/g2_import/models/g2_map.php2
8 files changed, 161 insertions, 62 deletions
diff --git a/modules/g2_import/controllers/admin_g2_import.php b/modules/g2_import/controllers/admin_g2_import.php
index f216091a..bc00378d 100644
--- a/modules/g2_import/controllers/admin_g2_import.php
+++ b/modules/g2_import/controllers/admin_g2_import.php
@@ -1,7 +1,7 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
+ * Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php
index 1d97653a..2c6ad1b4 100644
--- a/modules/g2_import/controllers/g2.php
+++ b/modules/g2_import/controllers/g2.php
@@ -1,7 +1,7 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
+ * Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php
index 95ec282d..456c13c4 100644
--- a/modules/g2_import/helpers/g2_import.php
+++ b/modules/g2_import/helpers/g2_import.php
@@ -1,7 +1,7 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
+ * Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -231,6 +231,7 @@ class g2_import_Core {
* Import a single group.
*/
static function import_group(&$queue) {
+ $messages = array();
$g2_group_id = array_shift($queue);
if (self::map($g2_group_id)) {
return;
@@ -239,33 +240,46 @@ class g2_import_Core {
try {
$g2_group = g2(GalleryCoreApi::loadEntitiesById($g2_group_id));
} catch (Exception $e) {
- return t("Failed to import Gallery 2 group with id: %id\n%exception",
- array("id" => $g2_group_id, "exception" => (string)$e));
+ throw new G2_Import_Exception(
+ t("Failed to import Gallery 2 group with id: %id,",
+ array("id" => $g2_group_id)),
+ $e);
}
switch ($g2_group->getGroupType()) {
case GROUP_NORMAL:
try {
$group = identity::create_group($g2_group->getGroupName());
+ $messages[] = t("Group '%name' was imported",
+ array("name" => $g2_group->getGroupname()));
} catch (Exception $e) {
- // @todo For now we assume this is a "duplicate group" exception
- $group = identity::lookup_user_by_name($g2_group->getGroupname());
+ // Did it fail because of a duplicate group name?
+ $group = identity::lookup_group_by_name($g2_group->getGroupname());
+ if ($group) {
+ $messages[] = t("Group '%name' was mapped to the existing group group of the same name.",
+ array("name" => $g2_group->getGroupname()));
+ } else {
+ throw new G2_Import_Exception(
+ t("Failed to import group '%name'",
+ array("name" => $g2_group->getGroupname())),
+ $e);
+ }
}
- $message = t("Group '%name' was imported", array("name" => $g2_group->getGroupname()));
+
break;
case GROUP_ALL_USERS:
$group = identity::registered_users();
- $message = t("Group 'Registered' was converted to '%name'", array("name" => $group->name));
+ $messages[] = t("Group 'Registered' was converted to '%name'", array("name" => $group->name));
break;
case GROUP_SITE_ADMINS:
- $message = t("Group 'Admin' does not exist in Gallery 3, skipping");
+ $messages[] = t("Group 'Admin' does not exist in Gallery 3, skipping");
break; // This is not a group in G3
case GROUP_EVERYBODY:
$group = identity::everybody();
- $message = t("Group 'Everybody' was converted to '%name'", array("name" => $group->name));
+ $messages[] = t("Group 'Everybody' was converted to '%name'", array("name" => $group->name));
break;
}
@@ -273,16 +287,18 @@ class g2_import_Core {
self::set_map($g2_group->getId(), $group->id, "group");
}
- return $message;
+ return $messages;
}
/**
* Import a single user.
*/
static function import_user(&$queue) {
+ $messages = array();
$g2_user_id = array_shift($queue);
if (self::map($g2_user_id)) {
- return t("User with id: %id already imported, skipping", array("id" => $g2_user_id));
+ return t("User with id: %id already imported, skipping",
+ array("id" => $g2_user_id));
}
if (g2(GalleryCoreApi::isAnonymousUser($g2_user_id))) {
@@ -295,52 +311,66 @@ class g2_import_Core {
try {
$g2_user = g2(GalleryCoreApi::loadEntitiesById($g2_user_id));
} catch (Exception $e) {
- return t("Failed to import Gallery 2 user with id: %id\n%exception",
- array("id" => $g2_user_id, "exception" => (string)$e));
+ throw new G2_Import_Exception(
+ t("Failed to import Gallery 2 user with id: %id\n%exception",
+ array("id" => $g2_user_id, "exception" => (string)$e)),
+ $e);
}
$g2_groups = g2(GalleryCoreApi::fetchGroupsForUser($g2_user->getId()));
$user = identity::lookup_user_by_name($g2_user->getUsername());
if ($user) {
- $message = t("Loaded existing user: '%name'.", array("name" => $user->name));
+ $messages[] = t("Loaded existing user: '%name'.", array("name" => $user->name));
} else {
$email = $g2_user->getEmail();
if (empty($email) || !valid::email($email)) {
$email = "unknown@unknown.com";
}
- $user = identity::create_user($g2_user->getUsername(), $g2_user->getfullname(),
- // Note: The API expects a password in cleartext.
- // Just use the hashed password as an unpredictable
- // value here. The user will have to reset the password.
- $g2_user->getHashedPassword(), $email);
+ try {
+ $user = identity::create_user($g2_user->getUserName(), $g2_user->getFullName(),
+ // Note: The API expects a password in cleartext.
+ // Just use the hashed password as an unpredictable
+ // value here. The user will have to reset the password.
+ $g2_user->getHashedPassword(), $email);
+ } catch (Exception $e) {
+ throw new G2_Import_Exception(
+ t("Failed to create user: '%name' (id: %id)",
+ array("name" => $g2_user->getUserName(), "id" => $g2_user_id)),
+ $e, $messages);
+ }
if (class_exists("User_Model") && $user instanceof User_Model) {
// This will work if G2's password is a PasswordHash password as well.
$user->hashed_password = $g2_user->getHashedPassword();
}
- $message = t("Created user: '%name'.", array("name" => $user->name));
+ $messages[] = t("Created user: '%name'.", array("name" => $user->name));
if ($email == "unknown@unknown.com") {
- $message .= t("\n\tFixed invalid email (was '%invalid_email')",
- array("invalid_email" => $g2_user->getEmail()));
+ $messages[] = t("Fixed invalid email (was '%invalid_email')",
+ array("invalid_email" => $g2_user->getEmail()));
}
}
- $user->hashed_password = $g2_user->getHashedPassword();
$user->locale = $g2_user->getLanguage();
foreach ($g2_groups as $g2_group_id => $g2_group_name) {
if ($g2_group_id == $g2_admin_group_id) {
$user->admin = true;
- $message .= t("\n\tAdded 'admin' flag to user");
+ $messages[] = t("Added 'admin' flag to user");
} else {
$group = identity::lookup_group(self::map($g2_group_id));
$user->add($group);
- $message .= t("\n\tAdded user to group '%group'.", array("group" => $group->name));
+ $messages[] = t("Added user to group '%group'.", array("group" => $group->name));
}
}
- $user->save();
- self::set_map($g2_user->getId(), $user->id, "user");
+ try {
+ $user->save();
+ self::set_map($g2_user->getId(), $user->id, "user");
+ } catch (Exception $e) {
+ throw new G2_Import_Exception(
+ t("Failed to create user: '%name'", array("name" => $user->name)),
+ $e, $messages);
+ }
- return $message;
+ return $messages;
}
/**
@@ -367,7 +397,7 @@ class g2_import_Core {
// Load the G2 album item, and figure out its parent in G3.
$g2_album = g2(GalleryCoreApi::loadEntitiesById($g2_album_id));
} catch (Exception $e) {
- return t("Failed to import Gallery 2 album with id: %id\n%exception",
+ return t("Failed to load Gallery 2 album with id: %id\n%exception",
array("id" => $g2_album_id, "exception" => (string)$e));
}
@@ -384,7 +414,12 @@ class g2_import_Core {
$album->title or $album->title = $album->name;
$album->description = self::_decode_html_special_chars(self::extract_description($g2_album));
$album->owner_id = self::map($g2_album->getOwnerId());
- $album->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_album_id));
+ try {
+ $album->view_count = (int) g2(GalleryCoreApi::fetchItemViewCount($g2_album_id));
+ } catch (Exception $e) {
+ // @todo log
+ $album->view_count = 0;
+ }
$album->created = $g2_album->getCreationTimestamp();
$order_map = array(
@@ -409,7 +444,15 @@ class g2_import_Core {
$album->sort_column = $order_map[$g2_order];
$album->sort_order = $direction_map[$g2_order_direction];
}
- $album->save();
+
+ try {
+ $album->save();
+ } catch (Exception $e) {
+ throw new G2_Import_Exception(
+ t("Failed to import Gallery 2 album with id %id and name %name.",
+ array("id" => $g2_album_id, "name" => $album->name)),
+ $e);
+ }
self::import_keywords_as_tags($g2_album->getKeywords(), $album);
}
@@ -433,6 +476,7 @@ class g2_import_Core {
$queue[$key] = $value;
}
+ $messages = array();
$g3_album_id = self::map($g2_album_id);
if (!$g3_album_id) {
return t("Album with id: %id not imported", array("id" => $g3_album_id));
@@ -448,12 +492,23 @@ class g2_import_Core {
$item_id = self::map($g2_source->getId());
if ($item_id) {
$item = ORM::factory("item", $item_id);
- $g2_album = ORM::factory("item", $g3_album_id);
- $g2_album->album_cover_item_id = $item->id;
- $g2_album->thumb_dirty = 1;
- $g2_album->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_album_id));
- $g2_album->save();
- graphics::generate($g2_album);
+ $g3_album = ORM::factory("item", $g3_album_id);
+ $g3_album->album_cover_item_id = $item->id;
+ $g3_album->thumb_dirty = 1;
+ try {
+ $g3_album->view_count = (int) g2(GalleryCoreApi::fetchItemViewCount($g2_album_id));
+ } catch (Exception $e) {
+ $g3_album->view_count = 0;
+ }
+ try {
+ $g3_album->save();
+ graphics::generate($g2_album);
+ } catch (Exception $e) {
+ return (string) new G2_Import_Exception(
+ t("Failed to generate an album highlight for album '%name'.",
+ array("name" => $g3_album->name)),
+ $e);
+ }
}
}
}
@@ -495,13 +550,13 @@ class g2_import_Core {
$corrupt = 1;
}
- $message = array();
+ $messages = array();
switch ($g2_type) {
case "GalleryPhotoItem":
if (!in_array($g2_item->getMimeType(), array("image/jpeg", "image/gif", "image/png"))) {
Kohana_Log::add("alert", "$g2_path is an unsupported image type; using a placeholder gif");
- $message[] = t("'%path' is an unsupported image type, using a placeholder",
- array("path" => $g2_path));
+ $messages[] = t("'%path' is an unsupported image type, using a placeholder",
+ array("path" => $g2_path));
$g2_path = MODPATH . "g2_import/data/broken-image.gif";
$corrupt = 1;
}
@@ -517,9 +572,11 @@ class g2_import_Core {
$item->owner_id = self::map($g2_item->getOwnerId());
$item->save();
} catch (Exception $e) {
- Kohana_Log::add("alert", "Corrupt image $g2_path\n" . (string)$e);
- $message[] = t("Corrupt image '%path'", array("path" => $g2_path));
- $message[] = (string)$e;
+ $exception_info = (string) new G2_Import_Exception(
+ t("Corrupt image '%path'", array("path" => $g2_path)),
+ $e, $messages);
+ Kohana_Log::add("alert", "Corrupt image $g2_path\n" . $exception_info);
+ $messages[] = $exception_info;
$corrupt = 1;
$item = null;
}
@@ -538,16 +595,19 @@ class g2_import_Core {
$item->title or $item->title = $item->name;
$item->description = self::_decode_html_special_chars(self::extract_description($g2_item));
$item->owner_id = self::map($g2_item->getOwnerId());
+ $item->save();
} catch (Exception $e) {
- Kohana_Log::add("alert", "Corrupt movie $g2_path\n" . (string)$e);
- $message[] = t("Corrupt movie '%path'", array("path" => $g2_path));
- $message[] = (string)$e;
+ $exception_info = (string) new G2_Import_Exception(
+ t("Corrupt movie '%path'", array("path" => $g2_path)),
+ $e, $messages);
+ Kohana_Log::add("alert", "Corrupt movie $g2_path\n" . $exception_info);
+ $messages[] = $exception_info;
$corrupt = 1;
$item = null;
}
} else {
Kohana_Log::add("alert", "$g2_path is an unsupported movie type");
- $message[] = t("'%path' is an unsupported movie type", array("path" => $g2_path));
+ $messages[] = t("'%path' is an unsupported movie type", array("path" => $g2_path));
$corrupt = 1;
}
@@ -564,7 +624,11 @@ class g2_import_Core {
$g2_item_url = self::g2_url(array("view" => "core.ShowItem", "itemId" => $g2_item->getId()));
if (isset($item)) {
- $item->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_item_id));
+ try {
+ $item->view_count = (int) g2(GalleryCoreApi::fetchItemViewCount($g2_item_id));
+ } catch (Exception $e) {
+ $view_count = 1;
+ }
$item->save();
self::set_map($g2_item_id, $item->id, "item", $g2_item_url);
@@ -591,21 +655,23 @@ class g2_import_Core {
if ($corrupt) {
if (!empty($item)) {
- $message[] =
+ $title = $g2_item->getTitle();
+ $title or $title = $g2_item->getPathComponent();
+ $messages[] =
t("<a href=\"%g2_url\">%title</a> from Gallery 2 could not be processed; " .
"(imported as <a href=\"%g3_url\">%title</a>)",
array("g2_url" => $g2_item_url,
"g3_url" => $item->url(),
- "title" => $g2_item->getTitle()));
+ "title" => $title));
} else {
- $message[] =
+ $messages[] =
t("<a href=\"%g2_url\">%title</a> from Gallery 2 could not be processed",
array("g2_url" => $g2_item_url, "title" => $g2_item->getTitle()));
}
}
self::$current_g2_item = null;
- return $message;
+ return $messages;
}
/**
@@ -745,7 +811,7 @@ class g2_import_Core {
try {
$g2_comment = g2(GalleryCoreApi::loadEntitiesById($g2_comment_id));
} catch (Exception $e) {
- return t("Failed to import Gallery 2 comment with id: %id\%exception",
+ return t("Failed to load Gallery 2 comment with id: %id\%exception",
array("id" => $g2_comment_id, "exception" => (string)$e));
}
@@ -775,7 +841,14 @@ class g2_import_Core {
$comment->state = "published";
$comment->server_http_host = $g2_comment->getHost();
$comment->created = $g2_comment->getDate();
- $comment->save();
+ try {
+ $comment->save();
+ } catch (Exception $e) {
+ return (string) new G2_Import_Exception(
+ t("Failed to import comment with id: %id.",
+ array("id" => $g2_comment_id)),
+ $e);
+ }
}
/**
@@ -888,7 +961,14 @@ class g2_import_Core {
}
}
}
- $item->save();
+ try {
+ $item->save();
+ } catch (Exception $e) {
+ return (string) new G2_Import_Exception(
+ t("Failed to copy thumbnails and resizes for item '%name' (Gallery 2 id: %id)",
+ array("name" => $item->name, "id" => $g2_item_id)),
+ $e);
+ }
}
/**
@@ -1124,3 +1204,22 @@ function g2() {
}
}
+/**
+ * A wrapper for exceptions to report more details in case
+ * it's a ORM validation exception.
+ */
+class G2_Import_Exception extends Exception {
+ public function __construct($message, Exception $previous=null, $additional_messages=null) {
+ if ($additional_messages) {
+ $message .= "\n" . implode("\n", $additional_messages);
+ }
+ if ($previous && $previous instanceof ORM_Validation_Exception) {
+ $message .= "\nORM validation errors: " . print_r($previous->validation->errors(), true);
+ }
+ if ($previous) {
+ $message .= "\n" . (string) $previous;
+ }
+ // The $previous parameter is supported in PHP 5.3.0+.
+ parent::__construct($message);
+ }
+} \ No newline at end of file
diff --git a/modules/g2_import/helpers/g2_import_event.php b/modules/g2_import/helpers/g2_import_event.php
index 02a2126d..d3eb001a 100644
--- a/modules/g2_import/helpers/g2_import_event.php
+++ b/modules/g2_import/helpers/g2_import_event.php
@@ -1,7 +1,7 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
+ * Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/modules/g2_import/helpers/g2_import_installer.php b/modules/g2_import/helpers/g2_import_installer.php
index 1ec8afa9..8ada4fcb 100644
--- a/modules/g2_import/helpers/g2_import_installer.php
+++ b/modules/g2_import/helpers/g2_import_installer.php
@@ -1,7 +1,7 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
+ * Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php
index b1179e22..f2a13291 100644
--- a/modules/g2_import/helpers/g2_import_task.php
+++ b/modules/g2_import/helpers/g2_import_task.php
@@ -1,7 +1,7 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
+ * Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/modules/g2_import/helpers/g2_import_theme.php b/modules/g2_import/helpers/g2_import_theme.php
index b1aaac00..788253f9 100644
--- a/modules/g2_import/helpers/g2_import_theme.php
+++ b/modules/g2_import/helpers/g2_import_theme.php
@@ -1,7 +1,7 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
+ * Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/modules/g2_import/models/g2_map.php b/modules/g2_import/models/g2_map.php
index 12fc1565..a20f48d6 100644
--- a/modules/g2_import/models/g2_map.php
+++ b/modules/g2_import/models/g2_map.php
@@ -1,7 +1,7 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
+ * Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by