summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/g2_import/controllers/admin_g2_import.php6
-rw-r--r--modules/g2_import/helpers/g2_import.php100
-rw-r--r--modules/g2_import/helpers/g2_import_event.php4
-rw-r--r--modules/g2_import/helpers/g2_import_task.php2
-rw-r--r--modules/g2_import/views/admin_g2_import.html.php50
5 files changed, 158 insertions, 4 deletions
diff --git a/modules/g2_import/controllers/admin_g2_import.php b/modules/g2_import/controllers/admin_g2_import.php
index 6197240b..5ef97b5a 100644
--- a/modules/g2_import/controllers/admin_g2_import.php
+++ b/modules/g2_import/controllers/admin_g2_import.php
@@ -21,11 +21,17 @@ class Admin_g2_import_Controller extends Admin_Controller {
public function index() {
if (g2_import::is_configured()) {
g2_import::init();
+ $g2_stats = g2_import::stats();
+ $g2_sizes = g2_import::common_sizes();
}
$view = new Admin_View("admin.html");
$view->content = new View("admin_g2_import.html");
$view->content->form = $this->_get_import_form();
+ $view->content->g2_stats = $g2_stats;
+ $view->content->g2_sizes = $g2_sizes;
+ $view->content->thumb_size = module::get_var("core", "thumb_size");
+ $view->content->resize_size = module::get_var("core", "resize_size");
print $view;
}
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php
index e3e7c872..dbe2260d 100644
--- a/modules/g2_import/helpers/g2_import.php
+++ b/modules/g2_import/helpers/g2_import.php
@@ -35,6 +35,8 @@ class g2_import_Core {
public static $init = false;
public static $map = array();
+ private static $current_g2_item = null;
+
static function is_configured() {
return module::get_var("g2_import", "embed_path");
}
@@ -94,6 +96,7 @@ class g2_import_Core {
$stats["groups"] = g2(GalleryCoreApi::fetchGroupCount());
$stats["albums"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryAlbumItem"));
$stats["photos"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryPhotoItem"));
+ $stats["movies"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryMovieItem"));
list (, $stats["comments"]) = g2(GalleryCommentHelper::fetchAllComments($root_album_id, 1));
return $stats;
}
@@ -232,7 +235,7 @@ class g2_import_Core {
return;
}
- $g2_item = g2(GalleryCoreApi::loadEntitiesById($g2_item_id));
+ self::$current_g2_item = $g2_item = g2(GalleryCoreApi::loadEntitiesById($g2_item_id));
$parent = ORM::factory("item", self::map($g2_item->getParentId()));
switch ($g2_item->getEntityType()) {
case "GalleryPhotoItem":
@@ -268,6 +271,101 @@ class g2_import_Core {
}
}
+ // If the thumbnails and resizes created for the Gallery2 photo match the dimensions of the
+ // ones we expect to create for Gallery3, then copy the files over instead of recreating them.
+ static function copy_matching_thumbnails_and_resizes($item) {
+ // Precaution: if the Gallery2 item was watermarked, or we have the Gallery3 watermark module
+ // active then we'd have to do something a lot more sophisticated here. For now, just skip
+ // this step in those cases.
+ if (module::is_installed("watermark")) {
+ return;
+ }
+
+ // For now just do the copy for photos and movies. Albums are tricky because we're may not
+ // yet be setting their album cover properly.
+ // @todo implement this for albums also
+ if (!$item->is_movie() && !$item->is_photo()) {
+ return;
+ }
+
+ $g2_item_id = self::$current_g2_item->getId();
+ $derivatives = g2(GalleryCoreApi::fetchDerivativesByItemIds(array($g2_item_id)));
+
+ $target_thumb_size = module::get_var("core", "thumb_size");
+ $target_resize_size = module::get_var("core", "resize_size");
+ foreach ($derivatives[$g2_item_id] as $derivative) {
+ if ($derivative->getPostFilterOperations()) {
+ // Let's assume for now that this is a watermark operation, which we can't handle.
+ continue;
+ }
+
+ if ($derivative->getDerivativeType() == DERIVATIVE_TYPE_IMAGE_THUMBNAIL &&
+ $item->thumb_dirty &&
+ ($derivative->getWidth() == $target_thumb_size ||
+ $derivative->getHeight() == $target_thumb_size)) {
+ copy(g2($derivative->fetchPath()), $item->thumb_path());
+ $item->thumb_dirty = false;
+ }
+
+ if ($derivative->getDerivativeType() == DERIVATIVE_TYPE_IMAGE_RESIZE &&
+ $item->resize_dirty &&
+ ($derivative->getWidth() == $target_resize_size ||
+ $derivative->getHeight() == $target_resize_size)) {
+ copy(g2($derivative->fetchPath()), $item->resize_path());
+ $item->resize_dirty = false;
+ }
+ }
+ $item->save();
+ }
+
+ static function common_sizes() {
+ global $gallery;
+ foreach (array("resize" => DERIVATIVE_TYPE_IMAGE_RESIZE,
+ "thumb" => DERIVATIVE_TYPE_IMAGE_THUMBNAIL) as $type => $g2_enum) {
+ $results = g2($gallery->search(
+ "SELECT COUNT(*) AS c, [GalleryDerivativeImage::width] " .
+ "FROM [GalleryDerivativeImage], [GalleryDerivative] " .
+ "WHERE [GalleryDerivativeImage::id] = [GalleryDerivative::id] " .
+ " AND [GalleryDerivative::derivativeType] = ? " .
+ " AND [GalleryDerivativeImage::width] >= [GalleryDerivativeImage::height] " .
+ "GROUP BY [GalleryDerivativeImage::width] " .
+ "ORDER by c DESC",
+ array($g2_enum),
+ array("limit" => array(1))));
+ $row = $results->nextResult();
+ $sizes[$type] = array("size" => $row[1], "count" => $row[0]);
+
+ $results = g2($gallery->search(
+ "SELECT COUNT(*) AS c, [GalleryDerivativeImage::height] " .
+ "FROM [GalleryDerivativeImage], [GalleryDerivative] " .
+ "WHERE [GalleryDerivativeImage::id] = [GalleryDerivative::id] " .
+ " AND [GalleryDerivative::derivativeType] = ? " .
+ " AND [GalleryDerivativeImage::height] >= [GalleryDerivativeImage::width] " .
+ "GROUP BY [GalleryDerivativeImage::height] " .
+ "ORDER by c DESC",
+ array($g2_enum),
+ array("limit" => array(1))));
+ $row = $results->nextResult();
+ // Compare the counts. If the best fitting height does not match the best fitting width,
+ // then pick the one with the largest count. Otherwise, sum them.
+ if ($sizes[$type]["size"] != $row[1]) {
+ if ($row[0] > $sizes[$type["count"]]) {
+ $sizes[$type] = array("size" => $row[1], "count" => $row[0]);
+ }
+ } else {
+ $sizes[$type]["count"] += $row[0];
+ }
+
+ $results = g2($gallery->search(
+ "SELECT COUNT(*) FROM [GalleryDerivative] WHERE [GalleryDerivative::derivativeType] = ?",
+ array($g2_enum)));
+ $row = $results->nextResult();
+ $sizes[$type]["total"] = $row[0];
+ }
+
+ return $sizes;
+ }
+
static function extract_description($g2_item) {
// If the summary is a subset of the description just import the description, else import both.
$g2_summary = $g2_item->getSummary();
diff --git a/modules/g2_import/helpers/g2_import_event.php b/modules/g2_import/helpers/g2_import_event.php
index 205de98e..d6f4fc15 100644
--- a/modules/g2_import/helpers/g2_import_event.php
+++ b/modules/g2_import/helpers/g2_import_event.php
@@ -21,4 +21,8 @@ class g2_import_event_Core {
static function item_before_delete($item) {
Database::instance()->delete("g2_maps", array("g3_id" => $item->id));
}
+
+ static function item_created($item) {
+ g2_import::copy_matching_thumbnails_and_resizes($item);
+ }
}
diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php
index bfcdf033..8fd8f72b 100644
--- a/modules/g2_import/helpers/g2_import_task.php
+++ b/modules/g2_import/helpers/g2_import_task.php
@@ -59,7 +59,7 @@ class g2_import_task_Core {
}
$modes = array("groups", "users", "albums", "photos", "comments", "done");
- while (!$task->done && microtime(true) - $start < 1) {
+ while (!$task->done && microtime(true) - $start < 1.5) {
if ($i >= ($stats[$modes[$mode]] - 1)) {
$i = 0;
$mode++;
diff --git a/modules/g2_import/views/admin_g2_import.html.php b/modules/g2_import/views/admin_g2_import.html.php
index 5c2cfa6d..329a55a8 100644
--- a/modules/g2_import/views/admin_g2_import.html.php
+++ b/modules/g2_import/views/admin_g2_import.html.php
@@ -12,10 +12,56 @@
<div id="gAdminG2Import">
<h1> <?= t("Import") ?> </h1>
<div class="gSuccess">
- <?= t("Gallery version %version detected", array("version" => g2_import::version())) ?>
+ <p>
+ <?= t("Gallery version %version detected", array("version" => g2_import::version())) ?>
+ </p>
</div>
- <?= t("You can perform an import on the <a href=\"%url\">maintenance page</a>",
+ <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>
+ </ul>
+ </div>
+
+ <? if ($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_details"))) ?>
+ </div>
+ <? endif ?>
+
+ <? if ($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_details"))) ?>
+ </div>
+ <? endif ?>
+
+ <?= t("You can begin your import on the <a href=\"%url\">maintenance page</a>",
array("url" => url::site("admin/maintenance"))) ?>
</div>
<? endif ?>