From 11e8b8b2e6e5e384129aeacfa494d65b3f1913fc Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Fri, 22 Aug 2014 22:14:50 +0200 Subject: [PATCH] Moved check for duplicates into its own function --- php/modules/Photo.php | 47 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/php/modules/Photo.php b/php/modules/Photo.php index adc2fc4..4089ac0 100755 --- a/php/modules/Photo.php +++ b/php/modules/Photo.php @@ -112,17 +112,13 @@ class Photo extends Module { } else { - $query = "SELECT id, url, thumbUrl FROM lychee_photos WHERE checksum = '$checksum' LIMIT 1;"; - $result = $this->database->query($query); - - if ($result->num_rows===1) { - $result = $result->fetch_assoc(); - $photo_name = $result['url']; - $path = LYCHEE_UPLOADS_BIG . $result['url']; - $path_thumb = $result['thumbUrl']; + $exists = $this->exists($checksum); + + if ($exists!==false) { + $photo_name = $exists['photo_name']; + $path = $exists['path']; + $path_thumb = $exists['path_thumb']; $exists = true; - } else { - $exists = false; } } @@ -214,6 +210,37 @@ class Photo extends Module { } + private function exists($checksum) { + + # Check dependencies + self::dependencies(isset($this->database, $checksum)); + + $query = "SELECT id, url, thumbUrl FROM lychee_photos WHERE checksum = '$checksum' LIMIT 1;"; + $result = $this->database->query($query); + + if (!$result) { + Log::error($this->database, __METHOD__, __LINE__, 'Could not check for existing photos with the same checksum'); + return false; + } + + if ($result->num_rows===1) { + + $result = $result->fetch_assoc(); + + $return = array( + 'photo_name' => $result['url'], + 'path' => LYCHEE_UPLOADS_BIG . $result['url'], + 'path_thumb' => $result['thumbUrl'], + ); + + return $return; + + } + + return false; + + } + private function createThumb($url, $filename, $width = 200, $height = 200) { # Check dependencies