update_020602.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. ###
  3. # @name Update to version 2.6.2
  4. # @author Tobias Reich
  5. # @copyright 2014 by Tobias Reich
  6. ###
  7. # Add a checksum
  8. $query = Database::prepare($database, "SELECT `id`, `url` FROM `?` WHERE `checksum` IS NULL", array(LYCHEE_TABLE_PHOTOS));
  9. $result = $database->query($query);
  10. if (!$result) {
  11. Log::error($database, 'update_020602', __LINE__, 'Could not find photos without checksum (' . $database->error . ')');
  12. return false;
  13. }
  14. while ($photo = $result->fetch_object()) {
  15. $checksum = sha1_file(LYCHEE_UPLOADS_BIG . $photo->url);
  16. if ($checksum!==false) {
  17. $query = Database::prepare($database, "UPDATE `?` SET `checksum` = '?' WHERE `id` = '?'", array(LYCHEE_TABLE_PHOTOS, $checksum, $photo->id));
  18. $setChecksum = $database->query($query);
  19. if (!$setChecksum) {
  20. Log::error($database, 'update_020602', __LINE__, 'Could not update checksum (' . $database->error . ')');
  21. return false;
  22. }
  23. } else {
  24. Log::error($database, 'update_020602', __LINE__, 'Could not calculate checksum for photo with id ' . $photo->id);
  25. return false;
  26. }
  27. }
  28. # Add Imagick
  29. $query = Database::prepare($database, "SELECT `key` FROM `?` WHERE `key` = 'imagick' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
  30. $result = $database->query($query);
  31. if ($result->num_rows===0) {
  32. $query = Database::prepare($database, "INSERT INTO `?` (`key`, `value`) VALUES ('imagick', '1')", array(LYCHEE_TABLE_SETTINGS));
  33. $result = $database->query($query);
  34. if (!$result) {
  35. Log::error($database, 'update_020100', __LINE__, 'Could not update database (' . $database->error . ')');
  36. return false;
  37. }
  38. }
  39. # Set version
  40. if (Database::setVersion($database, '020602')===false) return false;
  41. ?>