From: Mikael Nordfeldth Date: Sun, 27 Dec 2015 20:36:23 +0000 (+0100) Subject: File_redirection should get URLs properly X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4bc0b374bc24a9ef53775faf91c653e2a5a31311;p=quix0rs-gnu-social.git File_redirection should get URLs properly --- diff --git a/classes/File_redirection.php b/classes/File_redirection.php index adafab2ec5..a324deaa5d 100644 --- a/classes/File_redirection.php +++ b/classes/File_redirection.php @@ -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;