update_020602.php 1.6 KB

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