From ba852f8a038dd5a18c4d733bf06c7b774802fd66 Mon Sep 17 00:00:00 2001 From: pyro2927 Date: Wed, 2 Jul 2014 14:29:34 -0500 Subject: [PATCH] Adding in photo checksum to detect dupes --- php/database/update_020500.php | 9 +++++++++ php/modules/Photo.php | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/php/database/update_020500.php b/php/database/update_020500.php index 7f4af25..d16e41f 100644 --- a/php/database/update_020500.php +++ b/php/database/update_020500.php @@ -116,6 +116,15 @@ if (!$result) { return false; } +# Add `checksum` +if (!$database->query("SELECT `checksum` FROM `lychee_photos` LIMIT 1;")) { + $result = $database->query("ALTER TABLE `lychee_photos` ADD `checksum` VARCHAR(100) DEFAULT NULL"); + if (!$result) { + Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')'); + return false; + } +} + # Reset sorting $result = $database->query("UPDATE lychee_settings SET value = 'ORDER BY takestamp DESC' WHERE `key` = 'sorting' AND `value` LIKE '%UNIX_TIMESTAMP%';"); if (!$result) { diff --git a/php/modules/Photo.php b/php/modules/Photo.php index 790d256..860dd0a 100755 --- a/php/modules/Photo.php +++ b/php/modules/Photo.php @@ -130,7 +130,7 @@ class Photo extends Module { } # Save to DB - $query = "INSERT INTO lychee_photos (id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star) + $query = "INSERT INTO lychee_photos (id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star, checksum) VALUES ( '" . $id . "', '" . $info['title'] . "', @@ -151,7 +151,8 @@ class Photo extends Module { '" . md5($id) . ".jpeg', '" . $albumID . "', '" . $public . "', - '" . $star . "');"; + '" . $star . "', + '" . md5_file($path) . "');"; $result = $this->database->query($query); if (!$result) {