update_030001.php 2.4 KB

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