From dd229e855ae2197ca86d19c6838c578efc5df1d7 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 10 Feb 2016 04:37:43 +0100 Subject: [PATCH] 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(...) --- classes/File_thumbnail.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/classes/File_thumbnail.php b/classes/File_thumbnail.php index 6874528a7a..e028409f0f 100644 --- a/classes/File_thumbnail.php +++ b/classes/File_thumbnail.php @@ -85,13 +85,24 @@ class File_thumbnail extends Managed_DataObject /** * 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) { - $file_thumbnail = self::getKV('file_id', $file->getID()); - if (!$file_thumbnail instanceof File_thumbnail) { - throw new ServerException(sprintf('No File_thumbnail entry for File id==%u', $file->getID())); + static function byFile(File $file, $notNullUrl=true) { + $thumb = new File_thumbnail(); + $thumb->file_id = $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; } /**