Przeglądaj źródła

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

Klectik 7 lat temu
rodzic
commit
517481277d
4 zmienionych plików z 26 dodań i 11 usunięć
  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 Wyświetl plik

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

+ 22 - 4
classes/install.class.php Wyświetl plik

@@ -31,7 +31,9 @@ class Install
31 31
             false;
32 32
         }
33 33
 
34
-        $this->create_db();
34
+        if (!$this->create_db()) {
35
+            return false;
36
+        }
35 37
 
36 38
         if (!$this->install_db()) {
37 39
             return false;
@@ -47,7 +49,13 @@ class Install
47 49
         $db_login = $this->data['db_login'];
48 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 60
         if (!$link) {
53 61
             die('Could not connect: ' . $link->errorInfo());
@@ -64,8 +72,7 @@ class Install
64 72
 
65 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 76
         $sqlStr = array();
70 77
 
71 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,6 +106,11 @@ class Install
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 114
         return true;
103 115
     }
104 116
 
@@ -110,6 +122,12 @@ class Install
110 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 131
     public function mostrarerror($n)
114 132
     {
115 133
         if ($this->inerrors($n)) {

+ 0 - 4
config.php Wyświetl plik

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

+ 3 - 3
install.php Wyświetl plik

@@ -36,9 +36,9 @@ $theme = new themes;
36 36
 $theme->set('version', $util_class->version());
37 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 42
 $theme->set('login', isset($install->data['login'])?$install->data['login']:'');
43 43
 $theme->set('email', isset($install->data['email'])?$install->data['email']:'');
44 44
 $theme->set('title', isset($install->data['title'])?$install->data['title']:'');