aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorMikael Nordfeldth <mmn@hethane.se>2016-02-10 04:37:43 +0100
committerMikael Nordfeldth <mmn@hethane.se>2016-02-10 04:37:43 +0100
commitdd229e855ae2197ca86d19c6838c578efc5df1d7 (patch)
tree3f1f117421d9bc0a0372db73fc0ab4609f218825 /classes
parent893d8881522c1402e86af255545739482625d341 (diff)
downloadgnu-social-dd229e855ae2197ca86d19c6838c578efc5df1d7.tar
gnu-social-dd229e855ae2197ca86d19c6838c578efc5df1d7.zip
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(...)
Diffstat (limited to 'classes')
-rw-r--r--classes/File_thumbnail.php21
1 files 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');
+ }
+ $thumb->limit(1);
+ if (!$thumb->find(true)) {
+ throw new NoResultException($thumb);
}
- return $file_thumbnail;
+ return $thumb;
}
/**