Hi!
I helped a friend with his recent Gallery 2 installation. He migrated from Gallery1, and some thumbnails did not show up. I hope I'm now posting to the right forum.
I debugged this and traced it down to the getPseudoFileName function, that returned "unknown" for many images when being called with a URL like main.php?g2_view=core.DownloadItem&g2_itemId=607&g2_serialNumber=11&g2_fileName=MyFilename.jpg
I found out that the $entity that is passed to the function was an object "GalleryDerivateiveImage", whose parent is not a GalleryfielSystemEntity but a GalleryPhotoItem. This made me change the function to this code:
function getPseudoFileName($entity) {
/*
* If our GalleryEntity is a GalleryFileSystemEntity, then we've got a
* path component so we're cool. If it's a derivative, then get the
* pseudo filename of its parent and use that instead (but make sure
* the extension matches derivative, as parent mime type may differ).
* If it's neither, then return 'unknown' for now.
*/
if (GalleryUtilities::isA($entity, 'GalleryFileSystemEntity')) {
$pseudoFileName = $entity->getPathComponent();
} else if (GalleryUtilities::isA($entity, 'GalleryDerivative') || GalleryUtilities::isA($entity, 'GalleryDerivativeImage')) { // Garvin Patch
list ($ret, $parentEntity) = GalleryCoreApi::loadEntitiesById($entity->getParentId());
if ($ret) {
return array($ret->wrap(__FILE__, __LINE__), null);
}
if (GalleryUtilities::isA($parentEntity, 'GalleryFileSystemEntity') || GalleryUtilities::isA($parentEntity, 'GalleryPhotoItem')) { // Garvin Patch
$pseudoFileName = $parentEntity->getPathComponent();
if (!method_exists($parentEntity, 'getMimeType') ||
$parentEntity->getMimeType() != $entity->getMimeType()) {
list ($ret, $extensions) =
GalleryCoreApi::convertMimeToExtensions($entity->getMimeType());
if ($ret) {
return array($ret->wrap(__FILE__, __LINE__), null);
}
if (!empty($extensions)) {
if (method_exists($parentEntity, 'getMimeType')) {
/* Change extension for mime type of this derivative */
$pseudoFileName =
preg_replace('{\.[^.]+$}', '.' . $extensions[0], $pseudoFileName);
} else {
/* Non-item parent, like an album.. add extension for this mime type */
$pseudoFileName .= '.' . $extensions[0];
}
}
}
}
}
return array(null,
isset($pseudoFileName) ? $pseudoFileName : 'unknown');
}
Of course I wonder if this is intentional? I guess it's a problem with the migration, maybe? Since I know next to nothing of Gallery's internals, I don't know what this "GalleryDerivativeImage" comes from...
Best regards,
Garvin
--
http://garv.in/