]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/mediafile.php
No more needed (for this fix) but maybe later. So I always only comment them out.
[quix0rs-gnu-social.git] / lib / mediafile.php
index 6f456fca4f15000af3918906fe020228aa205920..3bbbd162f0c18985d7cfc6238ab2b2d39854d8a5 100644 (file)
@@ -61,8 +61,6 @@ class MediaFile
     public function attachToNotice(Notice $notice)
     {
         File_to_post::processNew($this->fileRecord->id, $notice->id);
-        $this->maybeAddRedir($this->fileRecord->id,
-                             common_local_url('file', array('notice' => $notice->id)));
     }
 
     public function getPath()
@@ -81,6 +79,15 @@ class MediaFile
         @unlink($filepath);
     }
 
+    public function getFile()
+    {
+        if (!$this->fileRecord instanceof File) {
+            throw new ServerException('File record did not exist for MediaFile');
+        }
+
+        return $this->fileRecord;
+    }
+
     protected function storeFile()
     {
 
@@ -134,15 +141,14 @@ class MediaFile
     {
         $file_redir = File_redirection::getKV('url', $url);
 
-        if (empty($file_redir)) {
-
+        if (!$file_redir instanceof File_redirection) {
             $file_redir = new File_redirection;
             $file_redir->url = $url;
             $file_redir->file_id = $file_id;
 
             $result = $file_redir->insert();
 
-            if (!$result) {
+            if ($result===false) {
                 common_log_db_error($file_redir, "INSERT", __FILE__);
                 // TRANS: Client exception thrown when a database error was thrown during a file upload operation.
                 throw new ClientException(_('There was a database error while saving your file. Please try again.'));
@@ -150,14 +156,15 @@ class MediaFile
         }
     }
 
-    static function fromUpload($param = 'media', Profile $scoped)
+    static function fromUpload($param='media', Profile $scoped=null)
     {
         if (is_null($scoped)) {
             $scoped = Profile::current();
         }
 
-        if (!isset($_FILES[$param]['error'])){
-            return;
+        // The existence of the "error" element means PHP has processed it properly even if it was ok.
+        if (!isset($_FILES[$param]) || !isset($_FILES[$param]['error'])) {
+            throw new NoUploadedMediaException($param);
         }
 
         switch ($_FILES[$param]['error']) {
@@ -179,7 +186,7 @@ class MediaFile
                             ' partially uploaded.'));
             case UPLOAD_ERR_NO_FILE:
                 // No file; probably just a non-AJAX submission.
-                return;
+                throw new NoUploadedMediaException($param);
             case UPLOAD_ERR_NO_TMP_DIR:
                 // TRANS: Client exception thrown when a temporary folder is not present to store a file upload.
                 throw new ClientException(_('Missing a temporary folder.'));