update_030001.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Update to version 3.0.1
  4. */
  5. use Lychee\Modules\Database;
  6. use Lychee\Modules\Response;
  7. // Change length of photo title
  8. $query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `title` `title` VARCHAR( 100 ) NOT NULL DEFAULT ''", array(LYCHEE_TABLE_PHOTOS));
  9. $result = Database::execute($connection, $query, 'update_030001', __LINE__);
  10. if ($result===false) Response::error('Could not change length of photo title in database!');
  11. // Change length of album title
  12. $query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `title` `title` VARCHAR( 100 ) NOT NULL DEFAULT ''", array(LYCHEE_TABLE_ALBUMS));
  13. $result = Database::execute($connection, $query, 'update_030001', __LINE__);
  14. if ($result===false) Response::error('Could not change length of album title in database!');
  15. // Add album sorting to settings
  16. $query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'sortingAlbums' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
  17. $result = Database::execute($connection, $query, 'update_030001', __LINE__);
  18. if ($result===false) Response::error('Could not get current album sorting from database!');
  19. if ($result->num_rows===0) {
  20. $query = Database::prepare($connection, "INSERT INTO `?` (`key`, `value`) VALUES ('sortingAlbums', 'ORDER BY id DESC')", array(LYCHEE_TABLE_SETTINGS));
  21. $result = Database::execute($connection, $query, 'update_030001', __LINE__);
  22. if ($result===false) Response::error('Could not add album sorting to database!');
  23. }
  24. // Rename sorting to sortingPhotos
  25. $query = Database::prepare($connection, "UPDATE ? SET `key` = 'sortingPhotos' WHERE `key` = 'sorting' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
  26. $result = Database::execute($connection, $query, 'update_030001', __LINE__);
  27. if ($result===false) Response::error('Could not rename photo sorting row in database!');
  28. // Add identifier to settings
  29. $query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'identifier' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
  30. $result = Database::execute($connection, $query, 'update_030001', __LINE__);
  31. if ($result===false) Response::error('Could not get current identifier from database!');
  32. if ($result->num_rows===0) {
  33. $identifier = md5(microtime(true));
  34. $query = Database::prepare($connection, "INSERT INTO `?` (`key`, `value`) VALUES ('identifier', '?')", array(LYCHEE_TABLE_SETTINGS, $identifier));
  35. $result = Database::execute($connection, $query, 'update_030001', __LINE__);
  36. if ($result===false) Response::error('Could not add identifier to database!');
  37. }
  38. // Set version
  39. if (Database::setVersion($connection, '030001')===false) Response::error('Could not update version of database!');
  40. ?>