UseFileAsThumbnailException uses direct File object now

This commit is contained in:
Mikael Nordfeldth 2016-05-04 11:34:50 +02:00
parent 60130633f0
commit 87dd0fbdb6
3 changed files with 9 additions and 9 deletions

View File

@ -498,7 +498,7 @@ class File extends Managed_DataObject
return File_thumbnail::byFile($this); return File_thumbnail::byFile($this);
} catch (NoResultException $e) { } catch (NoResultException $e) {
// and if it's not a remote file, it'll be safe to use the locally stored File // 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);
} }
} }
} }

View File

@ -132,7 +132,7 @@ class ImageFile
// First some mimetype specific exceptions // First some mimetype specific exceptions
switch ($file->mimetype) { switch ($file->mimetype) {
case 'image/svg+xml': 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 // 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)) { 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; return $outpath;

View File

@ -34,13 +34,9 @@ class UseFileAsThumbnailException extends UnsupportedMediaException
{ {
public $file = null; public $file = null;
public function __construct($file_id) public function __construct(File $file)
{ {
$this->file = File::getKV('id', $file_id); $this->file = $file;
if (!$this->file instanceof File) {
throw new ServerException('No File ID supplied to exception');
}
parent::__construct('Thumbnail not generated', $this->file->getPath()); parent::__construct('Thumbnail not generated', $this->file->getPath());
} }
} }