Browse Source

Added update for database for version 2.6.2

Tobias Reich 9 years ago
parent
commit
8b4ef96146
3 changed files with 42 additions and 1 deletions
  1. 36 0
      php/database/update_020602.php
  2. 2 1
      php/modules/Database.php
  3. 4 0
      php/modules/Photo.php

+ 36 - 0
php/database/update_020602.php

@@ -0,0 +1,36 @@
+<?php
+
+###
+# @name			Update to version 2.6.2
+# @author		Tobias Reich
+# @copyright	2014 by Tobias Reich
+###
+
+# Add a checksum
+$result = $database->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;
+}
+
+?>

+ 2 - 1
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

+ 4 - 0
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) {