update_020602.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. ###
  3. # @name Update to version 2.6.2
  4. # @copyright 2015 by Tobias Reich
  5. ###
  6. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  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_020602', __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. ?>