浏览代码

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

Klectik 7 年前
父节点
当前提交
517481277d
共有 4 个文件被更改,包括 26 次插入11 次删除
  1. 1 0
      admin/themes/admin/install.htm
  2. 22 4
      classes/install.class.php
  3. 0 4
      config.php
  4. 3 3
      install.php

+ 1 - 0
admin/themes/admin/install.htm 查看文件

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

+ 22 - 4
classes/install.class.php 查看文件

31
             false;
31
             false;
32
         }
32
         }
33
 
33
 
34
-        $this->create_db();
34
+        if (!$this->create_db()) {
35
+            return false;
36
+        }
35
 
37
 
36
         if (!$this->install_db()) {
38
         if (!$this->install_db()) {
37
             return false;
39
             return false;
47
         $db_login = $this->data['db_login'];
49
         $db_login = $this->data['db_login'];
48
         $db_password = $this->data['db_password'];
50
         $db_password = $this->data['db_password'];
49
 
51
 
50
-        $link = new PDO("mysql:host=$db_host;dbname=$db_name", $db_login, $db_password);
52
+        try {
53
+          $link = new PDO("mysql:host=$db_host;dbname=$db_name", $db_login, $db_password);
54
+        }
55
+        catch (Exception $e)
56
+        {
57
+          return false;
58
+        }
51
 
59
 
52
         if (!$link) {
60
         if (!$link) {
53
             die('Could not connect: ' . $link->errorInfo());
61
             die('Could not connect: ' . $link->errorInfo());
64
 
72
 
65
     public function install_db()
73
     public function install_db()
66
     {
74
     {
67
-        require_once(Absolute_Path.'config.php');
68
-        $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
75
+        $db = new Conexion_Mysql($this->data['db_name'], $this->data['db_host'], $this->data['db_login'], $this->data['db_password']);
69
         $sqlStr = array();
76
         $sqlStr = array();
70
 
77
 
71
         $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;";
78
         $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
             }
106
             }
100
         }
107
         }
101
 
108
 
109
+        if($this->writeConfig($this->data['db_name'], $this->data['db_host'], $this->data['db_login'], $this->data['db_password']) === FALSE)
110
+        {
111
+          return false;
112
+        }
113
+
102
         return true;
114
         return true;
103
     }
115
     }
104
 
116
 
110
         return true;
122
         return true;
111
     }
123
     }
112
 
124
 
125
+    public function writeConfig($name, $host, $login, $password)
126
+    {
127
+      $strToWrite = "define('DB_Server', '$host');\ndefine('DB_name', '$name');\ndefine('DB_User', '$login');\ndefine('DB_Password', '$password');\n";
128
+      return file_put_contents(Absolute_Path.'config.php', $strToWrite, FILE_APPEND | LOCK_EX);
129
+    }
130
+
113
     public function mostrarerror($n)
131
     public function mostrarerror($n)
114
     {
132
     {
115
         if ($this->inerrors($n)) {
133
         if ($this->inerrors($n)) {

+ 0 - 4
config.php 查看文件

13
 
13
 
14
   =========================== */
14
   =========================== */
15
 
15
 
16
-define('DB_Server', 'localhost');
17
-define('DB_name', '');
18
-define('DB_User', '');
19
-define('DB_Password', '');
20
 define('Table_prefix', 'gel_');
16
 define('Table_prefix', 'gel_');

+ 3 - 3
install.php 查看文件

36
 $theme->set('version', $util_class->version());
36
 $theme->set('version', $util_class->version());
37
 $theme->set('showForm', $install->showForm);
37
 $theme->set('showForm', $install->showForm);
38
 
38
 
39
-$theme->set('db_login', isset($install->data['db_login'])? $install->data['db_login'] : DB_User);
40
-$theme->set('db_host', (!empty($install->data['db_host']))? $install->data['db_host'] : DB_Server);
41
-$theme->set('db_name', (!empty($install->data['db_name']))?  $install->data['db_name'] : DB_name);
39
+$theme->set('db_login', isset($install->data['db_login'])? $install->data['db_login'] : '');
40
+$theme->set('db_host', (!empty($install->data['db_host']))? $install->data['db_host'] : '');
41
+$theme->set('db_name', (!empty($install->data['db_name']))?  $install->data['db_name'] : '');
42
 $theme->set('login', isset($install->data['login'])?$install->data['login']:'');
42
 $theme->set('login', isset($install->data['login'])?$install->data['login']:'');
43
 $theme->set('email', isset($install->data['email'])?$install->data['email']:'');
43
 $theme->set('email', isset($install->data['email'])?$install->data['email']:'');
44
 $theme->set('title', isset($install->data['title'])?$install->data['title']:'');
44
 $theme->set('title', isset($install->data['title'])?$install->data['title']:'');