]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/File_redirection.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / classes / File_redirection.php
index bb8ffc8c61301d3cf281382d719406354bf0dd81..bc405311fef63365ff2132cc04bf271f4ef3895e 100644 (file)
@@ -196,11 +196,11 @@ class File_redirection extends Managed_DataObject
             $redir->httpcode = $redir_info['code'];
             $redir->redirections = intval($redir_info['redirects']);
             $redir->file = new File();
-            $redir->file->url = $redir_info ? $redir_info['url'] : $in_url;
+            $redir->file->url = $redir_info['url'];
             $redir->file->mimetype = $redir_info['type'];
-            $redir->file->size = $redir_info['size'];
-            $redir->file->date = $redir_info['time'];
-            if ($redir_info['protected']) {
+            $redir->file->size = isset($redir_info['size']) ? $redir_info['size'] : null;
+            $redir->file->date = isset($redir_info['time']) ? $redir_info['time'] : null;
+            if (isset($redir_info['protected']) && !empty($redir_info['protected'])) {
                 $redir->file->protected = true;
             }
         }
@@ -262,8 +262,9 @@ class File_redirection extends Managed_DataObject
         if (!empty($short_url) && $short_url != $long_url) {
             $short_url = (string)$short_url;
             // store it
-            $file = File::getKV('url', $long_url);
-            if (!$file instanceof File) {
+            try {
+                $file = File::getByUrl($long_url);
+            } catch (NoResultException $e) {
                 // Check if the target URL is itself a redirect...
                 $redir = File_redirection::where($long_url);
                 $file = $redir->getFile();
@@ -271,12 +272,14 @@ class File_redirection extends Managed_DataObject
                     $file->saveFile();
                 }
             }
-            $file_redir = File_redirection::getKV('url', $short_url);
-            if (!$file_redir instanceof File_redirection) {
-                $file_redir = new File_redirection;
+            // Now we definitely have a File object in $file
+            try {
+                $file_redir = File_redirection::getByUrl($short_url);
+            } catch (NoResultException $e) {
+                $file_redir = new File_redirection();
                 $file_redir->urlhash = File::hashurl($short_url);
                 $file_redir->url = $short_url;
-                $file_redir->file_id = $file->id;
+                $file_redir->file_id = $file->getID();
                 $file_redir->insert();
             }
             return $short_url;
@@ -334,7 +337,7 @@ class File_redirection extends Managed_DataObject
         return $out_url;
     }
 
-    static function saveNew($data, $file_id, $url) {
+    static function saveNew(array $data, $file_id, $url) {
         $file_redir = new File_redirection;
         $file_redir->urlhash = File::hashurl($url);
         $file_redir->url = $url;