update_020500.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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) {
  12. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  13. return false;
  14. }
  15. }
  16. # Add `takestamp`
  17. if (!$database->query("SELECT `takestamp` FROM `lychee_photos` LIMIT 1;")) {
  18. $result = $database->query("ALTER TABLE `lychee_photos` ADD `takestamp` INT(11) DEFAULT NULL");
  19. if (!$result) {
  20. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  21. return false;
  22. }
  23. }
  24. # Convert to `takestamp`
  25. if ($database->query("SELECT `takedate`, `taketime` FROM `lychee_photos` LIMIT 1;")) {
  26. $result = $database->query("SELECT `id`, `takedate`, `taketime` FROM `lychee_photos` WHERE `takedate` <> '' AND `taketime` <> '';");
  27. if (!$result) {
  28. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  29. return false;
  30. }
  31. while ($photo = $result->fetch_object()) {
  32. $takestamp = strtotime($photo->takedate . $photo->taketime);
  33. $database->query("UPDATE `lychee_photos` SET `takestamp` = '$takestamp' WHERE `id` = '$photo->id';");
  34. }
  35. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `takedate`;");
  36. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `taketime`;");
  37. }
  38. # Remove `import_name`
  39. if ($database->query("SELECT `import_name` FROM `lychee_photos` LIMIT 1;")) {
  40. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `import_name`;");
  41. }
  42. # Remove `sysdate` and `systime`
  43. if ($database->query("SELECT `sysdate`, `systime` FROM `lychee_photos` LIMIT 1;")) {
  44. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `sysdate`;");
  45. $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `systime`;");
  46. }
  47. # Add `sysstamp`
  48. if (!$database->query("SELECT `sysstamp` FROM `lychee_albums` LIMIT 1;")) {
  49. $result = $database->query("ALTER TABLE `lychee_albums` ADD `sysstamp` INT(11) DEFAULT NULL");
  50. if (!$result) {
  51. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  52. return false;
  53. }
  54. }
  55. # Convert to `sysstamp`
  56. if ($database->query("SELECT `sysdate` FROM `lychee_albums` LIMIT 1;")) {
  57. $result = $database->query("SELECT `id`, `sysdate` FROM `lychee_albums`;");
  58. if (!$result) {
  59. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  60. return false;
  61. }
  62. while ($album = $result->fetch_object()) {
  63. $sysstamp = strtotime($album->sysdate);
  64. $database->query("UPDATE `lychee_albums` SET `sysstamp` = '$sysstamp' WHERE `id` = '$album->id';");
  65. }
  66. $result = $database->query("ALTER TABLE `lychee_albums` DROP COLUMN `sysdate`;");
  67. }
  68. # Set character of database
  69. $result = $database->query("ALTER DATABASE $dbName CHARACTER SET utf8 COLLATE utf8_general_ci;");
  70. if (!$result) {
  71. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  72. return false;
  73. }
  74. # Set character
  75. $result = $database->query("ALTER TABLE `lychee_albums` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;");
  76. if (!$result) {
  77. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  78. return false;
  79. }
  80. # Set character
  81. $result = $database->query("ALTER TABLE `lychee_photos` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;");
  82. if (!$result) {
  83. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  84. return false;
  85. }
  86. # Set character
  87. $result = $database->query("ALTER TABLE `lychee_settings` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;");
  88. if (!$result) {
  89. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  90. return false;
  91. }
  92. # Set album password length to 100 (for longer hashes)
  93. $result = $database->query("ALTER TABLE `lychee_albums` CHANGE `password` `password` VARCHAR(100);");
  94. if (!$result) {
  95. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  96. return false;
  97. }
  98. # Set make length to 50
  99. $result = $database->query("ALTER TABLE `lychee_photos` CHANGE `make` `make` VARCHAR(50);");
  100. if (!$result) {
  101. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  102. return false;
  103. }
  104. # Reset sorting
  105. $result = $database->query("UPDATE lychee_settings SET value = 'ORDER BY takestamp DESC' WHERE `key` = 'sorting' AND `value` LIKE '%UNIX_TIMESTAMP%';");
  106. if (!$result) {
  107. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  108. return false;
  109. }
  110. # Set version
  111. $result = $database->query("UPDATE lychee_settings SET value = '020500' WHERE `key` = 'version';");
  112. if (!$result) {
  113. Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
  114. return false;
  115. }
  116. ?>