From 517481277da3b5ca2e637664af3e2ff28e2acee0 Mon Sep 17 00:00:00 2001 From: Klectik Date: Fri, 3 Mar 2017 19:10:24 +0100 Subject: [PATCH] No need to manually edit the config file anymore, the installation is now completly automatic --- admin/themes/admin/install.htm | 1 + classes/install.class.php | 26 ++++++++++++++++++++++---- config.php | 4 ---- install.php | 6 +++--- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/admin/themes/admin/install.htm b/admin/themes/admin/install.htm index 3294cfa..253d4d3 100755 --- a/admin/themes/admin/install.htm +++ b/admin/themes/admin/install.htm @@ -28,6 +28,7 @@
Database Settings + {error.6}
  • {error.10}
  • diff --git a/classes/install.class.php b/classes/install.class.php index 9d64de4..2a3dabc 100755 --- a/classes/install.class.php +++ b/classes/install.class.php @@ -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)) { diff --git a/config.php b/config.php index fef9a5c..869a9cd 100755 --- a/config.php +++ b/config.php @@ -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_'); diff --git a/install.php b/install.php index bf9a4d6..c83fb24 100755 --- a/install.php +++ b/install.php @@ -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']:'');