update_020500.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. ###
  3. # @name Update to version 2.5
  4. # @author Tobias Reich
  5. # @copyright 2014 by Tobias Reich
  6. ###
  7. # Add `plugins`
  8. $result = $database->query("SELECT `key` FROM `lychee_settings` WHERE `key` = 'plugins' LIMIT 1;");
  9. if ($result->num_rows===0) {
  10. $result = $database->query("INSERT INTO `lychee_settings` (`key`, `value`) VALUES ('plugins', '')");
  11. if (!$result) return false;
  12. }
  13. # Add `takestamp`
  14. if (!$database->query("SELECT `takestamp` FROM `lychee_photos` LIMIT 1;")) {
  15. $result = $database->query("ALTER TABLE `lychee_photos` ADD `takestamp` INT(11) DEFAULT NULL");
  16. if (!$result) return false;
  17. }
  18. # Convert to `takestamp`
  19. if ($database->query("SELECT `takedate`, `taketime` FROM `lychee_photos` LIMIT 1;")) {
  20. $result = $database->query("SELECT `id`, `takedate`, `taketime` FROM `lychee_photos` WHERE `takedate` <> '' AND `taketime` <> '';");
  21. if (!$result) return false;
  22. while ($photo = $result->fetch_object()) {
  23. $takestamp = strtotime($photo->takedate . $photo->taketime);
  24. $database->query("UPDATE `lychee_photos` SET `takestamp` = '$takestamp' WHERE `id` = '$photo->id';");
  25. }
  26. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `takedate`;");
  27. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `taketime`;");
  28. }
  29. # Remove `import_name`
  30. if ($database->query("SELECT `import_name` FROM `lychee_photos` LIMIT 1;")) {
  31. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `import_name`;");
  32. }
  33. # Remove `sysdate` and `systime`
  34. if ($database->query("SELECT `sysdate`, `systime` FROM `lychee_photos` LIMIT 1;")) {
  35. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `sysdate`;");
  36. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `systime`;");
  37. }
  38. # Add `sysstamp`
  39. if (!$database->query("SELECT `sysstamp` FROM `lychee_albums` LIMIT 1;")) {
  40. $result = $database->query("ALTER TABLE `lychee_albums` ADD `sysstamp` INT(11) DEFAULT NULL");
  41. if (!$result) return false;
  42. }
  43. # Convert to `sysstamp`
  44. if ($database->query("SELECT `sysdate` FROM `lychee_albums` LIMIT 1;")) {
  45. $result = $database->query("SELECT `id`, `sysdate` FROM `lychee_albums`;");
  46. if (!$result) return false;
  47. while ($album = $result->fetch_object()) {
  48. $sysstamp = strtotime($album->sysdate);
  49. $database->query("UPDATE `lychee_albums` SET `sysstamp` = '$sysstamp' WHERE `id` = '$album->id';");
  50. }
  51. $result = $database->query("ALTER TABLE `lychee_albums` DROP COLUMN `sysdate`;");
  52. }
  53. # Set character of database
  54. $result = $database->query("ALTER DATABASE $dbName CHARACTER SET utf8 COLLATE utf8_general_ci;");
  55. if (!$result) return false;
  56. # Set character
  57. $result = $database->query("ALTER TABLE `lychee_albums` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;");
  58. if (!$result) return false;
  59. # Set character
  60. $result = $database->query("ALTER TABLE `lychee_photos` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;");
  61. if (!$result) return false;
  62. # Set character
  63. $result = $database->query("ALTER TABLE `lychee_settings` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;");
  64. if (!$result) return false;
  65. # Set album password length to 100 (for longer hashes)
  66. $result = $database->query("ALTER TABLE `lychee_albums` CHANGE `password` `password` VARCHAR(100);");
  67. if (!$result) return false;
  68. # Set make length to 50
  69. $result = $database->query("ALTER TABLE `lychee_photos` CHANGE `make` `make` VARCHAR(50);");
  70. if (!$result) return false;
  71. # Reset sorting
  72. $result = $database->query("UPDATE lychee_settings SET value = 'ORDER BY takestamp DESC' WHERE `key` = 'sorting' AND `value` LIKE '%UNIX_TIMESTAMP%';");
  73. if (!$result) return false;
  74. # Set version
  75. $result = $database->query("UPDATE lychee_settings SET value = '020500' WHERE `key` = 'version';");
  76. if (!$result) return false;
  77. ?>