summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-05-19 03:54:33 +0000
committerBharat Mediratta <bharat@menalto.com>2009-05-19 03:54:33 +0000
commitad347c04568bc281db9ccb89234c0967961e08dd (patch)
treef5b6136075212406f7ea0925f6886567972eb417
parent762ca225443626b69c94f6d6c833f66de69b2ce1 (diff)
If there's a missing source image during import, swap in our "broken
image" placeholder and keep on trucking. Oh, and notify the admin. Fixes ticket #287
-rwxr-xr-xmodules/g2_import/data/broken-image.gifbin0 -> 1589 bytes
-rw-r--r--modules/g2_import/helpers/g2_import.php39
2 files changed, 36 insertions, 3 deletions
diff --git a/modules/g2_import/data/broken-image.gif b/modules/g2_import/data/broken-image.gif
new file mode 100755
index 00000000..fb9c8240
--- /dev/null
+++ b/modules/g2_import/data/broken-image.gif
Binary files differ
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php
index 65710de3..03c125ed 100644
--- a/modules/g2_import/helpers/g2_import.php
+++ b/modules/g2_import/helpers/g2_import.php
@@ -284,11 +284,30 @@ class g2_import_Core {
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()) {
+
+ $g2_path = g2($g2_item->fetchPath());
+ $g2_type = $g2_item->getEntityType();
+ $corrupt = 0;
+ if (!file_exists($g2_path)) {
+ // If the Gallery2 source image isn't available, this operation is going to fail. That can
+ // happen in cases where there's corruption in the source Gallery 2. In that case, fall
+ // back on using a broken image. It's important that we import *something* otherwise
+ // anything that refers to this item in Gallery 2 will have a dangling pointer in Gallery 3
+ //
+ // 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_path = MODPATH . "g2_import/data/broken-image.gif";
+ $g2_type = "GalleryPhotoItem";
+ $corrupt = 1;
+ }
+
+ switch ($g2_type) {
case "GalleryPhotoItem":
$item = photo::create(
$parent,
- g2($g2_item->fetchPath()),
+ $g2_path,
$g2_item->getPathComponent(),
$g2_item->getTitle(),
self::extract_description($g2_item),
@@ -300,7 +319,7 @@ class g2_import_Core {
if (in_array($g2_item->getMimeType(), array("video/mp4", "video/x-flv"))) {
$item = movie::create(
$parent,
- g2($g2_item->fetchPath()),
+ $g2_path,
$g2_item->getPathComponent(),
$g2_item->getTitle(),
self::extract_description($g2_item),
@@ -321,6 +340,20 @@ class g2_import_Core {
self::set_map($g2_item_id, $item->id);
}
+ if ($corrupt) {
+ $url_generator = $GLOBALS["gallery"]->getUrlGenerator();
+ // @todo we need a more persistent
+ $warning =
+ t("<a href=\"%g2_url\">%title</a> corrupt in Gallery 2; " .
+ "(imported as <a href=\"%g3_url\">%title</a>)",
+ array("g2_url" => $url_generator->generateUrl(array("itemId" => $g2_item->getId())),
+ "g3_url" => $item->url(),
+ "title" => $g2_item->getTitle()));
+ message::warning($warning);
+ log::warning("g2_import", $warning);
+ Kohana::log("alert", $warning);
+ }
+
self::$current_g2_item = null;
}