update_020500.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 `sysdate` and `systime`
  30. if ($database->query("SELECT `sysdate`, `systime` FROM `lychee_photos` LIMIT 1;")) {
  31. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `sysdate`;");
  32. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `systime`;");
  33. }
  34. # Add `sysstamp`
  35. if (!$database->query("SELECT `sysstamp` FROM `lychee_albums` LIMIT 1;")) {
  36. $result = $database->query("ALTER TABLE `lychee_albums` ADD `sysstamp` INT(11) DEFAULT NULL");
  37. if (!$result) return false;
  38. }
  39. # Convert to `sysstamp`
  40. if ($database->query("SELECT `sysdate` FROM `lychee_albums` LIMIT 1;")) {
  41. $result = $database->query("SELECT `id`, `sysdate` FROM `lychee_albums`;");
  42. if (!$result) return false;
  43. while ($album = $result->fetch_object()) {
  44. $sysstamp = strtotime($album->sysdate);
  45. $database->query("UPDATE `lychee_albums` SET `sysstamp` = '$sysstamp' WHERE `id` = '$album->id';");
  46. }
  47. $result = $database->query("ALTER TABLE `lychee_albums` DROP COLUMN `sysdate`;");
  48. }
  49. # Set character of database
  50. $result = $database->query("ALTER DATABASE $dbName CHARACTER SET utf8 COLLATE utf8_general_ci;");
  51. if (!$result) return false;
  52. # Set character
  53. $result = $database->query("ALTER TABLE `lychee_albums` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;");
  54. if (!$result) return false;
  55. # Set character
  56. $result = $database->query("ALTER TABLE `lychee_photos` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;");
  57. if (!$result) return false;
  58. # Set character
  59. $result = $database->query("ALTER TABLE `lychee_settings` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;");
  60. if (!$result) return false;
  61. # Set version
  62. $result = $database->query("UPDATE lychee_settings SET value = '020500' WHERE `key` = 'version';");
  63. if (!$result) return false;
  64. ?>