Setup/Maintenance

* toggle maintenance mode in a more reasonable manner (i.e. not when displaying help test)
 * move connectivity tests to class DB
 * restore generate everything functionality when running --sql and --build with an empty parameter set
This commit is contained in:
Sarjuuk
2021-02-20 19:19:24 +01:00
parent 43778b01e7
commit fbc5d43aab
13 changed files with 130 additions and 113 deletions

View File

@@ -11,7 +11,7 @@ if (!CLI)
/* Account creation */
/********************/
function account()
function account() : void
{
$fields = array(
'name' => ['Username', false],

View File

@@ -11,15 +11,17 @@ if (!CLI)
/* Create required files */
/*************************/
function build($syncMe = null)
function build($syncMe = null) : array
{
require_once 'setup/tools/fileGen.class.php';
FileGen::init($syncMe !== null ? FileGen::MODE_UPDATE : FileGen::MODE_NORMAL, $syncMe ?: []);
if(!FileGen::init($syncMe !== null ? FileGen::MODE_UPDATE : FileGen::MODE_NORMAL, $syncMe ?: []))
return [];
$done = [];
if (FileGen::$subScripts)
{
CLISetup::siteLock(CLISetup::LOCK_ON);
$allOk = true;
// start file generation
@@ -80,6 +82,8 @@ function build($syncMe = null)
CLI::write('successfully finished file generation', CLI::LOG_OK);
else
CLI::write('finished file generation with errors', CLI::LOG_ERROR);
CLISetup::siteLock(CLISetup::LOCK_RESTORE);
}
else if (FileGen::getMode() == FileGen::MODE_NORMAL)
CLI::write('no valid script names supplied', CLI::LOG_ERROR);

View File

@@ -11,7 +11,7 @@ if (!CLI)
/* Configure DB connection*/
/**************************/
function dbconfig()
function dbconfig() : void
{
$databases = ['aowow', 'world', 'auth', 'characters'];
$AoWoWconf = [];
@@ -24,21 +24,11 @@ function dbconfig()
);
$testDB = function($idx, $name, $dbInfo)
{
$buff = '['.CLI::bold($idx).'] '.str_pad($name, 17);
$errStr = '';
$defPort = ini_get('mysqli.default_port');
$port = 0;
if (strstr($dbInfo['host'], ':'))
[$dbInfo['host'], $port] = explode(':', $dbInfo['host']);
$buff = '['.CLI::bold($idx).'] '.str_pad($name, 17);
if ($dbInfo['host'])
{
// test DB
if ($link = @mysqli_connect($dbInfo['host'], $dbInfo['user'], $dbInfo['pass'], $dbInfo['db'], $port ?: $defPort))
mysqli_close($link);
else
$errStr = '['.mysqli_connect_errno().'] '.mysqli_connect_error();
DB::test($dbInfo, $errStr);
$buff .= $errStr ? CLI::red('ERR ') : CLI::green('OK ');
$buff .= 'mysqli://'.$dbInfo['user'].':'.str_pad('', mb_strlen($dbInfo['pass']), '*').'@'.$dbInfo['host'].($port ? ':'.$port : null).'/'.$dbInfo['db'];
@@ -54,10 +44,8 @@ function dbconfig()
require 'config/config.php';
foreach ($databases as $idx => $name)
{
if (empty($AoWoWconf[$name]) && $name != 'characters' )
$AoWoWconf[$name] = array_combine(array_keys($dbFields), ['', '', '', '', '']);
}
while (true)
{

View File

@@ -11,7 +11,7 @@ if (!CLI)
/* string setup steps together for first use */
/*********************************************/
function firstrun() : bool
function setup() : void
{
require_once 'setup/tools/sqlGen.class.php';
require_once 'setup/tools/fileGen.class.php';
@@ -118,26 +118,16 @@ function firstrun() : bool
require 'config/config.php';
$error = [];
$defPort = ini_get('mysqli.default_port');
foreach (['aowow', 'world', 'auth'] as $idx => $what)
foreach (['world', 'aowow', 'auth'] as $idx => $what)
{
if ($what == 'auth' && (empty($AoWoWconf['auth']) || empty($AoWoWconf['auth']['host'])))
continue;
$port = 0;
if (strstr($AoWoWconf[$what]['host'], ':'))
[$AoWoWconf[$what]['host'], $port] = explode(':', $AoWoWconf[$what]['host']);
if ($link = @mysqli_connect($AoWoWconf[$what]['host'], $AoWoWconf[$what]['user'], $AoWoWconf[$what]['pass'], $AoWoWconf[$what]['db'], $port ?: $defPort))
{
mysqli_close($link);
// init proper access for further setup
// init proper access for further setup
if (DB::test($AoWoWconf[$what], $err))
DB::load($idx, $AoWoWconf[$what]);
}
else
$error[] = ' * '.$what.': '.'['.mysqli_connect_errno().'] '.mysqli_connect_error();
$error[] = ' * '.$what.': '.$err;
}
return empty($error);
@@ -247,7 +237,7 @@ function firstrun() : bool
}
CLI::write();
exit;
return;
}
if ($startStep)
@@ -274,6 +264,8 @@ function firstrun() : bool
/* run */
/*******/
CLISetup::siteLock(CLISetup::LOCK_ON);
foreach ($steps as $idx => $step)
{
if ($startStep > $idx)
@@ -288,7 +280,7 @@ function firstrun() : bool
$inp = ['x' => ['Press any key to continue', true]];
if (!CLI::read($inp, true)) // we don't actually care about the input
return false;
return;
}
while (true)
@@ -329,20 +321,21 @@ function firstrun() : bool
case 'r':
break;
case 'a':
return false;
return;
}
}
else
{
CLI::write();
return false;
return;
}
}
}
unlink('cache/firstrun');
CLISetup::siteLock(CLISetup::LOCK_OFF);
CLI::write('setup finished', CLI::LOG_OK);
return true;
return;
}
?>

View File

@@ -11,7 +11,7 @@ if (!CLI)
/* Configure Site variables */
/****************************/
function siteconfig()
function siteconfig() : void
{
$reqKeys = ['site_host', 'static_host'];
$updScripts = [];

View File

@@ -11,15 +11,17 @@ if (!CLI)
/* Create content from world tables / dbc files */
/************************************************/
function sql($syncMe = null)
function sql($syncMe = null) : array
{
require_once 'setup/tools/sqlGen.class.php';
SqlGen::init($syncMe !== null ? SqlGen::MODE_UPDATE : SqlGen::MODE_NORMAL, $syncMe ?: []);
if (!SqlGen::init($syncMe !== null ? SqlGen::MODE_UPDATE : SqlGen::MODE_NORMAL, $syncMe ?: []))
return [];
$done = [];
if (SqlGen::$subScripts)
{
CLISetup::siteLock(CLISetup::LOCK_ON);
$allOk = true;
// start file generation
@@ -46,6 +48,8 @@ function sql($syncMe = null)
CLI::write('successfully finished sql generation', CLI::LOG_OK);
else
CLI::write('finished sql generation with errors', CLI::LOG_ERROR);
CLISetup::siteLock(CLISetup::LOCK_RESTORE);
}
else if (SqlGen::getMode() == SqlGen::MODE_NORMAL)
CLI::write('no valid script names supplied', CLI::LOG_ERROR);

View File

@@ -27,7 +27,7 @@ function sync(array $s = [], array $b = []) : void
CLI::write(' e.g.: "php aowow --sync=creature_queststarter" causes the table aowow_quests_startend to be recreated.', -1, false);
CLI::write(' Also quest-related profiler files will be recreated as they depend on aowow_quests_startend and thus indirectly on creature_queststarter.', -1, false);
CLI::write();
exit;
return;
}
$_s = sql($s);
@@ -43,6 +43,9 @@ function sync(array $s = [], array $b = []) : void
$_ = array_diff($b, $_b);
DB::Aowow()->query('UPDATE ?_dbversion SET `build` = ?', $_ ? implode(' ', $_) : '');
}
if (!$s && !$_s && !$b && !$_b)
CLI::write('no valid table names supplied', CLI::LOG_ERROR);
}
?>

View File

@@ -11,7 +11,7 @@ if (!CLI)
/* automaticly apply sql-updates */
/*********************************/
function update() : array
function update(?array &$sql = [], ?array &$build = []) : void
{
[$date, $part] = array_values(DB::Aowow()->selectRow('SELECT `date`, `part` FROM ?_dbversion'));
@@ -25,10 +25,11 @@ function update() : array
CLI::write();
CLI::write(' Last Update: '.date(Util::$dateFormatInternal, $date).' (Part #'.$part.')', -1, false);
CLI::write();
exit;
return;
}
CLI::write('checking sql updates');
CLISetup::siteLock(CLISetup::LOCK_ON);
$nFiles = 0;
foreach (glob('setup/updates/*.sql') as $file)
@@ -69,6 +70,7 @@ function update() : array
CLI::write(' -> '.date('d.m.Y', $fDate).' #'.$fPart.': '.$nQuerys.' queries applied', CLI::LOG_OK);
}
CLISetup::siteLock(CLISetup::LOCK_RESTORE);
CLI::write($nFiles ? 'applied '.$nFiles.' update(s)' : 'db is already up to date', CLI::LOG_OK);
// fetch sql/build after applying updates, as they may contain sync-prompts
@@ -84,8 +86,6 @@ function update() : array
if ($build)
CLI::write('The following file(s) require syncing: '.implode(', ', $build));
return [$sql, $build];
}
?>