summaryrefslogtreecommitdiff
path: root/modules/g2_import/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/g2_import/helpers')
-rw-r--r--modules/g2_import/helpers/g2_import.php89
-rw-r--r--modules/g2_import/helpers/g2_import_installer.php21
-rw-r--r--modules/g2_import/helpers/g2_import_task.php8
3 files changed, 85 insertions, 33 deletions
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) {