update_020700.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Update to version 2.7.0
  4. */
  5. namespace Lychee\Database;
  6. use Lychee\Modules\Database;
  7. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  8. // Add medium to photos
  9. $query = Database::prepare($connection, "SELECT `medium` FROM `?` LIMIT 1", array(LYCHEE_TABLE_PHOTOS));
  10. if (!$connection->query($query)) {
  11. $query = Database::prepare($connection, "ALTER TABLE `?` ADD `medium` TINYINT(1) NOT NULL DEFAULT 0", array(LYCHEE_TABLE_PHOTOS));
  12. $result = $connection->query($query);
  13. if (!$result) {
  14. Log::error('update_020700', __LINE__, 'Could not update database (' . $connection->error . ')');
  15. return false;
  16. }
  17. }
  18. // Create medium folder
  19. if (is_dir(LYCHEE_UPLOADS_MEDIUM)===false) {
  20. // Only create the folder when it is missing
  21. if (@mkdir(LYCHEE_UPLOADS_MEDIUM)===false) {
  22. Log::error('update_020700', __LINE__, 'Could not create medium-folder');
  23. }
  24. }
  25. // Add medium to settings
  26. $query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'medium' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
  27. $result = $connection->query($query);
  28. if ($result->num_rows===0) {
  29. $query = Database::prepare($connection, "INSERT INTO `?` (`key`, `value`) VALUES ('medium', '1')", array(LYCHEE_TABLE_SETTINGS));
  30. $result = $connection->query($query);
  31. if (!$result) {
  32. Log::error('update_020700', __LINE__, 'Could not update database (' . $connection->error . ')');
  33. return false;
  34. }
  35. }
  36. // Set version
  37. if (Database::setVersion($connection, '020700')===false) return false;
  38. ?>