diff --git a/classes/File.php b/classes/File.php index 46d4d5498d..4489b4ecc1 100644 --- a/classes/File.php +++ b/classes/File.php @@ -498,7 +498,7 @@ class File extends Managed_DataObject return File_thumbnail::byFile($this); } catch (NoResultException $e) { // and if it's not a remote file, it'll be safe to use the locally stored File - throw new UseFileAsThumbnailException($this->id); + throw new UseFileAsThumbnailException($this); } } } diff --git a/lib/imagefile.php b/lib/imagefile.php index 85fc597126..156e3c6fd2 100644 --- a/lib/imagefile.php +++ b/lib/imagefile.php @@ -132,7 +132,7 @@ class ImageFile // First some mimetype specific exceptions switch ($file->mimetype) { case 'image/svg+xml': - throw new UseFileAsThumbnailException($file->id); + throw new UseFileAsThumbnailException($file); } // And we'll only consider it an image if it has such a media type @@ -282,7 +282,11 @@ class ImageFile } if (!file_exists($outpath)) { - throw new UseFileAsThumbnailException($this->id); + if ($this->fileRecord instanceof File) { + throw new UseFileAsThumbnailException($this->fileRecord); + } else { + throw new UnsupportedMediaException('No local File object exists for ImageFile.'); + } } return $outpath; diff --git a/lib/usefileasthumbnailexception.php b/lib/usefileasthumbnailexception.php index cafbe692b2..5ad33cb0a9 100644 --- a/lib/usefileasthumbnailexception.php +++ b/lib/usefileasthumbnailexception.php @@ -34,13 +34,9 @@ class UseFileAsThumbnailException extends UnsupportedMediaException { public $file = null; - public function __construct($file_id) + public function __construct(File $file) { - $this->file = File::getKV('id', $file_id); - if (!$this->file instanceof File) { - throw new ServerException('No File ID supplied to exception'); - } - + $this->file = $file; parent::__construct('Thumbnail not generated', $this->file->getPath()); } }