mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Make installer more responsive
Update each schema in update.php after applying Packaged new build.sql bundling all updates up to 067
This commit is contained in:
@@ -13,11 +13,8 @@ if ($sql_fh === false) {
|
||||
echo 'ERROR: Cannot open SQL build script '.$sql_file."\n";
|
||||
exit(1);
|
||||
}
|
||||
if (is_resource($test_db)) {
|
||||
$database_link = &$test_db;
|
||||
} else {
|
||||
$database_link = mysqli_connect('p:'.$config['db_host'], $config['db_user'], $config['db_pass']);
|
||||
}
|
||||
|
||||
$database_link = mysqli_connect('p:'.$config['db_host'], $config['db_user'], $config['db_pass']);
|
||||
if ($database_link === false) {
|
||||
echo 'ERROR: Cannot connect to database: '.mysqli_error($database_link)."\n";
|
||||
exit(1);
|
||||
@@ -29,11 +26,26 @@ if ($select === false) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$limit = 0;
|
||||
while (!feof($sql_fh)) {
|
||||
$line = fgetss($sql_fh);
|
||||
if (isset($_SESSION['stage']) ) {
|
||||
$limit++;
|
||||
if (isset($_SESSION['offset']) && $limit < $_REQUEST['offset']) {
|
||||
continue;
|
||||
}
|
||||
elseif ( abs($limit-$_REQUEST['offset']) > 6) {
|
||||
$_SESSION['offset'] = $limit;
|
||||
echo '<b>Installing, please wait..</b><sub>'.date('r').'</sub><script>window.location.href = "install.php?offset='.$limit.'";</script>';
|
||||
return;
|
||||
} else {
|
||||
echo 'Step #'.$limit.' ...'.PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($line)) {
|
||||
$creation = mysqli_query($database_link, $line);
|
||||
if (!$creation) {
|
||||
if (!$creation && ($limit <= 100 || $limit > 391) ) {
|
||||
echo 'WARNING: Cannot execute query ('.$line.'): '.mysqli_error($database_link)."\n";
|
||||
}
|
||||
}
|
||||
@@ -41,4 +53,9 @@ while (!feof($sql_fh)) {
|
||||
|
||||
fclose($sql_fh);
|
||||
|
||||
require 'includes/sql-schema/update.php';
|
||||
if( !isset($_SESSION['stage']) ) {
|
||||
require 'includes/sql-schema/update.php';
|
||||
} else {
|
||||
$_SESSION['build-ok'] = true;
|
||||
dbInsert(array('version' => 67), 'dbSchema');
|
||||
}
|
||||
|
@@ -1,9 +1,16 @@
|
||||
<?php
|
||||
session_start();
|
||||
if( empty($_POST) && !empty($_SESSION) && !isset($_REQUEST['stage'])) {
|
||||
$_POST = $_SESSION;
|
||||
} else {
|
||||
$_SESSION = $_POST;
|
||||
}
|
||||
|
||||
$stage = $_POST['stage'];
|
||||
|
||||
// Before we do anything, if we see config.php, redirect back to the homepage.
|
||||
if(file_exists('../config.php') && $stage != "6") {
|
||||
session_destroy();
|
||||
header("Location: /");
|
||||
exit;
|
||||
}
|
||||
@@ -11,13 +18,13 @@ if(file_exists('../config.php') && $stage != "6") {
|
||||
// List of php modules we expect to see
|
||||
$modules = array('gd','mysql','snmp','mcrypt');
|
||||
|
||||
$dbhost = $_POST['dbhost'] ?: 'localhost';
|
||||
$dbuser = $_POST['dbuser'] ?: 'librenms';
|
||||
$dbpass = $_POST['dbpass'] ?: '';
|
||||
$dbname = $_POST['dbname'] ?: 'librenms';
|
||||
$add_user = $_POST['add_user'] ?: '';
|
||||
$add_pass = $_POST['add_pass'] ?: '';
|
||||
$add_email = $_POST['add_email'] ?: '';
|
||||
$dbhost = @$_POST['dbhost'] ?: 'localhost';
|
||||
$dbuser = @$_POST['dbuser'] ?: 'librenms';
|
||||
$dbpass = @$_POST['dbpass'] ?: '';
|
||||
$dbname = @$_POST['dbname'] ?: 'librenms';
|
||||
$add_user = @$_POST['add_user'] ?: '';
|
||||
$add_pass = @$_POST['add_pass'] ?: '';
|
||||
$add_email = @$_POST['add_email'] ?: '';
|
||||
|
||||
if($stage == "4" || $stage == "3") {
|
||||
// Ok now let's set the db connection up
|
||||
@@ -47,24 +54,24 @@ require '../includes/functions.php';
|
||||
require 'includes/functions.inc.php';
|
||||
|
||||
// Check we can connect to MySQL DB, if not, back to stage 1 :)
|
||||
if($stage == 2) {
|
||||
$test_db = mysqli_connect('p:'.$dbhost,$dbuser,$dbpass,$dbname);
|
||||
if($stage == 2 || $stage == 3) {
|
||||
$database_link = mysqli_connect('p:'.$dbhost,$dbuser,$dbpass,$dbname);
|
||||
if(mysqli_connect_error()) {
|
||||
$stage = 1;
|
||||
$msg = "Couldn't connect to the database, please check your details<br /> " . mysqli_connect_error();
|
||||
}
|
||||
else {
|
||||
$sql = "SELECT * FROM users LIMIT 1";
|
||||
if(mysqli_query($test_db,$sql)) {
|
||||
$stage = 3;
|
||||
$msg = "It appears that the database is already setup so have moved onto stage $stage";
|
||||
elseif ($stage != 3) {
|
||||
if($_SESSION['build-ok'] == true) {
|
||||
$stage = 3;
|
||||
$msg = "It appears that the database is already setup so have moved onto stage $stage";
|
||||
}
|
||||
}
|
||||
$_SESSION['stage'] = $stage;
|
||||
}
|
||||
elseif($stage == "4") {
|
||||
// Now check we have a username, password and email before adding new user
|
||||
if(empty($add_user) || empty($add_pass) || empty($add_email)) {
|
||||
$stage = 4;
|
||||
$stage = 3;
|
||||
$msg = "You haven't entered enough information to add the user account, please check below and re-try";
|
||||
}
|
||||
}
|
||||
@@ -302,6 +309,7 @@ elseif($stage == "2") {
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h5 class="text-center">Importing MySQL DB - Do not close this page or interrupt the import</h5>
|
||||
<pre>
|
||||
<?php
|
||||
// Ok now let's set the db connection up
|
||||
$config['db_host']=$dbhost;
|
||||
@@ -312,6 +320,7 @@ elseif($stage == "2") {
|
||||
$sql_file = '../build.sql';
|
||||
require '../build-base.php';
|
||||
?>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
</div>
|
||||
|
@@ -147,17 +147,16 @@ foreach ($filelist as $file) {
|
||||
|
||||
$updating++;
|
||||
$db_rev = $filename;
|
||||
if ($insert) {
|
||||
dbInsert(array('version' => $db_rev), 'dbSchema');
|
||||
}
|
||||
else {
|
||||
dbUpdate(array('version' => $db_rev), 'dbSchema');
|
||||
}
|
||||
}//end if
|
||||
}//end foreach
|
||||
|
||||
if ($updating) {
|
||||
if ($insert) {
|
||||
dbInsert(array('version' => $db_rev), 'dbSchema');
|
||||
}
|
||||
else {
|
||||
dbUpdate(array('version' => $db_rev), 'dbSchema');
|
||||
}
|
||||
|
||||
echo "-- Done\n";
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user