From 8b4ef96146dc488a38009b5d1c7c8b440cb6e4ad Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Wed, 27 Aug 2014 21:17:05 +0200 Subject: [PATCH] Added update for database for version 2.6.2 --- php/database/update_020602.php | 36 ++++++++++++++++++++++++++++++++++ php/modules/Database.php | 3 ++- php/modules/Photo.php | 4 ++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 php/database/update_020602.php diff --git a/php/database/update_020602.php b/php/database/update_020602.php new file mode 100644 index 0000000..af1c313 --- /dev/null +++ b/php/database/update_020602.php @@ -0,0 +1,36 @@ +query("SELECT `id`, `url` FROM `lychee_photos` WHERE `checksum` IS NULL;"); +if (!$result) { + Log::error($database, 'update_020602', __LINE__, 'Could not find photos without checksum (' . $database->error . ')'); + return false; +} +while ($photo = $result->fetch_object()) { + $checksum = sha1_file(LYCHEE_UPLOADS_BIG . $photo->url); + if ($checksum!==false) { + $setChecksum = $database->query("UPDATE `lychee_photos` SET `checksum` = '$checksum' WHERE `id` = '$photo->id';"); + if (!$setChecksum) { + Log::error($database, 'update_020602', __LINE__, 'Could not update checksum (' . $database->error . ')'); + return false; + } + } else { + Log::error($database, 'update_020602', __LINE__, 'Could not calculate checksum for photo with id ' . $photo->id); + return false; + } +} + +# Set version +$result = $database->query("UPDATE lychee_settings SET value = '020602' WHERE `key` = 'version';"); +if (!$result) { + Log::error($database, 'update_020602', __LINE__, 'Could not update database (' . $database->error . ')'); + return false; +} + +?> \ No newline at end of file diff --git a/php/modules/Database.php b/php/modules/Database.php index b16a5fa..b20a40b 100755 --- a/php/modules/Database.php +++ b/php/modules/Database.php @@ -48,7 +48,8 @@ class Database extends Module { '020200', #2.2 '020500', #2.5 '020505', #2.5.5 - '020601' #2.6.1 + '020601', #2.6.1 + '020602' #2.6.2 ); # For each update diff --git a/php/modules/Photo.php b/php/modules/Photo.php index a4eb02c..afd7e25 100755 --- a/php/modules/Photo.php +++ b/php/modules/Photo.php @@ -103,6 +103,10 @@ class Photo extends Module { # Calculate checksum $checksum = sha1_file($tmp_name); + if ($checksum===false) { + Log::error($this->database, __METHOD__, __LINE__, 'Could not calculate checksum for photo'); + exit('Error: Could not calculate checksum for photo!'); + } # Check if image exists based on checksum if ($checksum===false) {