]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Never save our /attachment/{file_id} links as links in the file table, return the...
authorhannes <h@nnesmannerhe.im>
Fri, 29 Jan 2016 00:36:30 +0000 (00:36 +0000)
committerhannes <h@nnesmannerhe.im>
Fri, 29 Jan 2016 00:36:30 +0000 (00:36 +0000)
classes/File.php

index 6cad978a703cadaf66670014cea1cd6b05adccd8..428eb9f2855f3687d95e4c9118efa82f89415813 100644 (file)
@@ -106,6 +106,19 @@ class File extends Managed_DataObject
             // We don't have the file's URL since before, so let's continue.
         }
 
+        // if the given url is an local attachment url and the id already exists, don't
+        // save a new file record. This should never happen, but let's make it foolproof
+        $attachment_path = common_path('attachment/');
+        if(strpos($given_url,$attachment_path) == 0) {
+            $possible_file_id = substr($given_url,strlen($attachment_path));
+            if(is_numeric($possible_file_id)) {
+                $file = File::getKV('id',$possible_file_id);
+                if($file instanceof File) {
+                    return $file;
+                }
+            }
+        }
+
         $file = new File;
         $file->url = $given_url;
         if (!empty($redir_data['protected'])) $file->protected = $redir_data['protected'];