No need to manually edit the config file anymore, the installation is now completly automatic

master
Klectik 2017-03-03 19:10:24 +01:00
parent 16139b48a9
commit 517481277d
4 changed files with 26 additions and 11 deletions

View File

@ -28,6 +28,7 @@
<form action="install.php" method="post" id="config_form" autocomplete="off" class="newpost">
<fieldset class="install">
<legend class="install">Database Settings</legend>
{error.6}
<ul>
<li><label for="login">User:</label>
<input type="text" name="db_login" id="db_login" value="{db_login}" class="txt"/>{error.10}</li>

View File

@ -31,7 +31,9 @@ class Install
false;
}
$this->create_db();
if (!$this->create_db()) {
return false;
}
if (!$this->install_db()) {
return false;
@ -47,7 +49,13 @@ class Install
$db_login = $this->data['db_login'];
$db_password = $this->data['db_password'];
$link = new PDO("mysql:host=$db_host;dbname=$db_name", $db_login, $db_password);
try {
$link = new PDO("mysql:host=$db_host;dbname=$db_name", $db_login, $db_password);
}
catch (Exception $e)
{
return false;
}
if (!$link) {
die('Could not connect: ' . $link->errorInfo());
@ -64,8 +72,7 @@ class Install
public function install_db()
{
require_once(Absolute_Path.'config.php');
$db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
$db = new Conexion_Mysql($this->data['db_name'], $this->data['db_host'], $this->data['db_login'], $this->data['db_password']);
$sqlStr = array();
$sqlStr[] = "CREATE TABLE `".Table_prefix."data` ( `id_post` INT(11) NOT NULL AUTO_INCREMENT , `title` TEXT NULL , `url` VARCHAR(250) NULL DEFAULT NULL , `description` TEXT NULL , `type` TINYINT(4) NOT NULL DEFAULT '1' , `date` DATETIME NOT NULL , `id_user` INT(10) NOT NULL , PRIMARY KEY (`id_post`)) ENGINE = MyISAM;";
@ -99,6 +106,11 @@ class Install
}
}
if($this->writeConfig($this->data['db_name'], $this->data['db_host'], $this->data['db_login'], $this->data['db_password']) === FALSE)
{
return false;
}
return true;
}
@ -110,6 +122,12 @@ class Install
return true;
}
public function writeConfig($name, $host, $login, $password)
{
$strToWrite = "define('DB_Server', '$host');\ndefine('DB_name', '$name');\ndefine('DB_User', '$login');\ndefine('DB_Password', '$password');\n";
return file_put_contents(Absolute_Path.'config.php', $strToWrite, FILE_APPEND | LOCK_EX);
}
public function mostrarerror($n)
{
if ($this->inerrors($n)) {

View File

@ -13,8 +13,4 @@ if (!defined('entry') || !entry) {
=========================== */
define('DB_Server', 'localhost');
define('DB_name', '');
define('DB_User', '');
define('DB_Password', '');
define('Table_prefix', 'gel_');

View File

@ -36,9 +36,9 @@ $theme = new themes;
$theme->set('version', $util_class->version());
$theme->set('showForm', $install->showForm);
$theme->set('db_login', isset($install->data['db_login'])? $install->data['db_login'] : DB_User);
$theme->set('db_host', (!empty($install->data['db_host']))? $install->data['db_host'] : DB_Server);
$theme->set('db_name', (!empty($install->data['db_name']))? $install->data['db_name'] : DB_name);
$theme->set('db_login', isset($install->data['db_login'])? $install->data['db_login'] : '');
$theme->set('db_host', (!empty($install->data['db_host']))? $install->data['db_host'] : '');
$theme->set('db_name', (!empty($install->data['db_name']))? $install->data['db_name'] : '');
$theme->set('login', isset($install->data['login'])?$install->data['login']:'');
$theme->set('email', isset($install->data['email'])?$install->data['email']:'');
$theme->set('title', isset($install->data['title'])?$install->data['title']:'');