update_020500.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. # Set version
  72. $result = $database->query("UPDATE lychee_settings SET value = '020500' WHERE `key` = 'version';");
  73. if (!$result) return false;
  74. ?>