Improved updating mechanism

This commit is contained in:
Tobias Reich 2014-02-23 19:41:12 +01:00
parent b48321b04e
commit f0065bbebc
9 changed files with 41 additions and 20 deletions

View File

@ -7,7 +7,7 @@
var lychee = {
version: "2.1 b3",
version: "2.1 b4",
api_path: "php/api.php",
update_path: "http://lychee.electerious.com/version/index.php",
@ -26,6 +26,7 @@ var lychee = {
sorting: "",
dropbox: false,
dropboxKey: '',
loadingBar: $("#loading"),
header: $("header"),
@ -35,13 +36,17 @@ var lychee = {
init: function() {
lychee.api("init", function(data) {
var params;
params = "init&version=" + escape(lychee.version);
lychee.api(params, function(data) {
if (data.loggedIn!==true) {
lychee.setMode("public");
} else {
lychee.username = data.config.username;
lychee.sorting = data.config.sorting;
lychee.dropboxKey = data.config.dropboxKey;
}
// No configuration
@ -300,7 +305,7 @@ var lychee = {
g.id = "dropboxjs";
g.type = "text/javascript";
g.async = "true";
g.setAttribute("data-app-key", "iq7lioj9wu0ieqs");
g.setAttribute("data-app-key", lychee.dropboxKey);
g.onload = g.onreadystatechange = function() {
var rs = this.readyState;
if (rs&&rs!=="complete"&&rs!=="loaded") return;

View File

@ -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);
params = "dbCreateConfig&dbName=" + escape(dbName) + "&dbUser=" + escape(dbUser) + "&dbPassword=" + escape(dbPassword) + "&dbHost=" + escape(dbHost) + "&version=" + escape(lychee.version);
lychee.api(params, function(data) {
if (data!==true) {
@ -71,7 +71,7 @@ var settings = {
} else {
// Configuration successful
lychee.api("update", function(data) { window.location.reload() });
window.location.reload();
}

View File

@ -101,7 +101,7 @@ switch ($_POST['function']) {
// Session Function
case 'init': echo json_encode(init('admin'));
case 'init': echo json_encode(init('admin', $_POST['version']));
break;
case 'login': if (isset($_POST['user'])&&isset($_POST['password']))
@ -124,8 +124,6 @@ switch ($_POST['function']) {
// Miscellaneous
case 'update': echo update();
default: switch ($_GET['function']) {
case 'getFeed': if (isset($_GET['albumID']))

View File

@ -56,7 +56,7 @@ switch ($_POST['function']) {
// Session Functions
case 'init': echo json_encode(init('public'));
case 'init': echo json_encode(init('public', $_POST['version']));
break;
case 'login': if (isset($_POST['user'])&&isset($_POST['password']))

View File

@ -11,8 +11,8 @@ if (!defined('LYCHEE_ACCESS_INSTALLATION')) exit('Error: You are not allowed to
switch ($_POST['function']) {
case 'dbCreateConfig': if (isset($_POST['dbHost'])&&isset($_POST['dbUser'])&&isset($_POST['dbPassword'])&&isset($_POST['dbName']))
echo dbCreateConfig($_POST['dbHost'], $_POST['dbUser'], $_POST['dbPassword'], $_POST['dbName']);
case 'dbCreateConfig': if (isset($_POST['dbHost'])&&isset($_POST['dbUser'])&&isset($_POST['dbPassword'])&&isset($_POST['dbName'])&&isset($_POST['version']))
echo dbCreateConfig($_POST['dbHost'], $_POST['dbUser'], $_POST['dbPassword'], $_POST['dbName'], $_POST['version']);
break;
default: echo 'Warning: No configuration!';

View File

@ -58,7 +58,7 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
// Fallback for switch statement
if (!isset($_POST['function'])) $_POST['function'] = '';
if (!isset($_GET['function'])) $_GET['function'] = '';
if (isset($_SESSION['login'])&&$_SESSION['login']==true) {
/**

View File

@ -30,7 +30,7 @@ function dbConnect() {
}
function dbCreateConfig($dbHost = 'localhost', $dbUser, $dbPassword, $dbName = 'lychee') {
function dbCreateConfig($dbHost = 'localhost', $dbUser, $dbPassword, $dbName = 'lychee', $version) {
$dbPassword = urldecode($dbPassword);
$database = new mysqli($dbHost, $dbUser, $dbPassword);
@ -43,13 +43,13 @@ $config = "<?php
/**
* @name Config
* @author Tobias Reich
* @copyright 2014 by Philipp Maurer, Tobias Reich
* @copyright 2014 Tobias Reich
*/
if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
// Config version
\$configVersion = '2.1';
\$configVersion = '$version';
// Database configurations
\$dbHost = '$dbHost'; //Host of the Database
@ -101,7 +101,8 @@ function dbCreateTables($database) {
('password',''),
('thumbQuality','90'),
('checkForUpdates','1'),
('sorting','ORDER BY id DESC');
('sorting','ORDER BY id DESC'),
('dropboxKey','');
";

View File

@ -80,19 +80,32 @@ function search($term) {
}
function update() {
function update($version = '') {
global $database;
global $database, $configVersion;
// Albums
if(!$database->query("SELECT `public` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `public` TINYINT( 1 ) NOT NULL DEFAULT '0'");
if(!$database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `password` VARCHAR( 100 ) NULL DEFAULT ''");
if(!$database->query("SELECT `description` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `description` VARCHAR( 1000 ) NULL DEFAULT ''");
if($database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` CHANGE `password` `password` VARCHAR( 100 ) NULL DEFAULT ''");
// Photos
if($database->query("SELECT `description` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` CHANGE `description` `description` VARCHAR( 1000 ) NULL DEFAULT ''");
if(!$database->query("SELECT `tags` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` ADD `tags` VARCHAR( 1000 ) NULL DEFAULT ''");
$database->query("UPDATE `lychee_photos` SET url = replace(url, 'uploads/big/', ''), thumbUrl = replace(thumbUrl, 'uploads/thumb/', '')");
// Settings
$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', '')");
// Config
if ($version!==''&&$configVersion!==$version) {
$data = file_get_contents('../data/config.php');
$data = preg_replace('/\$configVersion = \'[\w. ]*\';/', "\$configVersion = '$version';", $data);
file_put_contents('../data/config.php', $data);
}
return true;
}

View File

@ -9,9 +9,13 @@
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
function init($mode) {
function init($mode, $version) {
global $settings;
global $settings, $configVersion;
// Update
if ($configVersion!==$version)
if (!update($version)) exit('Error: Updating the database failed!');
$return['config'] = $settings;
unset($return['config']['password']);