summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2010-03-02 07:10:22 -0800
committerTim Almdal <tnalmdal@shaw.ca>2010-03-02 07:10:22 -0800
commitd1b8589ea42deab5ec976f265a3d4b195dda09cd (patch)
tree84477e949d883425a330f6e64ad74aaff4378018
parente3e72ca4da0375d88b86ba69b6596b10be164e23 (diff)
parentaff40d2d787bf4a5853a2b097836e33226dc097d (diff)
Merge branch 'master' into talmdal_dev
-rw-r--r--lib/gallery.common.css66
-rw-r--r--modules/g2_import/helpers/g2_import.php196
-rw-r--r--modules/gallery/css/gallery.css68
-rw-r--r--modules/gallery/views/form_uploadify.html.php31
4 files changed, 224 insertions, 137 deletions
diff --git a/lib/gallery.common.css b/lib/gallery.common.css
index 98b4ee40..31988b67 100644
--- a/lib/gallery.common.css
+++ b/lib/gallery.common.css
@@ -273,7 +273,7 @@ form li.g-warning {
}
.g-short-form li.g-error {
- padding: .3em 0 .3em 0;
+ padding: .3em 0;
}
form.g-error input[type="text"],
@@ -294,7 +294,8 @@ li.g-error select {
.g-error,
.g-denied,
-tr.g-error td.g-error {
+tr.g-error td.g-error,
+#g-add-photos-status .g-error {
background: #f6cbca url('images/ico-error.png') no-repeat .4em 50%;
color: #f00;
}
@@ -304,7 +305,8 @@ tr.g-error td.g-error {
}
.g-success,
-.g-allowed {
+.g-allowed,
+#g-add-photos-status .g-success {
background: #d9efc2 url('images/ico-success.png') no-repeat .4em 50%;
}
@@ -603,60 +605,6 @@ div#g-action-status {
margin-left: 0;
}
-/* Simple uploader ~~~~~~~~~~~~~~~~~~~~~~~ */
-
-#g-add-photos-canvas {
- border: 1px solid #ccc;
- height: 200px;
- margin: .5em 0;
- overflow: auto;
- width: 469px;
-}
-
-#g-add-photos-status {
- border: 1px solid #ccc;
- height: 125px;
- margin: .5em 0;
- overflow: auto;
- width: 469px;
-}
-
-#g-add-photos button {
- float: right;
- margin-bottom: .5em;
- margin-left: .5em;
-}
-
-#g-add-photos-status li {
- text-align: left;
- padding-left: 2em;
-}
-
-#g-add-photos-status li.g-success {
- background: #d9efc2 url('images/ico-success.png') no-repeat .4em 50%;
- width: 429px;
-}
-
-#g-add-photos-status li.g-error {
- background: #f6cbca url('images/ico-error.png') no-repeat .4em 50%;
- width: 429px;
-/* color: #f00;*/
-}
-
-#g-add-photos-button {
- background: #DFEFFC;
- border: 1px solid #C5DBEC;
- color: #2E6E9E
-}
-
-#g-add-photos p {
- margin: 0
-}
-
-#g-add-photos .g-breadcrumbs li {
- padding-top: .5em;
-}
-
/** *******************************************************************
* 7) Right to left language styles
**********************************************************************/
@@ -685,7 +633,9 @@ div#g-action-status {
.rtl .g-error,
.rtl .g-info,
.rtl .g-success,
-.rtl .g-warning {
+.rtl .g-warning,
+.rtl #g-add-photos-status .g-success,
+.rtl #g-add-photos-status .g-error {
background-position: center right;
padding-right: 30px !important;
}
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php
index 9a91770a..6240403d 100644
--- a/modules/g2_import/helpers/g2_import.php
+++ b/modules/g2_import/helpers/g2_import.php
@@ -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));
}
@@ -409,7 +439,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 +471,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 +487,19 @@ 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;
+ $g3_album->view_count = (int) g2(GalleryCoreApi::fetchItemViewCount($g2_album_id));
+ 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 +541,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 +563,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;
}
@@ -537,16 +585,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;
}
@@ -563,7 +614,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));
+ $view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_item_id));
+ if (!is_numeric($view_count)) {
+ $messages[] = t("Bad view count value '%view_count'", array("view_count" => $view_count));
+ }
+ $item->view_count = (int) $view_count;
$item->save();
self::set_map($g2_item_id, $item->id, "item", $g2_item_url);
@@ -590,21 +645,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;
}
/**
@@ -744,7 +801,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));
}
@@ -774,7 +831,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);
+ }
}
/**
@@ -887,7 +951,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);
+ }
}
/**
@@ -1123,3 +1194,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/gallery/css/gallery.css b/modules/gallery/css/gallery.css
index f3e5ec6d..ed9986bf 100644
--- a/modules/gallery/css/gallery.css
+++ b/modules/gallery/css/gallery.css
@@ -11,6 +11,70 @@
* 1) End-user
**********************************************************************/
+/* Uploader ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+#g-add-photos-canvas,
+#g-add-photos-status {
+ width: 469px;
+}
+
+#g-add-photos-canvas {
+ border: 1px solid #ccc;
+ height: 200px;
+ margin: .5em 0;
+ padding: 1.8em 0 0 0;
+ overflow: auto;
+ position: relative;
+}
+
+#g-add-photos-canvas object,
+#g-add-photos-button {
+ left: 137px;
+ margin: 0 0 .5em 0;
+ padding: .4em 1em;
+ position: absolute;
+ top: 0;
+ width: 175px;
+}
+
+#g-add-photos-canvas object {
+ margin: 0;
+ z-index: 100;
+}
+
+#g-add-photos-canvas .uploadifyQueueItem {
+ margin: 0;
+}
+
+#g-add-photos-button {
+ z-index: 1;
+}
+
+#g-add-photos-status {
+ border: 1px solid #ccc;
+ height: 125px;
+ margin: .4em 0;
+ overflow: auto;
+}
+
+#g-add-photos-status .g-message-block {
+ border: none;
+}
+
+#g-add-photos-status #g-action-status li {
+ margin: 0 0 1px 0;
+ padding-top: .7em;
+ width: 433px;
+}
+
+#g-add-photos-form .g-breadcrumbs {
+ margin: 0;
+}
+
+#g-add-photos-form p {
+ margin-bottom: 0
+}
+
/* Permissions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
#g-edit-permissions-form {
@@ -121,6 +185,10 @@
* 3) Right to left language styles
**********************************************************************/
+.rtl #g-add-photos-status #g-action-status li {
+ width: 407px;
+}
+
.rtl #g-block-admin .g-left {
margin-left: 1em;
margin-right: 0;
diff --git a/modules/gallery/views/form_uploadify.html.php b/modules/gallery/views/form_uploadify.html.php
index 137cb353..d811f913 100644
--- a/modules/gallery/views/form_uploadify.html.php
+++ b/modules/gallery/views/form_uploadify.html.php
@@ -1,25 +1,4 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
-<style>
-#g-add-photos-canvas object {
- height: 33px;
- left: -80px;
- position: relative;
- z-index: 100;
-}
-#g-add-photos-canvas span {
- height: 33px;
- width: 150px;
-}
-#g-add-photos-button {
- float: left;
- left: 155px;
- padding-bottom: .5em;
- padding-top: .5em;
- position: relative;
- width: 150px;
- z-index: 1;
-}
-</style>
<script type="text/javascript" src="<?= url::file("lib/swfobject.js") ?>"></script>
<script type="text/javascript" src="<?= url::file("lib/uploadify/jquery.uploadify.min.js") ?>"></script>
<script type="text/javascript">
@@ -113,7 +92,7 @@
<p>
<?= t("Photos will be uploaded to album: ") ?>
</p>
- <ul class="g-breadcrumbs">
+ <ul class="g-breadcrumbs ui-helper-clearfix">
<? foreach ($album->parents() as $i => $parent): ?>
<li<? if ($i == 0) print " class=\"g-first\"" ?>> <?= html::clean($parent->title) ?> </li>
<? endforeach ?>
@@ -121,11 +100,11 @@
</ul>
</div>
-<div id="g-add-photos-canvas" style="text-align: center;clear: both">
- <a id="g-add-photos-button" class="ui-corner-all" href="#"><?= t("Select photos...") ?></a>
+<div id="g-add-photos-canvas">
+ <button id="g-add-photos-button" class="g-button ui-state-default ui-corner-all" href="#"><?= t("Select photos...") ?></button>
<span id="g-uploadify"></span>
</div>
-<div id="g-add-photos-status" style="text-align: center;">
- <ul>
+<div id="g-add-photos-status">
+ <ul id="g-action-status" class="g-message-block">
</ul>
</div>