]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Use exception instead of if-statement in File::saveNew
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 27 Sep 2015 10:29:38 +0000 (12:29 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 27 Sep 2015 10:29:38 +0000 (12:29 +0200)
classes/File.php

index 8991616f82e54d825f68c981c0d1ab3071c84743..d31141cf8eca9e3e55431687b7ee88ea5e54c9df 100644 (file)
@@ -82,14 +82,15 @@ class File extends Managed_DataObject
      * @param string $given_url
      * @return File
      */
-    public static function saveNew(array $redir_data, $given_url) {
-
-        // I don't know why we have to keep doing this but I'm adding this last check to avoid
-        // uniqueness bugs.
+    public static function saveNew(array $redir_data, $given_url)
+    {
+        $file = null;
 
-        $file = File::getKV('urlhash', self::hashurl($given_url));
-        
-        if (!$file instanceof File) {
+        try {
+            // I don't know why we have to keep doing this but we run a last check to avoid
+            // uniqueness bugs.
+            $file = File::getByUrl($given_url);
+        } catch (NoResultException $e) {
             $file = new File;
             $file->urlhash = self::hashurl($given_url);
             $file->url = $given_url;