diff options
author | Nathan Kinkade <nkinkade@nkinka.de> | 2010-02-02 02:59:20 +0000 |
---|---|---|
committer | Nathan Kinkade <nkinkade@nkinka.de> | 2010-02-02 02:59:20 +0000 |
commit | 9d0927dda936756f1f5003813f437d714fe481f8 (patch) | |
tree | fe1b887345b37387ab0ddcfd78bf344f6150b6cc /modules/g2_import/helpers | |
parent | a6f794c20dc3592bcaef17c622413c1b670a20d8 (diff) | |
parent | 43985ea2fb137aa7d532617271e37d7c20def3c5 (diff) |
Merge branch 'master' of git://github.com/gallery/gallery3
Diffstat (limited to 'modules/g2_import/helpers')
-rw-r--r-- | modules/g2_import/helpers/g2_import.php | 93 | ||||
-rw-r--r-- | modules/g2_import/helpers/g2_import_installer.php | 2 | ||||
-rw-r--r-- | modules/g2_import/helpers/g2_import_task.php | 10 |
3 files changed, 63 insertions, 42 deletions
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 8724ae50..0fcc0539 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -24,6 +24,7 @@ class g2_import_Core { public static $g2_base_url = null; private static $current_g2_item = null; + private static $error_reporting = null; static function is_configured() { return module::get_var("g2_import", "embed_path"); @@ -239,7 +240,7 @@ class g2_import_Core { $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" => $e->__toString())); + array("id" => $g2_group_id, "exception" => (string)$e)); } switch ($g2_group->getGroupType()) { @@ -295,21 +296,20 @@ class g2_import_Core { $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" => $e->__toString())); + array("id" => $g2_user_id, "exception" => (string)$e)); } $g2_groups = g2(GalleryCoreApi::fetchGroupsForUser($g2_user->getId())); - try { + $user = identity::lookup_user_by_name($g2_user->getUsername()); + if ($user) { + $message = t("Loaded existing user: '%name'.", array("name" => $user->name)); + } else { $user = identity::create_user($g2_user->getUsername(), $g2_user->getfullname(), ""); $message = t("Created user: '%name'.", array("name" => $user->name)); - } catch (Exception $e) { - // @todo For now we assume this is a "duplicate user" exception - $user = identity::lookup_user_by_name($g2_user->getUsername()); - $message = t("Loaded existing user: '%name'.", array("name" => $user->name)); } $user->hashed_password = $g2_user->getHashedPassword(); - $user->email = $g2_user->getEmail(); + $user->email = $g2_user->getEmail() ? $g2_user->getEmail() : "unknown@unknown.com"; $user->locale = $g2_user->getLanguage(); foreach ($g2_groups as $g2_group_id => $g2_group_name) { if ($g2_group_id == $g2_admin_group_id) { @@ -353,7 +353,7 @@ class g2_import_Core { $g2_album = g2(GalleryCoreApi::loadEntitiesById($g2_album_id)); } catch (Exception $e) { return t("Failed to import Gallery 2 album with id: %id\n%exception", - array("id" => $g2_album_id, "exception" => $e->__toString())); + array("id" => $g2_album_id, "exception" => (string)$e)); } if ($g2_album->getParentId() == null) { @@ -361,13 +361,13 @@ class g2_import_Core { } $parent_album = ORM::factory("item", self::map($g2_album->getParentId())); - $album = album::create( - $parent_album, - $g2_album->getPathComponent(), - self::_decode_html_special_chars($g2_album->getTitle()), - self::_decode_html_special_chars(self::extract_description($g2_album)), - self::map($g2_album->getOwnerId())); - + $album = ORM::factory("item"); + $album->type = "album"; + $album->parent_id = self::map($g2_album->getParentId()); + $album->name = $g2_album->getPathComponent(); + $album->title = self::_decode_html_special_chars($g2_album->getTitle()); + $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)); $album->created = $g2_album->getCreationTimestamp(); @@ -449,7 +449,7 @@ class g2_import_Core { $g2_path = g2($g2_item->fetchPath()); } catch (Exception $e) { return t("Failed to import Gallery 2 item with id: %id\n%exception", - array("id" => $g2_item_id, "exception" => $e->__toString())); + array("id" => $g2_item_id, "exception" => (string)$e)); } $parent = ORM::factory("item", self::map($g2_item->getParentId())); @@ -482,19 +482,21 @@ class g2_import_Core { $corrupt = 1; } try { - $item = photo::create( - $parent, - $g2_path, - $g2_item->getPathComponent(), - self::_decode_html_special_chars($g2_item->getTitle()), - self::_decode_html_special_chars(self::extract_description($g2_item)), - self::map($g2_item->getOwnerId())); + $item = ORM::factory("item"); + $item->type = "photo"; + $item->parent_id = $parent->id; + $item->set_data_file($g2_path); + $item->name = $g2_item->getPathComponent(); + $item->title = self::_decode_html_special_chars($g2_item->getTitle()); + $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 image $g2_path\n" . $e->__toString()); + Kohana_Log::add("alert", "Corrupt image $g2_path\n" . (string)$e); $message[] = t("Corrupt image '%path'", array("path" => $g2_path)); - $message[] = $e->__toString(); + $message[] = (string)$e; $corrupt = 1; + $item = null; } break; @@ -502,18 +504,19 @@ class g2_import_Core { // @todo we should transcode other types into FLV if (in_array($g2_item->getMimeType(), array("video/mp4", "video/x-flv"))) { try { - $item = movie::create( - $parent, - $g2_path, - $g2_item->getPathComponent(), - self::_decode_html_special_chars($g2_item->getTitle()), - self::_decode_html_special_chars(self::extract_description($g2_item)), - self::map($g2_item->getOwnerId())); + $item = ORM::factory("item"); + $item->parent_id = $parent->id; + $item->set_data_file($g2_path); + $item->name = $g2_item->getPathComponent(); + $item->title = self::_decode_html_special_chars($g2_item->getTitle()); + $item->description = self::_decode_html_special_chars(self::extract_description($g2_item)); + $item->owner_id = self::map($g2_item->getOwnerId()); } catch (Exception $e) { - Kohana_Log::add("alert", "Corrupt movie $g2_path\n" . $e->__toString()); + Kohana_Log::add("alert", "Corrupt movie $g2_path\n" . (string)$e); $message[] = t("Corrupt movie '%path'", array("path" => $g2_path)); - $message[] = $e->__toString(); + $message[] = (string)$e; $corrupt = 1; + $item = null; } } else { Kohana_Log::add("alert", "$g2_path is an unsupported movie type"); @@ -593,7 +596,7 @@ class g2_import_Core { $g2_comment = g2(GalleryCoreApi::loadEntitiesById($g2_comment_id)); } catch (Exception $e) { return t("Failed to import Gallery 2 comment with id: %id\%exception", - array("id" => $g2_comment_id, "exception" => $e->__toString())); + array("id" => $g2_comment_id, "exception" => (string)$e)); } $text = $g2_comment->getSubject(); @@ -631,15 +634,17 @@ class g2_import_Core { GalleryCoreApi::requireOnce("modules/tags/classes/TagsHelper.class"); $g2_item_id = array_shift($queue); $g3_item = ORM::factory("item", self::map($g2_item_id)); + if (!$g3_item->loaded()) { + return; + } try { $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); } catch (Exception $e) { return t("Failed to import Gallery 2 tags for item with id: %id\n%exception", - array("id" => $g2_item_id, "exception" => $e->__toString())); + array("id" => $g2_item_id, "exception" => (string)$e)); } - // Multiword tags have the space changed to dots.s foreach ($tag_names as $tag_name) { tag::add($g3_item, $tag_name); } @@ -927,6 +932,16 @@ class g2_import_Core { "useAuthToken" => false)); return str_replace(self::$g2_base_url, "", $url); } + + static function lower_error_reporting() { + // Gallery 2 was not designed to run in E_STRICT mode and will barf out errors. So dial down + // the error reporting when we make G2 calls. + self::$error_reporting = error_reporting(error_reporting() & ~E_STRICT); + } + + static function restore_error_reporting() { + error_reporting(self::$error_reporting); + } } /** diff --git a/modules/g2_import/helpers/g2_import_installer.php b/modules/g2_import/helpers/g2_import_installer.php index 77b61d3e..1ec8afa9 100644 --- a/modules/g2_import/helpers/g2_import_installer.php +++ b/modules/g2_import/helpers/g2_import_installer.php @@ -31,7 +31,7 @@ class g2_import_installer { KEY `g2_id` (`g2_id`)) DEFAULT CHARSET=utf8;"); - module::set_version("g2_import", 1); + module::set_version("g2_import", 2); mkdir(VARPATH . "modules/g2_import"); } diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index e80b88b9..21ba4c3a 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -19,17 +19,19 @@ */ class g2_import_task_Core { static function available_tasks() { + g2_import::lower_error_reporting(); if (g2_import::is_configured()) { g2_import::init(); } - + $version = g2_import::version(); + g2_import::restore_error_reporting(); if (class_exists("GalleryCoreApi")) { return array(Task_Definition::factory() ->callback("g2_import_task::import") ->name(t("Import from Gallery 2")) ->description( - t("Gallery %version detected", array("version" => g2_import::version()))) + t("Gallery %version detected", array("version" => $version))) ->severity(log::SUCCESS)); } @@ -37,6 +39,8 @@ class g2_import_task_Core { } static function import($task) { + g2_import::lower_error_reporting(); + $start = microtime(true); g2_import::init(); @@ -207,5 +211,7 @@ class g2_import_task_Core { $task->set("mode", $mode); $task->set("queue", $queue); $task->set("done", $done); + + g2_import::restore_error_reporting(); } } |