Improved update mechanism (#115)
This commit is contained in:
parent
b7ca72b817
commit
44d44e04fd
@ -8,7 +8,8 @@
|
||||
var lychee = {
|
||||
|
||||
title: "",
|
||||
version: "2.2 b1",
|
||||
version: "2.5 b1",
|
||||
version_code: "020200",
|
||||
|
||||
api_path: "php/api.php",
|
||||
update_path: "http://lychee.electerious.com/version/index.php",
|
||||
@ -39,7 +40,7 @@ var lychee = {
|
||||
|
||||
var params;
|
||||
|
||||
params = "init&version=" + escape(lychee.version);
|
||||
params = "init&version=" + lychee.version_code;
|
||||
lychee.api(params, function(data) {
|
||||
|
||||
if (data.loggedIn!==true) {
|
||||
|
@ -26,7 +26,7 @@ var settings = {
|
||||
if (dbHost.length<1) dbHost = "localhost";
|
||||
if (dbName.length<1) dbName = "lychee";
|
||||
|
||||
params = "dbCreateConfig&dbName=" + escape(dbName) + "&dbUser=" + escape(dbUser) + "&dbPassword=" + escape(dbPassword) + "&dbHost=" + escape(dbHost) + "&version=" + escape(lychee.version);
|
||||
params = "dbCreateConfig&dbName=" + escape(dbName) + "&dbUser=" + escape(dbUser) + "&dbPassword=" + escape(dbPassword) + "&dbHost=" + escape(dbHost);
|
||||
lychee.api(params, function(data) {
|
||||
|
||||
if (data!==true) {
|
||||
|
File diff suppressed because one or more lines are too long
@ -118,7 +118,7 @@ switch ($_POST['function']) {
|
||||
|
||||
case 'init': if (!isset($_POST['version'])) exit();
|
||||
$session = new Session($plugins, $settings);
|
||||
echo json_encode($session->init(false, $_POST['version']));
|
||||
echo json_encode($session->init($database, false, $_POST['version']));
|
||||
break;
|
||||
|
||||
case 'login': if (!isset($_POST['user'], $_POST['password'])) exit();
|
||||
@ -162,9 +162,6 @@ switch ($_POST['function']) {
|
||||
$photo->getArchive();
|
||||
break;
|
||||
|
||||
case 'update': echo update();
|
||||
break;
|
||||
|
||||
default: exit('Error: Function not found! Please check the spelling of the called function.');
|
||||
break;
|
||||
|
||||
|
@ -54,7 +54,7 @@ switch ($_POST['function']) {
|
||||
// Session Functions
|
||||
|
||||
case 'init': $session = new Session($plugins, $settings);
|
||||
echo json_encode($session->init(true, $_POST['version']));
|
||||
echo json_encode($session->init($database, true, $_POST['version']));
|
||||
break;
|
||||
|
||||
case 'login': if (!isset($_POST['user'], $_POST['password'])) exit();
|
||||
|
14
php/database/albums_table.sql
Normal file
14
php/database/albums_table.sql
Normal file
@ -0,0 +1,14 @@
|
||||
# Dump of table lychee_albums
|
||||
# Version 2.5
|
||||
# ------------------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `lychee_albums` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(50) NOT NULL,
|
||||
`description` varchar(1000) DEFAULT '',
|
||||
`sysdate` varchar(10) NOT NULL,
|
||||
`public` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`visible` tinyint(1) NOT NULL DEFAULT '1',
|
||||
`password` varchar(100) DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
29
php/database/photos_table.sql
Normal file
29
php/database/photos_table.sql
Normal file
@ -0,0 +1,29 @@
|
||||
# Dump of table lychee_photos
|
||||
# Version 2.5
|
||||
# ------------------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `lychee_photos` (
|
||||
`id` bigint(14) NOT NULL,
|
||||
`title` varchar(50) NOT NULL,
|
||||
`description` varchar(1000) DEFAULT '',
|
||||
`url` varchar(100) NOT NULL,
|
||||
`tags` varchar(1000) NOT NULL DEFAULT '',
|
||||
`public` tinyint(1) NOT NULL,
|
||||
`type` varchar(10) NOT NULL,
|
||||
`width` int(11) NOT NULL,
|
||||
`height` int(11) NOT NULL,
|
||||
`size` varchar(20) NOT NULL,
|
||||
`iso` varchar(15) NOT NULL,
|
||||
`aperture` varchar(20) NOT NULL,
|
||||
`make` varchar(20) NOT NULL,
|
||||
`model` varchar(50) NOT NULL,
|
||||
`shutter` varchar(30) NOT NULL,
|
||||
`focal` varchar(20) NOT NULL,
|
||||
`takedate` varchar(20) NOT NULL,
|
||||
`taketime` varchar(8) NOT NULL,
|
||||
`star` tinyint(1) NOT NULL,
|
||||
`thumbUrl` varchar(50) NOT NULL,
|
||||
`album` varchar(30) NOT NULL DEFAULT '0',
|
||||
`import_name` varchar(100) DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
14
php/database/settings_content.sql
Normal file
14
php/database/settings_content.sql
Normal file
@ -0,0 +1,14 @@
|
||||
# Content of table lychee_settings
|
||||
# Version 2.5
|
||||
# ------------------------------------------------------------
|
||||
|
||||
INSERT INTO `lychee_settings` (`key`, `value`)
|
||||
VALUES
|
||||
('version',''),
|
||||
('username',''),
|
||||
('password',''),
|
||||
('thumbQuality','90'),
|
||||
('checkForUpdates','1'),
|
||||
('sorting','ORDER BY id DESC'),
|
||||
('dropboxKey',''),
|
||||
('plugins','');
|
8
php/database/settings_table.sql
Normal file
8
php/database/settings_table.sql
Normal file
@ -0,0 +1,8 @@
|
||||
# Dump of table lychee_settings
|
||||
# Version 2.5
|
||||
# ------------------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `lychee_settings` (
|
||||
`key` varchar(50) NOT NULL DEFAULT '',
|
||||
`value` varchar(200) DEFAULT ''
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
29
php/database/update_020100.php
Normal file
29
php/database/update_020100.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
###
|
||||
# @name Update to version 2.1
|
||||
# @author Tobias Reich
|
||||
# @copyright 2014 by Tobias Reich
|
||||
###
|
||||
|
||||
if(!$database->query("SELECT `tags` FROM `lychee_photos` LIMIT 1;")) {
|
||||
$result = $database->query("ALTER TABLE `lychee_photos` ADD `tags` VARCHAR( 1000 ) NULL DEFAULT ''");
|
||||
if (!$result) return false;
|
||||
}
|
||||
|
||||
$result = $database->query("SELECT `key` FROM `lychee_settings` WHERE `key` = 'dropboxKey' LIMIT 1;");
|
||||
if ($result->num_rows===0) {
|
||||
$result = $database->query("INSERT INTO `lychee_settings` (`key`, `value`) VALUES ('dropboxKey', '')");
|
||||
if (!$result) return false;
|
||||
}
|
||||
|
||||
$result = $database->query("SELECT `key` FROM `lychee_settings` WHERE `key` = 'version' LIMIT 1;");
|
||||
if ($result->num_rows===0) {
|
||||
$result = $database->query("INSERT INTO `lychee_settings` (`key`, `value`) VALUES ('version', '020100')");
|
||||
if (!$result) return false;
|
||||
} else {
|
||||
$result = $database->query("UPDATE lychee_settings SET value = '020100' WHERE `key` = 'version';");
|
||||
if (!$result) return false;
|
||||
}
|
||||
|
||||
?>
|
15
php/database/update_020101.php
Normal file
15
php/database/update_020101.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
###
|
||||
# @name Update to version 2.1.1
|
||||
# @author Tobias Reich
|
||||
# @copyright 2014 by Tobias Reich
|
||||
###
|
||||
|
||||
$result = $database->query("ALTER TABLE `lychee_settings` CHANGE `value` `value` VARCHAR( 200 ) NULL DEFAULT ''");
|
||||
if (!$result) return false;
|
||||
|
||||
$result = $database->query("UPDATE lychee_settings SET value = '020101' WHERE `key` = 'version';");
|
||||
if (!$result) return false;
|
||||
|
||||
?>
|
17
php/database/update_020200.php
Normal file
17
php/database/update_020200.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
###
|
||||
# @name Update to version 2.2
|
||||
# @author Tobias Reich
|
||||
# @copyright 2014 by Tobias Reich
|
||||
###
|
||||
|
||||
if(!$database->query("SELECT `visible` FROM `lychee_albums` LIMIT 1;")) {
|
||||
$result = $database->query("ALTER TABLE `lychee_albums` ADD `visible` TINYINT(1) NOT NULL DEFAULT 1");
|
||||
if (!$result) return false;
|
||||
}
|
||||
|
||||
$result = $database->query("UPDATE lychee_settings SET value = '020200' WHERE `key` = 'version';");
|
||||
if (!$result) return false;
|
||||
|
||||
?>
|
@ -34,9 +34,34 @@ class Database extends Module {
|
||||
|
||||
}
|
||||
|
||||
static function createConfig($host = 'localhost', $user, $password, $name = 'lychee', $version) {
|
||||
static function update($database, $version) {
|
||||
|
||||
if (!isset($host, $user, $password, $name, $version)) return false;
|
||||
if (!isset($database)) return false;
|
||||
|
||||
# List of updates
|
||||
$updates = array(
|
||||
'020100', #2.1
|
||||
'020101', #2.1.1
|
||||
'020200' #2.2
|
||||
);
|
||||
|
||||
# For each update
|
||||
foreach ($updates as $update) {
|
||||
|
||||
if (isset($version)&&$update<=$version) continue;
|
||||
|
||||
# Load update
|
||||
include('./database/update_' . $update . '.php');
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
static function createConfig($host = 'localhost', $user, $password, $name = 'lychee') {
|
||||
|
||||
if (!isset($host, $user, $password, $name)) return false;
|
||||
|
||||
$database = new mysqli($host, $user, $password);
|
||||
|
||||
@ -53,9 +78,6 @@ $config = "<?php
|
||||
|
||||
if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||
|
||||
# Config version
|
||||
\$configVersion = '';
|
||||
|
||||
# Database configuration
|
||||
\$dbHost = '$host'; # Host of the database
|
||||
\$dbUser = '$user'; # Username of the database
|
||||
@ -77,7 +99,7 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||
|
||||
if (!isset($database, $name)) return false;
|
||||
|
||||
# Execute query
|
||||
# Create database
|
||||
$result = $database->query("CREATE DATABASE IF NOT EXISTS $name;");
|
||||
$database->select_db($name);
|
||||
|
||||
@ -93,30 +115,18 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||
# Create settings
|
||||
if (!$database->query('SELECT * FROM lychee_settings LIMIT 0;')) {
|
||||
|
||||
$query = "
|
||||
|
||||
CREATE TABLE `lychee_settings` (
|
||||
`key` varchar(50) NOT NULL DEFAULT '',
|
||||
`value` varchar(50) DEFAULT ''
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
||||
|
||||
";
|
||||
# Read file
|
||||
$file = './database/settings_table.sql';
|
||||
$query = file_get_contents($file);
|
||||
|
||||
# Create table
|
||||
if (!$database->query($query)) return false;
|
||||
|
||||
$query = "
|
||||
|
||||
INSERT INTO `lychee_settings` (`key`, `value`)
|
||||
VALUES
|
||||
('username',''),
|
||||
('password',''),
|
||||
('thumbQuality','90'),
|
||||
('checkForUpdates','1'),
|
||||
('sorting','ORDER BY id DESC'),
|
||||
('dropboxKey','');
|
||||
|
||||
";
|
||||
# Read file
|
||||
$file = './database/settings_content.sql';
|
||||
$query = file_get_contents($file);
|
||||
|
||||
# Add content
|
||||
if (!$database->query($query)) return false;
|
||||
|
||||
}
|
||||
@ -124,21 +134,11 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||
# Create albums
|
||||
if (!$database->query('SELECT * FROM lychee_albums LIMIT 0;')) {
|
||||
|
||||
$query = "
|
||||
|
||||
CREATE TABLE `lychee_albums` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(50) NOT NULL,
|
||||
`description` varchar(1000) DEFAULT '',
|
||||
`sysdate` varchar(10) NOT NULL,
|
||||
`public` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`visible` tinyint(1) NOT NULL DEFAULT '1',
|
||||
`password` varchar(100) DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
||||
|
||||
";
|
||||
# Read file
|
||||
$file = './database/albums_table.sql';
|
||||
$query = file_get_contents($file);
|
||||
|
||||
# Create table
|
||||
if (!$database->query($query)) return false;
|
||||
|
||||
}
|
||||
@ -146,38 +146,11 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||
# Create photos
|
||||
if (!$database->query('SELECT * FROM lychee_photos LIMIT 0;')) {
|
||||
|
||||
$query = "
|
||||
|
||||
CREATE TABLE `lychee_photos` (
|
||||
`id` bigint(14) NOT NULL,
|
||||
`title` varchar(50) NOT NULL,
|
||||
`description` varchar(1000) NOT NULL DEFAULT '',
|
||||
`url` varchar(100) NOT NULL,
|
||||
`tags` varchar(1000) NOT NULL DEFAULT '',
|
||||
`public` tinyint(1) NOT NULL,
|
||||
`type` varchar(10) NOT NULL,
|
||||
`width` int(11) NOT NULL,
|
||||
`height` int(11) NOT NULL,
|
||||
`size` varchar(20) NOT NULL,
|
||||
`sysdate` varchar(10) NOT NULL,
|
||||
`systime` varchar(8) NOT NULL,
|
||||
`iso` varchar(15) NOT NULL,
|
||||
`aperture` varchar(20) NOT NULL,
|
||||
`make` varchar(20) NOT NULL,
|
||||
`model` varchar(50) NOT NULL,
|
||||
`shutter` varchar(30) NOT NULL,
|
||||
`focal` varchar(20) NOT NULL,
|
||||
`takedate` varchar(20) NOT NULL,
|
||||
`taketime` varchar(8) NOT NULL,
|
||||
`star` tinyint(1) NOT NULL,
|
||||
`thumbUrl` varchar(50) NOT NULL,
|
||||
`album` varchar(30) NOT NULL DEFAULT '0',
|
||||
`import_name` varchar(100) DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
||||
|
||||
";
|
||||
# Read file
|
||||
$file = './database/photos_table.sql';
|
||||
$query = file_get_contents($file);
|
||||
|
||||
# Create table
|
||||
if (!$database->query($query)) return false;
|
||||
|
||||
}
|
||||
|
@ -22,18 +22,16 @@ class Session extends Module {
|
||||
|
||||
}
|
||||
|
||||
public function init($public, $version) {
|
||||
public function init($database, $public, $version) {
|
||||
|
||||
if (!isset($this->settings, $public, $version)) return false;
|
||||
|
||||
# Call plugins
|
||||
$this->plugins(__METHOD__, 0, func_get_args());
|
||||
|
||||
global $configVersion;
|
||||
|
||||
# Update
|
||||
if ($configVersion!==$version)
|
||||
if (!update($version)) exit('Error: Updating the database failed!');
|
||||
if (!isset($this->settings['version'])||$this->settings['version']!==$version)
|
||||
if (!Database::update($database, @$this->settings['version'])) exit('Error: Updating the database failed!');
|
||||
|
||||
# Return settings
|
||||
$return['config'] = $this->settings;
|
||||
|
@ -80,34 +80,4 @@ function search($term) {
|
||||
|
||||
}
|
||||
|
||||
function update($version = '') {
|
||||
|
||||
global $database, $configVersion;
|
||||
|
||||
// Albums
|
||||
if(!$database->query("SELECT `description` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `description` VARCHAR( 1000 ) NULL DEFAULT ''"); // v2.0
|
||||
if($database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` CHANGE `password` `password` VARCHAR( 100 ) NULL DEFAULT ''"); // v2.0
|
||||
if(!$database->query("SELECT `visible` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `visible` TINYINT(1) NOT NULL DEFAULT 1"); // v2.2
|
||||
|
||||
// Photos
|
||||
if($database->query("SELECT `description` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` CHANGE `description` `description` VARCHAR( 1000 ) NULL DEFAULT ''"); // v2.0
|
||||
if(!$database->query("SELECT `tags` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` ADD `tags` VARCHAR( 1000 ) NULL DEFAULT ''"); // v2.1
|
||||
$database->query("UPDATE `lychee_photos` SET url = replace(url, 'uploads/big/', ''), thumbUrl = replace(thumbUrl, 'uploads/thumb/', '')");
|
||||
|
||||
// Settings
|
||||
$database->query("ALTER TABLE `lychee_settings` CHANGE `value` `value` VARCHAR( 200 ) NULL DEFAULT ''"); // v2.1.1
|
||||
$result = $database->query("SELECT `key` FROM `lychee_settings` WHERE `key` = 'dropboxKey' LIMIT 1;");
|
||||
if ($result->num_rows===0) $database->query("INSERT INTO `lychee_settings` (`key`, `value`) VALUES ('dropboxKey', '')"); // v2.1
|
||||
|
||||
// Config
|
||||
if ($version!==''&&$configVersion!==$version) {
|
||||
$data = file_get_contents('../data/config.php');
|
||||
$data = preg_replace('/\$configVersion = \'[\w. ]*\';/', "\$configVersion = '$version';", $data);
|
||||
if (file_put_contents('../data/config.php', $data)===false) return 'Error: Could not save updated config!';
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user