update_030001.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. ###
  3. # @name Update to version 3.0.1
  4. # @copyright 2015 by Tobias Reich
  5. ###
  6. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  7. # Change length of photo title
  8. $query = Database::prepare($database, "ALTER TABLE `?` CHANGE `title` `title` VARCHAR( 100 ) NOT NULL DEFAULT ''", array(LYCHEE_TABLE_PHOTOS));
  9. $result = $database->query($query);
  10. if (!$result) {
  11. Log::error($database, 'update_030001', __LINE__, 'Could not update database (' . $database->error . ')');
  12. return false;
  13. }
  14. # Change length of album title
  15. $query = Database::prepare($database, "ALTER TABLE `?` CHANGE `title` `title` VARCHAR( 100 ) NOT NULL DEFAULT ''", array(LYCHEE_TABLE_ALBUMS));
  16. $result = $database->query($query);
  17. if (!$result) {
  18. Log::error($database, 'update_030001', __LINE__, 'Could not update database (' . $database->error . ')');
  19. return false;
  20. }
  21. # Add album sorting to settings
  22. $query = Database::prepare($database, "SELECT `key` FROM `?` WHERE `key` = 'sortingAlbums' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
  23. $result = $database->query($query);
  24. if ($result->num_rows===0) {
  25. $query = Database::prepare($database, "INSERT INTO `?` (`key`, `value`) VALUES ('sortingAlbums', 'ORDER BY id DESC')", array(LYCHEE_TABLE_SETTINGS));
  26. $result = $database->query($query);
  27. if (!$result) {
  28. Log::error($database, 'update_030001', __LINE__, 'Could not update database (' . $database->error . ')');
  29. return false;
  30. }
  31. }
  32. # Rename sorting to sortingPhotos
  33. $query = Database::prepare($database, "UPDATE ? SET `key` = 'sortingPhotos' WHERE `key` = 'sorting' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
  34. $result = $database->query($query);
  35. if (!$result) {
  36. Log::error($database, 'update_030001', __LINE__, 'Could not update database (' . $database->error . ')');
  37. return false;
  38. }
  39. # Add identifier to settings
  40. $query = Database::prepare($database, "SELECT `key` FROM `?` WHERE `key` = 'identifier' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
  41. $result = $database->query($query);
  42. if ($result->num_rows===0) {
  43. $identifier = md5(microtime(true));
  44. $query = Database::prepare($database, "INSERT INTO `?` (`key`, `value`) VALUES ('identifier', '?')", array(LYCHEE_TABLE_SETTINGS, $identifier));
  45. $result = $database->query($query);
  46. if (!$result) {
  47. Log::error($database, 'update_030001', __LINE__, 'Could not update database (' . $database->error . ')');
  48. return false;
  49. }
  50. } else {
  51. $identifier = md5(microtime(true));
  52. $query = Database::prepare($database, "UPDATE `?` SET `value` = '?' WHERE `key` = 'identifier' LIMIT 1", array(LYCHEE_TABLE_SETTINGS, $identifier));
  53. $result = $database->query($query);
  54. if (!$result) {
  55. Log::error($database, 'update_030001', __LINE__, 'Could not reset public albums (' . $database->error . ')');
  56. return false;
  57. }
  58. }
  59. # Set version
  60. if (Database::setVersion($database, '030001')===false) return false;
  61. ?>