Moved check for duplicates into its own function

pull/221/head
Tobias Reich 10 years ago
parent e942c9c525
commit 11e8b8b2e6

@ -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

Loading…
Cancel
Save