diff --git a/php/access/admin.php b/php/access/admin.php index 8da6127..c929109 100644 --- a/php/access/admin.php +++ b/php/access/admin.php @@ -118,7 +118,7 @@ switch ($_POST['function']) { case 'init': if (!isset($_POST['version'])) exit(); $session = new Session($plugins, $settings); - echo json_encode($session->init($database, false, $_POST['version'])); + echo json_encode($session->init($database, $dbName, false, $_POST['version'])); break; case 'login': if (!isset($_POST['user'], $_POST['password'])) exit(); diff --git a/php/access/guest.php b/php/access/guest.php index f809a36..8e6e6dd 100644 --- a/php/access/guest.php +++ b/php/access/guest.php @@ -54,7 +54,7 @@ switch ($_POST['function']) { // Session Functions case 'init': $session = new Session($plugins, $settings); - echo json_encode($session->init($database, true, $_POST['version'])); + echo json_encode($session->init($database, $dbName, true, $_POST['version'])); break; case 'login': if (!isset($_POST['user'], $_POST['password'])) exit(); diff --git a/php/database/update_020500.php b/php/database/update_020500.php index cf97d86..6bb4ed9 100644 --- a/php/database/update_020500.php +++ b/php/database/update_020500.php @@ -6,11 +6,20 @@ # @copyright 2014 by Tobias Reich ### +# Add `plugins` +$result = $database->query("SELECT `key` FROM `lychee_settings` WHERE `key` = 'plugins' LIMIT 1;"); +if ($result->num_rows===0) { + $result = $database->query("INSERT INTO `lychee_settings` (`key`, `value`) VALUES ('plugins', '')"); + if (!$result) return false; +} + +# Add `takestamp` if (!$database->query("SELECT `takestamp` FROM `lychee_photos` LIMIT 1;")) { $result = $database->query("ALTER TABLE `lychee_photos` ADD `takestamp` INT(11) DEFAULT NULL"); if (!$result) return false; } +# Convert to `takestamp` if ($database->query("SELECT `takedate`, `taketime` FROM `lychee_photos` LIMIT 1;")) { $result = $database->query("SELECT `id`, `takedate`, `taketime` FROM `lychee_photos` WHERE `takedate` <> '' AND `taketime` <> '';"); if (!$result) return false; @@ -22,11 +31,19 @@ if ($database->query("SELECT `takedate`, `taketime` FROM `lychee_photos` LIMIT 1 $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `taketime`;"); } +# Remove `sysdate` and `systime` +if ($database->query("SELECT `sysdate`, `systime` FROM `lychee_photos` LIMIT 1;")) { + $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `sysdate`;"); + $result = $database->query("ALTER TABLE `lychee_photos` DROP COLUMN `systime`;"); +} + +# Add `sysstamp` if (!$database->query("SELECT `sysstamp` FROM `lychee_albums` LIMIT 1;")) { $result = $database->query("ALTER TABLE `lychee_albums` ADD `sysstamp` INT(11) DEFAULT NULL"); if (!$result) return false; } +# Convert to `sysstamp` if ($database->query("SELECT `sysdate` FROM `lychee_albums` LIMIT 1;")) { $result = $database->query("SELECT `id`, `sysdate` FROM `lychee_albums`;"); if (!$result) return false; @@ -37,6 +54,23 @@ if ($database->query("SELECT `sysdate` FROM `lychee_albums` LIMIT 1;")) { $result = $database->query("ALTER TABLE `lychee_albums` DROP COLUMN `sysdate`;"); } +# Set character of database +$result = $database->query("ALTER DATABASE $dbName CHARACTER SET utf8 COLLATE utf8_general_ci;"); +if (!$result) return false; + +# Set character +$result = $database->query("ALTER TABLE `lychee_albums` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"); +if (!$result) return false; + +# Set character +$result = $database->query("ALTER TABLE `lychee_photos` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"); +if (!$result) return false; + +# Set character +$result = $database->query("ALTER TABLE `lychee_settings` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"); +if (!$result) return false; + +# Set version $result = $database->query("UPDATE lychee_settings SET value = '020500' WHERE `key` = 'version';"); if (!$result) return false; diff --git a/php/modules/Database.php b/php/modules/Database.php index 42cb42a..71738f3 100755 --- a/php/modules/Database.php +++ b/php/modules/Database.php @@ -35,7 +35,7 @@ class Database extends Module { } - static function update($database, $version) { + static function update($database, $dbName, $version) { if (!isset($database)) return false; diff --git a/php/modules/Session.php b/php/modules/Session.php index 0bfe9e3..c9db80f 100755 --- a/php/modules/Session.php +++ b/php/modules/Session.php @@ -22,7 +22,7 @@ class Session extends Module { } - public function init($database, $public, $version) { + public function init($database, $dbName, $public, $version) { if (!isset($this->settings, $public, $version)) return false; @@ -31,7 +31,7 @@ class Session extends Module { # Update if (!isset($this->settings['version'])||$this->settings['version']!==$version) - if (!Database::update($database, @$this->settings['version'])) exit('Error: Updating the database failed!'); + if (!Database::update($database, $dbName, @$this->settings['version'])) exit('Error: Updating the database failed!'); # Return settings $return['config'] = $this->settings; diff --git a/php/modules/Settings.php b/php/modules/Settings.php index 8aee2a8..2506e18 100755 --- a/php/modules/Settings.php +++ b/php/modules/Settings.php @@ -31,6 +31,9 @@ class Settings extends Module { # Add each to return while ($setting = $settings->fetch_object()) $return[$setting->key] = $setting->value; + # Fallback for versions below v2.5 + if (!isset($return['plugins'])) $return['plugins'] = ''; + return $return; }