]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newnotice.php
MediaFile upload simplifying
[quix0rs-gnu-social.git] / actions / newnotice.php
index ca770f38b67a4a418e0d0f70de2646684640dbed..d1e47fec5c095b994240f870d296be01303a7caf 100644 (file)
@@ -129,10 +129,10 @@ class NewnoticeAction extends FormAction
             $options['reply_to'] = $replyto;
         }
 
-        $upload = MediaFile::fromUpload('attach', $this->scoped);
-
-        if (isset($upload)) {
-
+        $upload = null;
+        try {
+            // throws exception on failure
+            $upload = MediaFile::fromUpload('attach', $this->scoped);
             if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options))) {
                 $content_shortened .= ' ' . $upload->shortUrl();
             }
@@ -147,8 +147,11 @@ class NewnoticeAction extends FormAction
                                               Notice::maxContent()),
                                            Notice::maxContent()));
             }
+        } catch (NoUploadedMediaException $e) {
+            // simply no attached media to the new notice
         }
 
+
         if ($this->scoped->shareLocation()) {
             // use browser data if checked; otherwise profile data
             if ($this->arg('notice_data-geo')) {
@@ -179,7 +182,7 @@ class NewnoticeAction extends FormAction
 
             $this->stored = Notice::saveNew($this->scoped->id, $content_shortened, 'web', $options);
 
-            if (isset($upload)) {
+            if ($upload instanceof MediaFile) {
                 $upload->attachToNotice($this->stored);
             }