Allow finding the "original remote thumbnail"

This will probably cause older oEmbed images not to show, since they
probably were updated to use empty url entries because they were thought
of as local ones. During a migration period maybe you want to change
the default value of notNullUrl to 'false' in File_thumbnail::byFile(...)
This commit is contained in:
Mikael Nordfeldth 2016-02-10 04:37:43 +01:00
parent 893d888152
commit dd229e855a

View File

@ -85,13 +85,24 @@ class File_thumbnail extends Managed_DataObject
/** /**
* Fetch an entry by using a File's id * Fetch an entry by using a File's id
*
* @param File $file The File object we're getting a thumbnail for.
* @param boolean $notNullUrl Originally remote thumbnails have a URL stored, we use this to find the "original"
*
* @return File_thumbnail
* @throws NoResultException if no File_thumbnail matched the criteria
*/ */
static function byFile(File $file) { static function byFile(File $file, $notNullUrl=true) {
$file_thumbnail = self::getKV('file_id', $file->getID()); $thumb = new File_thumbnail();
if (!$file_thumbnail instanceof File_thumbnail) { $thumb->file_id = $file->getID();
throw new ServerException(sprintf('No File_thumbnail entry for File id==%u', $file->getID())); if ($notNullUrl) {
$thumb->whereAdd('url IS NOT NULL');
} }
return $file_thumbnail; $thumb->limit(1);
if (!$thumb->find(true)) {
throw new NoResultException($thumb);
}
return $thumb;
} }
/** /**