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 {
|
} else {
|
||||||
|
|
||||||
$query = "SELECT id, url, thumbUrl FROM lychee_photos WHERE checksum = '$checksum' LIMIT 1;";
|
$exists = $this->exists($checksum);
|
||||||
$result = $this->database->query($query);
|
|
||||||
|
|
||||||
if ($result->num_rows===1) {
|
if ($exists!==false) {
|
||||||
$result = $result->fetch_assoc();
|
$photo_name = $exists['photo_name'];
|
||||||
$photo_name = $result['url'];
|
$path = $exists['path'];
|
||||||
$path = LYCHEE_UPLOADS_BIG . $result['url'];
|
$path_thumb = $exists['path_thumb'];
|
||||||
$path_thumb = $result['thumbUrl'];
|
|
||||||
$exists = true;
|
$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) {
|
private function createThumb($url, $filename, $width = 200, $height = 200) {
|
||||||
|
|
||||||
# Check dependencies
|
# Check dependencies
|
||||||
|
Loading…
Reference in New Issue
Block a user