diff options
Diffstat (limited to 'modules/g2_import')
| -rw-r--r-- | modules/g2_import/controllers/admin_g2_import.php | 3 | ||||
| -rw-r--r-- | modules/g2_import/helpers/g2_import.php | 89 | ||||
| -rw-r--r-- | modules/g2_import/helpers/g2_import_installer.php | 21 | ||||
| -rw-r--r-- | modules/g2_import/helpers/g2_import_task.php | 8 | ||||
| -rw-r--r-- | modules/g2_import/views/admin_g2_import.html.php | 116 |
5 files changed, 156 insertions, 81 deletions
diff --git a/modules/g2_import/controllers/admin_g2_import.php b/modules/g2_import/controllers/admin_g2_import.php index f2969f49..18d09363 100644 --- a/modules/g2_import/controllers/admin_g2_import.php +++ b/modules/g2_import/controllers/admin_g2_import.php @@ -21,6 +21,9 @@ class Admin_g2_import_Controller extends Admin_Controller { public function index() { if (g2_import::is_configured()) { g2_import::init(); + } + + if (class_exists("GalleryCoreApi")) { $g2_stats = g2_import::stats(); $g2_sizes = g2_import::common_sizes(); } diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index bcaffab1..91ca1e63 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -17,6 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ + class g2_import_Core { public static $init = false; public static $map = array(); @@ -112,11 +113,13 @@ class g2_import_Core { "require_once(dirname(__FILE__) . '/modules/core/classes/GalleryDataCache.class');", "define('GALLERY_CONFIG_DIR', dirname(__FILE__));", "\$gallery =& new Gallery();", + "\$GLOBALS['gallery'] =& new Gallery();", "\$gallery = new Gallery();"), array("require_once(dirname(__FILE__) . '/Gallery.class');", "require_once('$base_dir/modules/core/classes/GalleryDataCache.class');", "define('GALLERY_CONFIG_DIR', '$config_dir');", "\$gallery =& new G2_Gallery();", + "\$GLOBALS['gallery'] =& new G2_Gallery();", "\$gallery = new G2_Gallery();"), array_merge(array("<?php defined(\"SYSPATH\") or die(\"No direct script access.\") ?>\n"), file("$base_dir/bootstrap.inc")))); @@ -213,7 +216,14 @@ class g2_import_Core { return; } - $g2_group = g2(GalleryCoreApi::loadEntitiesById($g2_group_id)); + try { + $g2_group = g2(GalleryCoreApi::loadEntitiesById($g2_group_id)); + } catch (Exception $e) { + g2_import::log( + t("Failed to import Gallery 2 group with id: %id", array("id" => $g2_group_id))); + return; + } + switch ($g2_group->getGroupType()) { case GROUP_NORMAL: try { @@ -261,9 +271,8 @@ class g2_import_Core { try { $g2_user = g2(GalleryCoreApi::loadEntitiesById($g2_user_id)); } catch (Exception $e) { - $msg = t("Failed to import Gallery 2 user with id: %id", array("id" => $g2_user_id)); - Kohana::log("alert", $msg); - message::warning($msg); + g2_import::log( + t("Failed to import Gallery 2 user with id: %id", array("id" => $g2_user_id))); return; } $g2_groups = g2(GalleryCoreApi::fetchGroupsForUser($g2_user->getId())); @@ -311,8 +320,15 @@ class g2_import_Core { return; } - // Load the G2 album item, and figure out its parent in G3. - $g2_album = g2(GalleryCoreApi::loadEntitiesById($g2_album_id)); + try { + // Load the G2 album item, and figure out its parent in G3. + $g2_album = g2(GalleryCoreApi::loadEntitiesById($g2_album_id)); + } catch (Exception $e) { + g2_import::log( + t("Failed to import Gallery 2 album with id: %id", array("id" => $g2_album_id))); + return; + } + if ($g2_album->getParentId() == null) { return; } @@ -398,10 +414,17 @@ class g2_import_Core { return; } - self::$current_g2_item = $g2_item = g2(GalleryCoreApi::loadEntitiesById($g2_item_id)); + try { + self::$current_g2_item = $g2_item = g2(GalleryCoreApi::loadEntitiesById($g2_item_id)); + $g2_path = g2($g2_item->fetchPath()); + } catch (Exception $e) { + g2_import::log( + t("Failed to import Gallery 2 item with id: %id", array("id" => $g2_item_id))); + return; + } + $parent = ORM::factory("item", self::map($g2_item->getParentId())); - $g2_path = g2($g2_item->fetchPath()); $g2_type = $g2_item->getEntityType(); $corrupt = 0; if (!file_exists($g2_path)) { @@ -412,8 +435,8 @@ class g2_import_Core { // // Note that this will change movies to be photos, if there's a broken movie. Hopefully // this case is rare enough that we don't need to take any heroic action here. - - Kohana::log("alert", "$g2_path missing in import; replacing it"); + g2_import::log( + t("%path missing in import; replacing it with a placeholder", array("path" => $g2_path))); $g2_path = MODPATH . "g2_import/data/broken-image.gif"; $g2_type = "GalleryPhotoItem"; $corrupt = 1; @@ -422,8 +445,8 @@ class g2_import_Core { switch ($g2_type) { case "GalleryPhotoItem": if (!in_array($g2_item->getMimeType(), array("image/jpeg", "image/gif", "image/png"))) { + Kohana::log("alert", "$g2_path is an unsupported image type; using a placeholder gif"); $g2_path = MODPATH . "g2_import/data/broken-image.gif"; - Kohana::log("alert", "$g2_path unsupported image type; using a placeholder gif"); $corrupt = 1; } try { @@ -435,8 +458,8 @@ class g2_import_Core { self::extract_description($g2_item), self::map($g2_item->getOwnerId())); } catch (Exception $e) { - Kohana::log("alert", "Corrupt image $g2_path\n" . - $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana::log( + "alert", "Corrupt image $g2_path\n" . $e->getMessage() . "\n" . $e->getTraceAsString()); $corrupt = 1; } break; @@ -492,9 +515,7 @@ class g2_import_Core { t("<a href=\"%g2_url\">%title</a> from Gallery 2 could not be processed", array("g2_url" => $g2_item_url, "title" => $g2_item->getTitle())); } - message::warning($warning); - log::warning("g2_import", $warning); - Kohana::log("alert", $warning); + g2_import::log($warning); } self::$current_g2_item = null; @@ -505,7 +526,14 @@ class g2_import_Core { */ static function import_comment(&$queue) { $g2_comment_id = array_shift($queue); - $g2_comment = g2(GalleryCoreApi::loadEntitiesById($g2_comment_id)); + + try { + $g2_comment = g2(GalleryCoreApi::loadEntitiesById($g2_comment_id)); + } catch (Exception $e) { + g2_import::log("Failed to import Gallery 2 comment with id: %id", + array("id" => $g2_comment_id)); + return; + } $text = $g2_comment->getSubject(); if ($text) { @@ -534,7 +562,14 @@ 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)); - $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); + + try { + $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); + } catch (Exception $e) { + g2_import::log("Failed to import tags for Gallery 2 item with id: %id", + array("id" => $g2_item_id)); + return; + } foreach ($tag_names as $tag_name) { $tag = tag::add($g3_item, $tag_name); @@ -549,7 +584,18 @@ class g2_import_Core { return; } - foreach (preg_split("/[,;]/", $keywords) as $keyword) { + // Keywords in G2 are free form. So we don't know what our user used as a separator. Try to + // be smart about it. If we see a comma or a semicolon, expect the keywords to be separated + // by that delimeter. Otherwise, use space as the delimiter. + if (strpos($keywords, ";")) { + $delim = ";"; + } else if (strpos($keywords, ",")) { + $delim = ","; + } else { + $delim = " "; + } + + foreach (preg_split("/$delim/", $keywords) as $keyword) { $keyword = trim($keyword); if ($keyword) { tag::add($item, $keyword); @@ -773,6 +819,11 @@ class g2_import_Core { $g2_map->save(); self::$map[$g2_id] = $g3_id; } + + static function log($msg) { + message::warning($msg); + Kohana::log("alert", $msg); + } } /** diff --git a/modules/g2_import/helpers/g2_import_installer.php b/modules/g2_import/helpers/g2_import_installer.php index 5f414d42..0f87da6c 100644 --- a/modules/g2_import/helpers/g2_import_installer.php +++ b/modules/g2_import/helpers/g2_import_installer.php @@ -20,19 +20,16 @@ class g2_import_installer { static function install() { $db = Database::instance(); - $version = module::get_version("g2_import"); - if ($version == 0) { - $db->query("CREATE TABLE IF NOT EXISTS {g2_maps} ( - `id` int(9) NOT NULL auto_increment, - `g2_id` int(9) NOT NULL, - `g3_id` int(9) NOT NULL, - PRIMARY KEY (`id`), - KEY (`g2_id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE IF NOT EXISTS {g2_maps} ( + `id` int(9) NOT NULL auto_increment, + `g2_id` int(9) NOT NULL, + `g3_id` int(9) NOT NULL, + PRIMARY KEY (`id`), + KEY (`g2_id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - module::set_version("g2_import", 1); - mkdir(VARPATH . "modules/g2_import"); - } + module::set_version("g2_import", 1); + mkdir(VARPATH . "modules/g2_import"); } static function uninstall() { diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index 4cd95581..3961097d 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -21,15 +21,19 @@ class g2_import_task_Core { static function available_tasks() { if (g2_import::is_configured()) { g2_import::init(); + } + + + 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()))) ->severity(log::SUCCESS)); - } else { - return array(); } + + return array(); } static function import($task) { diff --git a/modules/g2_import/views/admin_g2_import.html.php b/modules/g2_import/views/admin_g2_import.html.php index d5e29e12..da2bb5d1 100644 --- a/modules/g2_import/views/admin_g2_import.html.php +++ b/modules/g2_import/views/admin_g2_import.html.php @@ -1,74 +1,94 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> -<div id="gAdminG2Config"> +<div id="gAdminG2Import"> <h1> <?= t("Gallery 2 Import") ?> </h1> <p> <?= t("Import your Gallery 2 users, photos, movies, comments and tags into your new Gallery 3 installation.") ?> - <br/> - <?= t("<b>Note</b>: The importer is a work in progress and does not currently support permissions, and movie formats other than Flash video and MP4") ?> - <br/> - <?= t("<b>Note</b>: The importer has <i>known issues</i> with the eAccelerator PHP accelerator. If you're using eAccelerator, please disable it. One way to do that is to put <code>php_value eaccelerator.enable 0</code> in gallery3/.htaccess") ?> </p> - <?= $form ?> -</div> - -<? if (g2_import::is_initialized()): ?> -<div id="gAdminG2Import"> - <h1> <?= t("Import") ?> </h1> - <ul id="gMessage"> - <li class="gSuccess"> - <?= t("Gallery version %version detected", array("version" => g2_import::version())) ?> - </li> - </ul> - <div class="gInfo"> + <div id="gAdminG2ImportNotes"> + <h2> <?= t("Notes") ?> </h2> <p> - <?= t("Your Gallery 2 has the following importable data in it") ?> + <?= t("The import process is a work in progress with some known issues:") ?> </p> <ul> <li> - <?= t2("1 user", "%count users", $g2_stats["users"]) ?> + <?= t("Permissions are <b>not imported</b>. You will have to set them again manually (for now).") ?> </li> <li> - <?= t2("1 group", "%count groups", $g2_stats["groups"]) ?> + <?= t("The only supported image formats are JPG, PNG and GIF. Other formats will be skipped.") ?> </li> <li> - <?= t2("1 album", "%count albums", $g2_stats["albums"]) ?> + <?= t("The only supported movie formats are FLV and MP4. Other formats will be skipped.") ?> </li> <li> - <?= t2("1 photo", "%count photos", $g2_stats["photos"]) ?> + <?= t("The eAccelerator PHP performance extension is known to cause issues. If you're using eAccelerator and having problems, please disable it while you do your import. One way to do that is to put <code>php_value eaccelerator.enable 0</code> in gallery3/.htaccess") ?> </li> - <li> - <?= t2("1 movie", "%count movies", $g2_stats["movies"]) ?> + </ul> + </div> + <?= $form ?> + + <? if (g2_import::is_initialized()): ?> + <div id="gAdminG2ImportDetails"> + <h2> <?= t("Import") ?> </h2> + <ul id="gMessage"> + <li class="gSuccess"> + <?= t("Gallery version %version detected", array("version" => g2_import::version())) ?> </li> - <li> - <?= t2("1 comment", "%count comments", $g2_stats["comments"]) ?> + <? if ($g2_sizes["thumb"]["size"] && $thumb_size != $g2_sizes["thumb"]["size"]): ?> + <li class="gWarning"> + <?= t("Your most common thumbnail size in Gallery 2 is %g2_pixels pixels, but your Gallery 3 thumbnail size is set to %g3_pixels pixels. <a href=\"%url\">Using the same value</a> will speed up your import.", + array("g2_pixels" => $g2_sizes["thumb"]["size"], + "g3_pixels" => $thumb_size, + "url" => url::site("admin/theme_options"))) ?> </li> - <li> - <?= t2("1 tagged photo/movie/album", - "%count tagged photos/movies/albums", $g2_stats["tags"]) ?> + <? endif ?> + + <? if ($g2_sizes["resize"]["size"] && $resize_size != $g2_sizes["resize"]["size"]): ?> + <li class="gWarning"> + <?= t("Your most common intermediate size in Gallery 2 is %g2_pixels pixels, but your Gallery 3 thumbnail size is set to %g3_pixels pixels. <a href=\"%url\">Using the same value</a> will speed up your import.", + array("g2_pixels" => $g2_sizes["resize"]["size"], + "g3_pixels" => $resize_size, + "url" => url::site("admin/theme_options"))) ?> </li> + <? endif ?> </ul> - </div> - <? if ($g2_sizes["thumb"]["size"] && $thumb_size != $g2_sizes["thumb"]["size"]): ?> - <div class="gWarning"> - <?= t("Your most common thumbnail size in Gallery 2 is %g2_pixels pixels, but your Gallery 3 thumbnail size is set to %g3_pixels pixels. <a href=\"%url\">Using the same value</a> will speed up your import.", - array("g2_pixels" => $g2_sizes["thumb"]["size"], - "g3_pixels" => $thumb_size, - "url" => url::site("admin/theme_options"))) ?> - </div> - <? endif ?> + <div class="gInfo"> + <p> + <?= t("Your Gallery 2 has the following importable data in it") ?> + </p> + <ul> + <li> + <?= t2("1 user", "%count users", $g2_stats["users"]) ?> + </li> + <li> + <?= t2("1 group", "%count groups", $g2_stats["groups"]) ?> + </li> + <li> + <?= t2("1 album", "%count albums", $g2_stats["albums"]) ?> + </li> + <li> + <?= t2("1 photo", "%count photos", $g2_stats["photos"]) ?> + </li> + <li> + <?= t2("1 movie", "%count movies", $g2_stats["movies"]) ?> + </li> + <li> + <?= t2("1 comment", "%count comments", $g2_stats["comments"]) ?> + </li> + <li> + <?= t2("1 tagged photo/movie/album", + "%count tagged photos/movies/albums", $g2_stats["tags"]) ?> + </li> + </ul> + </div> - <? if ($g2_sizes["resize"]["size"] && $resize_size != $g2_sizes["resize"]["size"]): ?> - <div class="gWarning"> - <?= t("Your most common intermediate size in Gallery 2 is %g2_pixels pixels, but your Gallery 3 thumbnail size is set to %g3_pixels pixels. <a href=\"%url\">Using the same value</a> will speed up your import.", - array("g2_pixels" => $g2_sizes["resize"]["size"], - "g3_pixels" => $resize_size, - "url" => url::site("admin/theme_options"))) ?> + <p> + <a class="gButtonLink gDialogLink ui-state-default ui-corner-all" + href="<?= url::site("admin/maintenance/start/g2_import_task::import?csrf=$csrf") ?>"> + <?= t("Begin import!") ?> + </a> + </p> </div> <? endif ?> - - <?= t("You can begin your import on the <a href=\"%url\">maintenance page</a>", - array("url" => url::site("admin/maintenance"))) ?> </div> -<? endif ?> |
