summaryrefslogtreecommitdiff
path: root/modules/g2_import
diff options
context:
space:
mode:
Diffstat (limited to 'modules/g2_import')
-rw-r--r--modules/g2_import/controllers/g2.php80
-rw-r--r--modules/g2_import/helpers/g2_import.php92
-rw-r--r--modules/g2_import/helpers/g2_import_event.php5
-rw-r--r--modules/g2_import/helpers/g2_import_installer.php15
-rw-r--r--modules/g2_import/helpers/g2_import_task.php4
-rw-r--r--modules/g2_import/module.info2
-rw-r--r--modules/g2_import/views/admin_g2_import.html.php20
7 files changed, 184 insertions, 34 deletions
diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php
new file mode 100644
index 00000000..3e002758
--- /dev/null
+++ b/modules/g2_import/controllers/g2.php
@@ -0,0 +1,80 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2009 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
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * 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_Controller extends Admin_Controller {
+ /**
+ * Redirect Gallery 2 urls to their appropriate matching Gallery 3 url.
+ *
+ * We use mod_rewrite to create this path, so Gallery2 urls like this:
+ * /gallery2/v/Family/Wedding.jpg.html
+ * /gallery2/main.php?g2_view=core.ShowItem&g2_itemId=1234
+ *
+ * Show up here like this:
+ * /g2/map?path=v/Family/Wedding.jpg.html
+ * /g2/map?g2_view=core.ShowItem&g2_itemId=1931
+ */
+ public function map() {
+ $input = Input::instance();
+ $path = $input->get("path");
+ $id = $input->get("g2_itemId");
+
+ if ($id) {
+ $where = array("g2_id", "=", $id);
+ } else if ($path) {
+ $where = array("g2_url", "=", $path);
+ } else {
+ throw new Kohana_404_Exception();
+ }
+
+ $g2_map = ORM::factory("g2_map")
+ ->merge_where(array($where))
+ ->find();
+
+ if (!$g2_map->loaded()) {
+ throw new Kohana_404_Exception();
+ }
+
+ $item = ORM::factory("item")->where("id", "=", $g2_map->g3_id)->find();
+ if (!$item->loaded() || !access::can("view", $item)) {
+ throw new Kohana_404_Exception();
+ }
+
+
+ // Redirect the user to the new url
+ switch ($g2_map->resource_type) {
+ case "thumbnail":
+ url::redirect($item->thumb_url(true));
+
+ case "resize":
+ url::redirect($item->resize_url(true));
+
+ case "full":
+ url::redirect($item->file_url(true));
+
+ case "item":
+ case "album":
+ url::redirect($item->abs_url());
+
+ case "group":
+ case "user":
+ default:
+ throw new Kohana_404_Exception();
+ }
+ }
+} \ No newline at end of file
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php
index 202a0e92..8724ae50 100644
--- a/modules/g2_import/helpers/g2_import.php
+++ b/modules/g2_import/helpers/g2_import.php
@@ -21,6 +21,7 @@
class g2_import_Core {
public static $init = false;
public static $map = array();
+ public static $g2_base_url = null;
private static $current_g2_item = null;
@@ -155,6 +156,20 @@ class g2_import_Core {
$admin = g2(GalleryCoreApi::loadEntitiesById($admin_id));
$GLOBALS["gallery"]->setActiveUser($admin);
+ // Make sure we have an embed location so that embedded url generation comes out ok. Without
+ // this, the Gallery2 ModRewrite code won't try to do url generation.
+ $g2_embed_location =
+ g2(GalleryCoreApi::getPluginParameter("module", "rewrite", "modrewrite.embeddedLocation"));
+
+ if (empty($g2_embed_location)) {
+ $g2_embed_location =
+ g2(GalleryCoreApi::getPluginParameter("module", "rewrite", "modrewrite.galleryLocation"));
+ g2(GalleryCoreApi::setPluginParameter(
+ "module", "rewrite", "modrewrite.embeddedLocation", $g2_embed_location));
+ g2($gallery->getStorage()->checkPoint());
+ }
+ self::$g2_base_url = $g2_embed_location;
+
return true;
}
@@ -254,7 +269,7 @@ class g2_import_Core {
}
if (isset($group)) {
- self::set_map($g2_group->getId(), $group->id);
+ self::set_map($g2_group->getId(), $group->id, "group");
}
return $message;
@@ -270,7 +285,7 @@ class g2_import_Core {
}
if (g2(GalleryCoreApi::isAnonymousUser($g2_user_id))) {
- self::set_map($g2_user_id, identity::guest()->id);
+ self::set_map($g2_user_id, identity::guest()->id, "group");
return t("Skipping anonymous user");
}
@@ -308,7 +323,7 @@ class g2_import_Core {
}
$user->save();
- self::set_map($g2_user->getId(), $user->id);
+ self::set_map($g2_user->getId(), $user->id, "user");
return $message;
}
@@ -376,9 +391,11 @@ class g2_import_Core {
$album->save();
self::import_keywords_as_tags($g2_album->getKeywords(), $album);
- self::set_map($g2_album_id, $album->id);
- // @todo import album highlights
+ self::set_map(
+ $g2_album_id, $album->id,
+ "album",
+ self::g2_url(array("view" => "core.ShowItem", "itemId" => $g2_album->getId())));
}
/**
@@ -458,7 +475,7 @@ 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");
+ 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));
$g2_path = MODPATH . "g2_import/data/broken-image.gif";
@@ -473,7 +490,7 @@ class g2_import_Core {
self::_decode_html_special_chars(self::extract_description($g2_item)),
self::map($g2_item->getOwnerId()));
} catch (Exception $e) {
- Kohana::log(
+ Kohana_Log::add(
"alert", "Corrupt image $g2_path\n" . $e->__toString());
$message[] = t("Corrupt image '%path'", array("path" => $g2_path));
$message[] = $e->__toString();
@@ -493,13 +510,13 @@ class g2_import_Core {
self::_decode_html_special_chars(self::extract_description($g2_item)),
self::map($g2_item->getOwnerId()));
} catch (Exception $e) {
- Kohana::log("alert", "Corrupt movie $g2_path\n" . $e->__toString());
+ Kohana_Log::add("alert", "Corrupt movie $g2_path\n" . $e->__toString());
$message[] = t("Corrupt movie '%path'", array("path" => $g2_path));
$message[] = $e->__toString();
$corrupt = 1;
}
} else {
- Kohana::log("alert", "$g2_path is an unsupported movie type");
+ Kohana_Log::add("alert", "$g2_path is an unsupported movie type");
$message[] = t("'%path' is an unsupported movie type", array("path" => $g2_path));
$corrupt = 1;
}
@@ -515,19 +532,30 @@ class g2_import_Core {
self::import_keywords_as_tags($g2_item->getKeywords(), $item);
}
+ $g2_item_url = self::g2_url(array("view" => "core.ShowItem", "itemId" => $g2_item->getId()));
if (isset($item)) {
- self::set_map($g2_item_id, $item->id);
$item->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_item_id));
$item->save();
+
+ self::set_map($g2_item_id, $item->id, "item", $g2_item_url);
+ $derivatives = g2(GalleryCoreApi::fetchDerivativesByItemIds(array($g2_item_id)));
+ if (!empty($derivatives[$g2_item_id])) {
+ foreach ($derivatives[$g2_item_id] as $derivative) {
+ switch ($derivative->getDerivativeType()) {
+ case DERIVATIVE_TYPE_IMAGE_THUMBNAIL: $resource_type = "thumbnail"; break;
+ case DERIVATIVE_TYPE_IMAGE_RESIZE: $resource_type = "resize"; break;
+ case DERIVATIVE_TYPE_IMAGE_PREFERRED: $resource_type = "full"; break;
+ }
+
+ self::set_map(
+ $derivative->getId(), $item->id,
+ $resource_type,
+ self::g2_url(array("view" => "core.DownloadItem", "itemId" => $derivative->getId())));
+ }
+ }
}
if ($corrupt) {
- $url_generator = $GLOBALS["gallery"]->getUrlGenerator();
- // @todo we need a more persistent warning
- $g2_item_url = $url_generator->generateUrl(array("itemId" => $g2_item->getId()));
- // Why oh why did I ever approve the session id placeholder idea in G2?
- $g2_item_url =
- str_replace('&amp;g2_GALLERYSID=TMP_SESSION_ID_DI_NOISSES_PMT', '', $g2_item_url);
if (!empty($item)) {
$message[] =
t("<a href=\"%g2_url\">%title</a> from Gallery 2 could not be processed; " .
@@ -611,11 +639,9 @@ class g2_import_Core {
array("id" => $g2_item_id, "exception" => $e->__toString()));
}
- $tags = "";
// Multiword tags have the space changed to dots.s
foreach ($tag_names as $tag_name) {
- $tags .= (strlen($tags) ? ", " : "") .
- tag::add($g3_item, $tag_name);
+ tag::add($g3_item, $tag_name);
}
// Tag operations are idempotent so we don't need to map them. Which is good because we don't
@@ -634,11 +660,10 @@ class g2_import_Core {
$delim = " ";
}
- $tags = "";
foreach (preg_split("/$delim/", $keywords) as $keyword) {
$keyword = trim($keyword);
if ($keyword) {
- $tags .= (strlen($tags) ? ", " : "") . tag::add($item, $keyword);
+ tag::add($item, $keyword);
}
}
}
@@ -867,8 +892,8 @@ class g2_import_Core {
*/
static function map($g2_id) {
if (!array_key_exists($g2_id, self::$map)) {
- $g2_map = ORM::factory("g2_map")->where("g2_id", $g2_id)->find();
- self::$map[$g2_id] = $g2_map->loaded ? $g2_map->g3_id : null;
+ $g2_map = ORM::factory("g2_map")->where("g2_id", "=", $g2_id)->find();
+ self::$map[$g2_id] = $g2_map->loaded() ? $g2_map->g3_id : null;
}
return self::$map[$g2_id];
@@ -877,17 +902,30 @@ class g2_import_Core {
/**
* Associate a Gallery 2 id with a Gallery 3 item id.
*/
- static function set_map($g2_id, $g3_id) {
+ static function set_map($g2_id, $g3_id, $resource_type, $g2_url=null) {
$g2_map = ORM::factory("g2_map");
$g2_map->g3_id = $g3_id;
$g2_map->g2_id = $g2_id;
+ $g2_map->resource_type = $resource_type;
+ $g2_map->g2_url = $g2_url;
$g2_map->save();
self::$map[$g2_id] = $g3_id;
}
static function log($msg) {
message::warning($msg);
- Kohana::log("alert", $msg);
+ Kohana_Log::add("alert", $msg);
+ }
+
+ static function g2_url($params) {
+ global $gallery;
+ $url = $gallery->getUrlGenerator()->generateUrl(
+ $params,
+ array("forceSessionId" => false,
+ "htmlEntities" => false,
+ "urlEncode" => false,
+ "useAuthToken" => false));
+ return str_replace(self::$g2_base_url, "", $url);
}
}
@@ -904,9 +942,9 @@ class g2_import_Core {
*/
function g2() {
$args = func_get_arg(0);
- $ret = array_shift($args);
+ $ret = is_array($args) ? array_shift($args) : $args;
if ($ret) {
- Kohana::log("error", "Gallery 2 call failed with: " . $ret->getAsText());
+ Kohana_Log::add("error", "Gallery 2 call failed with: " . $ret->getAsText());
throw new Exception("@todo G2_FUNCTION_FAILED");
}
if (count($args) == 1) {
diff --git a/modules/g2_import/helpers/g2_import_event.php b/modules/g2_import/helpers/g2_import_event.php
index 609e1a45..02a2126d 100644
--- a/modules/g2_import/helpers/g2_import_event.php
+++ b/modules/g2_import/helpers/g2_import_event.php
@@ -19,7 +19,10 @@
*/
class g2_import_event_Core {
static function item_deleted($item) {
- Database::instance()->delete("g2_maps", array("g3_id" => $item->id));
+ db::build()
+ ->delete("g2_maps")
+ ->where("g3_id", "=", $item->id)
+ ->execute();
}
static function item_created($item) {
diff --git a/modules/g2_import/helpers/g2_import_installer.php b/modules/g2_import/helpers/g2_import_installer.php
index feacb518..77b61d3e 100644
--- a/modules/g2_import/helpers/g2_import_installer.php
+++ b/modules/g2_import/helpers/g2_import_installer.php
@@ -24,14 +24,27 @@ class g2_import_installer {
`id` int(9) NOT NULL auto_increment,
`g2_id` int(9) NOT NULL,
`g3_id` int(9) NOT NULL,
+ `g2_url` varchar(255) default NULL,
+ `resource_type` varchar(64) default NULL,
PRIMARY KEY (`id`),
- KEY (`g2_id`))
+ KEY `g2_url` (`g2_url`),
+ KEY `g2_id` (`g2_id`))
DEFAULT CHARSET=utf8;");
module::set_version("g2_import", 1);
mkdir(VARPATH . "modules/g2_import");
}
+ static function upgrade($version) {
+ $db = Database::instance();
+ if ($version == 1) {
+ $db->query("ALTER TABLE {g2_maps} ADD COLUMN `g2_url` VARCHAR(255)");
+ $db->query("ALTER TABLE {g2_maps} ADD COLUMN `resource_type` VARCHAR(64)");
+ $db->query("ALTER TABLE {g2_maps} ADD KEY `g2_url` (`g2_url`)");
+ module::set_version("g2_import", $version = 2);
+ }
+ }
+
static function uninstall() {
@dir::unlink(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 47a205bd..e80b88b9 100644
--- a/modules/g2_import/helpers/g2_import_task.php
+++ b/modules/g2_import/helpers/g2_import_task.php
@@ -65,8 +65,8 @@ class g2_import_task_Core {
$task->set("done", $done);
$root_g2_id = g2(GalleryCoreApi::getDefaultAlbumId());
- $root = ORM::factory("g2_map")->where("g2_id", $root_g2_id)->find();
- if (!$root->loaded) {
+ $root = ORM::factory("g2_map")->where("g2_id", "=", $root_g2_id)->find();
+ if (!$root->loaded()) {
$root->g2_id = $root_g2_id;
$root->g3_id = 1;
$root->save();
diff --git a/modules/g2_import/module.info b/modules/g2_import/module.info
index 554cf33b..977af251 100644
--- a/modules/g2_import/module.info
+++ b/modules/g2_import/module.info
@@ -1,3 +1,3 @@
name = "Gallery2 Import"
description = "Import your Gallery 2 content into Gallery 3"
-version = 1
+version = 2
diff --git a/modules/g2_import/views/admin_g2_import.html.php b/modules/g2_import/views/admin_g2_import.html.php
index 9a5e3f05..0875e7f7 100644
--- a/modules/g2_import/views/admin_g2_import.html.php
+++ b/modules/g2_import/views/admin_g2_import.html.php
@@ -16,16 +16,17 @@
<?= t("Permissions are <b>not imported</b>. You will have to set them again manually (for now).") ?>
</li>
<li>
- <?= t("The only supported image formats are JPG, PNG and GIF. Other formats will be skipped.") ?>
+ <?= t("The only supported file formats are JPG, PNG and GIF, FLV and MP4. Other formats will be skipped.") ?>
</li>
<li>
- <?= t("The only supported movie formats are FLV and MP4. Other formats will be skipped.") ?>
+ <?= t("Deactivating the <b>notification</b>, <b>search</b> and <b>exif</b> modules during your import will make it go faster.") ?>
</li>
<li>
<?= 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>
</ul>
</div>
+
<?= $form ?>
<? if (g2_import::is_initialized()): ?>
@@ -91,6 +92,21 @@
</a>
</p>
</div>
+
+ <div>
+ <h2> <?= t("Migrating from Gallery 2") ?> </h2>
+ <p>
+ <?= t("Once your migration is complete, put this block at the top of your gallery2/.htaccess file and all Gallery 2 urls will be redirected to Gallery 3") ?>
+ </p>
+
+ <code>
+ &lt;IfModule mod_rewrite.c&gt;<br/>
+ RewriteEngine On<br/>
+ RewriteBase <?= html::clean(g2_import::$g2_base_url) ?><br/>
+ RewriteRule ^(.*)$ <?= url::site("g2/map?path=\$1") ?> [QSA,L]<br/>
+ &lt;/IfModule&gt;<br/>
+ </code>
+ </div>
<? endif ?>
</div>
</div>