From edb73ec48009749f4c607c88947f182a02312ad5 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 27 Sep 2015 12:29:38 +0200 Subject: [PATCH] Use exception instead of if-statement in File::saveNew --- classes/File.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/classes/File.php b/classes/File.php index 8991616f82..d31141cf8e 100644 --- a/classes/File.php +++ b/classes/File.php @@ -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; -- 2.39.5