Moved check for duplicates into its own function
This commit is contained in:
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);
|
||||
$exists = $this->exists($checksum);
|
||||
|
||||
if ($result->num_rows===1) {
|
||||
$result = $result->fetch_assoc();
|
||||
$photo_name = $result['url'];
|
||||
$path = LYCHEE_UPLOADS_BIG . $result['url'];
|
||||
$path_thumb = $result['thumbUrl'];
|
||||
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…
Reference in New Issue
Block a user