Improved update to v2.5
- Removed `sysdate` and `systime`(#115) - Add `plugins` - Convert to utf-8 (#111)
This commit is contained in:
parent
316c1039fb
commit
1c44616b06
@ -118,7 +118,7 @@ switch ($_POST['function']) {
|
|||||||
|
|
||||||
case 'init': if (!isset($_POST['version'])) exit();
|
case 'init': if (!isset($_POST['version'])) exit();
|
||||||
$session = new Session($plugins, $settings);
|
$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;
|
break;
|
||||||
|
|
||||||
case 'login': if (!isset($_POST['user'], $_POST['password'])) exit();
|
case 'login': if (!isset($_POST['user'], $_POST['password'])) exit();
|
||||||
|
@ -54,7 +54,7 @@ switch ($_POST['function']) {
|
|||||||
// Session Functions
|
// Session Functions
|
||||||
|
|
||||||
case 'init': $session = new Session($plugins, $settings);
|
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;
|
break;
|
||||||
|
|
||||||
case 'login': if (!isset($_POST['user'], $_POST['password'])) exit();
|
case 'login': if (!isset($_POST['user'], $_POST['password'])) exit();
|
||||||
|
@ -6,11 +6,20 @@
|
|||||||
# @copyright 2014 by Tobias Reich
|
# @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;")) {
|
if (!$database->query("SELECT `takestamp` FROM `lychee_photos` LIMIT 1;")) {
|
||||||
$result = $database->query("ALTER TABLE `lychee_photos` ADD `takestamp` INT(11) DEFAULT NULL");
|
$result = $database->query("ALTER TABLE `lychee_photos` ADD `takestamp` INT(11) DEFAULT NULL");
|
||||||
if (!$result) return false;
|
if (!$result) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Convert to `takestamp`
|
||||||
if ($database->query("SELECT `takedate`, `taketime` FROM `lychee_photos` LIMIT 1;")) {
|
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` <> '';");
|
$result = $database->query("SELECT `id`, `takedate`, `taketime` FROM `lychee_photos` WHERE `takedate` <> '' AND `taketime` <> '';");
|
||||||
if (!$result) return false;
|
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`;");
|
$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;")) {
|
if (!$database->query("SELECT `sysstamp` FROM `lychee_albums` LIMIT 1;")) {
|
||||||
$result = $database->query("ALTER TABLE `lychee_albums` ADD `sysstamp` INT(11) DEFAULT NULL");
|
$result = $database->query("ALTER TABLE `lychee_albums` ADD `sysstamp` INT(11) DEFAULT NULL");
|
||||||
if (!$result) return false;
|
if (!$result) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Convert to `sysstamp`
|
||||||
if ($database->query("SELECT `sysdate` FROM `lychee_albums` LIMIT 1;")) {
|
if ($database->query("SELECT `sysdate` FROM `lychee_albums` LIMIT 1;")) {
|
||||||
$result = $database->query("SELECT `id`, `sysdate` FROM `lychee_albums`;");
|
$result = $database->query("SELECT `id`, `sysdate` FROM `lychee_albums`;");
|
||||||
if (!$result) return false;
|
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`;");
|
$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';");
|
$result = $database->query("UPDATE lychee_settings SET value = '020500' WHERE `key` = 'version';");
|
||||||
if (!$result) return false;
|
if (!$result) return false;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class Database extends Module {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static function update($database, $version) {
|
static function update($database, $dbName, $version) {
|
||||||
|
|
||||||
if (!isset($database)) return false;
|
if (!isset($database)) return false;
|
||||||
|
|
||||||
|
@ -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;
|
if (!isset($this->settings, $public, $version)) return false;
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ class Session extends Module {
|
|||||||
|
|
||||||
# Update
|
# Update
|
||||||
if (!isset($this->settings['version'])||$this->settings['version']!==$version)
|
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 settings
|
||||||
$return['config'] = $this->settings;
|
$return['config'] = $this->settings;
|
||||||
|
@ -31,6 +31,9 @@ class Settings extends Module {
|
|||||||
# Add each to return
|
# Add each to return
|
||||||
while ($setting = $settings->fetch_object()) $return[$setting->key] = $setting->value;
|
while ($setting = $settings->fetch_object()) $return[$setting->key] = $setting->value;
|
||||||
|
|
||||||
|
# Fallback for versions below v2.5
|
||||||
|
if (!isset($return['plugins'])) $return['plugins'] = '';
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user