Improved update to v2.5

- Removed `sysdate` and `systime`(#115)
- Add `plugins`
- Convert to utf-8 (#111)
This commit is contained in:
Tobias Reich 2014-04-11 22:25:03 +02:00
parent 316c1039fb
commit 1c44616b06
6 changed files with 42 additions and 5 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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;

View File

@ -35,7 +35,7 @@ class Database extends Module {
}
static function update($database, $version) {
static function update($database, $dbName, $version) {
if (!isset($database)) return false;

View File

@ -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;

View File

@ -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;
}