* install: better error message on database failed connect

* changed <p> tag to <div> in notification messages
This commit is contained in:
slawkens1 2018-01-13 21:18:21 +01:00
parent 9738c1896d
commit fc243466da
11 changed files with 98 additions and 53 deletions

View File

@ -5,8 +5,20 @@ require(SYSTEM . 'libs/pot/OTS.php');
$ots = POT::getInstance();
require(SYSTEM . 'database.php');
if($db->hasTable('accounts'))
define('USE_ACCOUNT_NAME', $db->hasColumn('accounts', 'name'));
else
if(!isset($db)) {
$database_error = $locale['step_database_error_mysql_connect'] . '<br/>' .
$locale['step_database_error_mysql_connect_2'] .
'<ul>' .
'<li>' . $locale['step_database_error_mysql_connect_3'] . '</li>' .
'<li>' . $locale['step_database_error_mysql_connect_4'] . '</li>' .
'</ul>' . '<br/>' . $error;
}
else {
if($db->hasTable('accounts'))
define('USE_ACCOUNT_NAME', $db->hasColumn('accounts', 'name'));
}
if(!defined('USE_ACCOUNT_NAME')) {
define('USE_ACCOUNT_NAME', false);
}
?>

View File

@ -1,6 +1,8 @@
<?php
require('../common.php');
define('MYAAC_INSTALL', true);
// includes
require(SYSTEM . 'functions.php');
require(BASE . 'install/includes/functions.php');

View File

@ -47,46 +47,51 @@ if(!$error) {
success($locale['step_database_importing']);
require(BASE . 'install/includes/database.php');
echo $twig->render('install.installer.html.twig', array(
'url' => 'tools/5-database.php',
'message' => $locale['loading_spinner']
));
if(!$error) {
if(!Validator::email($_SESSION['var_mail_admin'])) {
error($locale['step_config_mail_admin_error']);
$error = true;
}
if(!Validator::email($_SESSION['var_mail_address'])) {
error($locale['step_config_mail_address_error']);
$error = true;
}
if(isset($database_error)) { // we failed connect to the database
error($database_error);
}
else {
echo $twig->render('install.installer.html.twig', array(
'url' => 'tools/5-database.php',
'message' => $locale['loading_spinner']
));
$content .= '$config[\'client_download\'] = \'http://tibia-clients.com/clients/download/\'. $config[\'client\'] . \'/exe/windows\';';
$content .= PHP_EOL;
$content .= '$config[\'client_download_linux\'] = \'http://tibia-clients.com/clients/download/\'. $config[\'client\'] . \'/tar/linux\';';
$content .= PHP_EOL;
$content .= '$config[\'session_prefix\'] = \'myaac_' . generateRandomString(8, true, false, true, false) . '_\';';
$content .= PHP_EOL;
$content .= '$config[\'cache_prefix\'] = \'myaac_' . generateRandomString(8, true, false, true, false) . '_\';';
$saved = true;
if(!$error) {
$saved = file_put_contents(BASE . 'config.local.php', $content);
}
if($saved) {
if(!$error) {
$_SESSION['saved'] = true;
if(!Validator::email($_SESSION['var_mail_admin'])) {
error($locale['step_config_mail_admin_error']);
$error = true;
}
if(!Validator::email($_SESSION['var_mail_address'])) {
error($locale['step_config_mail_address_error']);
$error = true;
}
}
else {
$_SESSION['config_content'] = $content;
unset($_SESSION['saved']);
$locale['step_database_error_file'] = str_replace('$FILE$', '<b>' . BASE . 'config.local.php</b>', $locale['step_database_error_file']);
warning($locale['step_database_error_file'] . '<br/>
<textarea cols="70" rows="10">' . $content . '</textarea>');
$content .= '$config[\'client_download\'] = \'http://tibia-clients.com/clients/download/\'. $config[\'client\'] . \'/exe/windows\';';
$content .= PHP_EOL;
$content .= '$config[\'client_download_linux\'] = \'http://tibia-clients.com/clients/download/\'. $config[\'client\'] . \'/tar/linux\';';
$content .= PHP_EOL;
$content .= '$config[\'session_prefix\'] = \'myaac_' . generateRandomString(8, true, false, true, false) . '_\';';
$content .= PHP_EOL;
$content .= '$config[\'cache_prefix\'] = \'myaac_' . generateRandomString(8, true, false, true, false) . '_\';';
$saved = true;
if(!$error) {
$saved = file_put_contents(BASE . 'config.local.php', $content);
}
if($saved) {
if(!$error) {
$_SESSION['saved'] = true;
}
}
else {
$_SESSION['config_content'] = $content;
unset($_SESSION['saved']);
$locale['step_database_error_file'] = str_replace('$FILE$', '<b>' . BASE . 'config.local.php</b>', $locale['step_database_error_file']);
warning($locale['step_database_error_file'] . '<br/>
<textarea cols="70" rows="10">' . $content . '</textarea>');
}
}
}
}

View File

@ -5,6 +5,10 @@ require(BASE . 'install/includes/config.php');
if(!$error) {
require(BASE . 'install/includes/database.php');
if(isset($database_error)) { // we failed connect to the database
error($database_error);
}
echo $twig->render('install.admin.html.twig', array(
'locale' => $locale,
'session' => $_SESSION,

View File

@ -107,6 +107,8 @@ img {
background-position: 5px 6px;
border-style: solid;
border-width: 1px;
line-height: 1.6em;
margin-bottom: 10px;
}
.error {
background-color: #FDD9D9;

View File

@ -14,29 +14,35 @@ ob_end_flush();
if(!$error) {
require(BASE . 'install/includes/database.php');
if(isset($database_error)) { // we failed connect to the database
error($database_error);
return;
}
}
if(!$db->hasTable('accounts')) {
$locale['step_database_error_table'] = str_replace('$TABLE$', 'accounts', $locale['step_database_error_table']);
error($locale['step_database_error_table']);
$error = true;
return;
}
else if(!$db->hasTable('players')) {
if(!$db->hasTable('players')) {
$locale['step_database_error_table'] = str_replace('$TABLE$', 'players', $locale['step_database_error_table']);
error($locale['step_database_error_table']);
$error = true;
return;
}
else if(!$db->hasTable('guilds')) {
if(!$db->hasTable('guilds')) {
$locale['step_database_error_table'] = str_replace('$TABLE$', 'guilds', $locale['step_database_error_table']);
error($locale['step_database_error_table']);
$error = true;
return;
}
if($db->hasTable(TABLE_PREFIX . 'account_actions')) {
$locale['step_database_error_table_exist'] = str_replace('$TABLE$', TABLE_PREFIX . 'account_actions', $locale['step_database_error_table_exist']);
warning($locale['step_database_error_table_exist']);
}
else if(!$error) {
else {
// import schema
try {
$db->query(file_get_contents(BASE . 'install/includes/schema.sql'));
@ -47,14 +53,10 @@ else if(!$error) {
}
catch(PDOException $error_) {
error($locale['step_database_error_schema'] . ' ' . $error_);
$error = true;
return;
}
}
if($error) {
return;
}
if($db->hasColumn('accounts', 'key')) {
if(query("ALTER TABLE `accounts` MODIFY `key` VARCHAR(64) NOT NULL DEFAULT '';"))
success($locale['step_database_modifying_field'] . ' accounts.key...');

View File

@ -89,11 +89,18 @@ defined('MYAAC') or die('Direct access not allowed!');
'log' => $config['database_log']
)
);
$db = POT::getInstance()->getDBHandle();
}
catch(PDOException $error) {
if(isset($cache) && $cache->enabled()) {
$cache->delete('config_lua');
}
if(defined('MYAAC_INSTALL')) {
return; // installer will take care of this
}
die('ERROR: Cannot connect to MySQL database.<br/>' .
'Possible reasons:' .
'<ul>' .
@ -102,5 +109,4 @@ defined('MYAAC') or die('Direct access not allowed!');
'</ul>' . $error);
}
$db = POT::getInstance()->getDBHandle();
?>

View File

@ -12,9 +12,9 @@ defined('MYAAC') or die('Direct access not allowed!');
function message($message, $type, $return)
{
if($return)
return '<p class="' . $type . '">' . $message . '</p>';
return '<div class="' . $type . '">' . $message . '</div>';
echo '<p class="' . $type . '">' . $message . '</p>';
echo '<div class="' . $type . '">' . $message . '</div>';
return true;
}
function success($message, $return = false) {

View File

@ -70,6 +70,10 @@ $locale['step_database_error_database_empty'] = 'Der Datenbanktyp kann nicht aus
$locale['step_database_error_only_mysql'] = 'Dieser AAC unterstützt nur MySQL. Aus Ihrer Konfigurationsdatei scheint Ihr OTS die Datenbank $DATABASE_TYPE$ zu verwenden. Bitte ändern Sie Ihre Datenbank in MySQL und folgen Sie dann der Installation erneut.';
$locale['step_database_error_table'] = 'Die Tabelle $TABLE$ existiert nicht. Bitte importieren Sie zuerst Ihr OTS-Datenbankschema.';
$locale['step_database_error_table_exist'] = 'Die Tabelle $TABLE$ existiert bereits. Scheint, dass AAC bereits installiert ist. Das Importieren des MySQL-Schemas wird übersprungen..';
$locale['step_database_error_mysql_connect'] = 'Verbindung zur MySQL-Datenbank nicht möglich.';
$locale['step_database_error_mysql_connect_2'] = 'Mögliche Gründe:';
$locale['step_database_error_mysql_connect_3'] = 'MySQL ist nicht richtig konfiguriert in <i>config.lua</i>.';
$locale['step_database_error_mysql_connect_4'] = 'MySQL-Server läuft nicht.';
$locale['step_database_error_schema'] = 'Fehler beim Importieren des Schemas:';
$locale['step_database_success_schema'] = '$PREFIX$ Tabellen wurden erfolgreich installiert.';
$locale['step_database_error_file'] = '$FILE$ konnte nicht geöffnet werden. Bitte kopieren Sie diesen Inhalt und fügen Sie ihn dort ein:';

View File

@ -70,6 +70,10 @@ $locale['step_database_error_database_empty'] = 'Cannot determine database type
$locale['step_database_error_only_mysql'] = 'This AAC supports only MySQL. From your config file it seems that your OTS is using: $DATABASE_TYPE$ database. Please change your database to MySQL and then follow the installation again.';
$locale['step_database_error_table'] = 'Table $TABLE$ doesn\'t exist. Please import your OTS database schema first.';
$locale['step_database_error_table_exist'] = 'Table $TABLE$ already exist. Seems AAC is already installed. Skipping importing MySQL schema..';
$locale['step_database_error_mysql_connect'] = 'Cannot connect to the MySQL database.';
$locale['step_database_error_mysql_connect_2'] = 'Possible reasons:';
$locale['step_database_error_mysql_connect_3'] = 'MySQL is not configured propertly in <i>config.lua</i>.';
$locale['step_database_error_mysql_connect_4'] = 'MySQL server is not running.';
$locale['step_database_error_schema'] = 'Error while importing schema:';
$locale['step_database_success_schema'] = 'Successfully installed $PREFIX$ tables.';
$locale['step_database_error_file'] = '$FILE$ couldn\'t be opened. Please copy this content and paste there:';

View File

@ -65,6 +65,10 @@ $locale['step_database_error_database_empty'] = 'Nie można wykryć typu bazy da
$locale['step_database_error_only_mysql'] = 'Ten AAC wspiera tylko bazy danych MySQL. Z Twojego pliku config wynika, że Twój serwera używa bazy: $DATABASE_TYPE$. Proszę zmienić typ bazy na MySQL i ponownie przystąpić do instalacji.';
$locale['step_database_error_table'] = 'Tabela $TABLE$ nie istnieje. Proszę najpierw zaimportować schemat bazy danych serwera OTS.';
$locale['step_database_error_table_exist'] = 'Tabela $TABLE$ już istnieje. Wygląda na to, że AAC został już zainstalowany. Schemat MySQL nie zostanie zaimportowany..';
$locale['step_database_error_mysql_connect'] = 'Nie udało się połączyć z bazą danych MySQL.';
$locale['step_database_error_mysql_connect_2'] = 'Możliwe przyczyny:';
$locale['step_database_error_mysql_connect_3'] = 'MySQL nie jest poprawnie skonfigurowane w <i>config.lua</i>.';
$locale['step_database_error_mysql_connect_4'] = 'Serwer MySQL nie jest uruchomiony.';
$locale['step_database_error_schema'] = 'Błąd podczas importowania struktury bazy danych:';
$locale['step_database_success_schema'] = 'Pomyślnie zainstalowano tabele $PREFIX$.';
$locale['step_database_error_file'] = '$FILE$ nie mógł zostać otwarty. Proszę skopiować zawartość pola tekstowego i wkleić do tego pliku:';