update_030001.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }
  51. # Set version
  52. if (Database::setVersion($database, '030001')===false) return false;
  53. ?>