2016-09-14 10:53:04 -05:00
|
|
|
#!/usr/bin/env php
|
2013-10-28 18:40:48 -07:00
|
|
|
<?php
|
|
|
|
|
2017-04-06 16:02:37 -05:00
|
|
|
if (!isset($init_modules)) {
|
|
|
|
$init_modules = array();
|
|
|
|
require __DIR__ . '/includes/init.php';
|
|
|
|
|
|
|
|
$options = getopt('d');
|
|
|
|
$debug = isset($options['d']);
|
|
|
|
}
|
2013-10-28 18:40:48 -07:00
|
|
|
|
2014-08-14 08:06:49 +10:00
|
|
|
if (!isset($sql_file)) {
|
2015-07-13 20:10:26 +02:00
|
|
|
$sql_file = 'build.sql';
|
2014-08-14 08:06:49 +10:00
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
|
|
|
$sql_fh = fopen($sql_file, 'r');
|
|
|
|
if ($sql_fh === false) {
|
2017-04-06 16:02:37 -05:00
|
|
|
echo 'ERROR: Cannot open SQL build script '.$sql_file.PHP_EOL;
|
2015-07-13 20:10:26 +02:00
|
|
|
exit(1);
|
2014-08-14 08:06:49 +10:00
|
|
|
}
|
|
|
|
|
2017-04-06 16:02:37 -05:00
|
|
|
// only import build.sql to an empty database
|
|
|
|
$tables = dbFetchRows("SHOW TABLES FROM {$config['db_name']}");
|
|
|
|
if (empty($tables)) {
|
|
|
|
$limit = 0;
|
|
|
|
|
|
|
|
while (!feof($sql_fh)) {
|
|
|
|
$line = fgetss($sql_fh);
|
|
|
|
if (isset($_SESSION['stage'])) {
|
|
|
|
$limit++;
|
|
|
|
if (isset($_SESSION['offset']) && $limit < $_REQUEST['offset']) {
|
|
|
|
continue;
|
|
|
|
} elseif (time()-$_SESSION['last'] > 45) {
|
|
|
|
$_SESSION['offset'] = $limit;
|
|
|
|
$GLOBALS['refresh'] = '<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;
|
|
|
|
}
|
2015-09-01 22:42:02 +01:00
|
|
|
}
|
|
|
|
|
2017-04-06 16:02:37 -05:00
|
|
|
if (!empty($line)) {
|
|
|
|
$creation = dbQuery($line);
|
|
|
|
if (!$creation) {
|
|
|
|
echo 'WARNING: Cannot execute query ('.$line.'): '.mysqli_error($database_link)."\n";
|
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
2014-01-15 02:51:25 +00:00
|
|
|
}
|
2013-10-28 18:40:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose($sql_fh);
|
2015-09-01 23:31:41 +01:00
|
|
|
|
|
|
|
require 'includes/sql-schema/update.php';
|