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);
} 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);
}
}
}

View File

@ -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;

View File

@ -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());
}
}