@@ -114,100 +114,76 @@ function step2Action()
114
114
$ form = $ this ->Form ->Install ->createDBForm ($ type );
115
115
if ($ form ->isValid ($ this ->getRequest ()->getPost ()))
116
116
{
117
- $ databaseConfig = parse_ini_file (CORE_CONFIGS_PATH . '/database.ini ' , true );
117
+ $ configDatabase = parse_ini_file (CORE_CONFIGS_PATH . '/database.ini ' , true );
118
118
require_once BASE_PATH . '/core/controllers/components/UpgradeComponent.php ' ;
119
119
$ upgradeComponent = new UpgradeComponent ();
120
120
$ upgradeComponent ->dir = BASE_PATH . '/core/database/ ' .$ type ;
121
121
$ upgradeComponent ->init = true ;
122
122
$ sqlFile = $ upgradeComponent ->getNewestVersion (true );
123
123
$ sqlFile = BASE_PATH . '/core/database/ ' .$ type .'/ ' .$ sqlFile .'.sql ' ;
124
+
124
125
if (!isset ($ sqlFile ) || !file_exists ($ sqlFile ))
125
126
{
126
127
throw new Zend_Exception ('Unable to find sql file ' );
127
128
}
128
129
129
- switch ($ type )
130
+ $ dbtype = 'PDO_ ' . strtoupper ($ type );
131
+ $ version = str_replace ('.sql ' , '' , basename ($ sqlFile ));
132
+
133
+ $ configDatabase ['production ' ]['database.type ' ] = 'pdo ' ;
134
+ $ configDatabase ['production ' ]['database.adapter ' ] = $ dbtype ;
135
+ $ configDatabase ['production ' ]['database.params.host ' ] = $ form ->getValue ('host ' );
136
+ $ configDatabase ['production ' ]['database.params.port ' ] = $ form ->getValue ('port ' );
137
+ $ configDatabase ['production ' ]['database.params.unix_socket ' ] = $ form ->getValue ('unix_socket ' );
138
+ $ configDatabase ['production ' ]['database.params.dbname ' ] = $ form ->getValue ('dbname ' );
139
+ $ configDatabase ['production ' ]['database.params.username ' ] = $ form ->getValue ('username ' );
140
+ $ configDatabase ['production ' ]['database.params.password ' ] = $ form ->getValue ('password ' );
141
+ $ configDatabase ['production ' ]['version ' ] = $ version ;
142
+
143
+ $ configDatabase ['development ' ]['database.type ' ] = 'pdo ' ;
144
+ $ configDatabase ['development ' ]['database.adapter ' ] = $ dbtype ;
145
+ $ configDatabase ['development ' ]['database.params.host ' ] = $ form ->getValue ('host ' );
146
+ $ configDatabase ['development ' ]['database.params.port ' ] = $ form ->getValue ('port ' );
147
+ $ configDatabase ['development ' ]['database.params.unix_socket ' ] = $ form ->getValue ('unix_socket ' );
148
+ $ configDatabase ['development ' ]['database.params.dbname ' ] = $ form ->getValue ('dbname ' );
149
+ $ configDatabase ['development ' ]['database.params.username ' ] = $ form ->getValue ('username ' );
150
+ $ configDatabase ['development ' ]['database.params.password ' ] = $ form ->getValue ('password ' );
151
+ $ configDatabase ['development ' ]['version ' ] = $ version ;
152
+
153
+ $ driverOptions = array ();
154
+ $ params = array (
155
+ 'dbname ' => $ form ->getValue ('dbname ' ),
156
+ 'username ' => $ form ->getValue ('username ' ),
157
+ 'password ' => $ form ->getValue ('password ' ),
158
+ 'driver_options ' => $ driverOptions );
159
+ $ unixsocket = $ form ->getValue ('unix_socket ' );
160
+ if ($ unixsocket )
130
161
{
131
- case 'mysql ' :
132
- $ this ->Component ->Utility ->run_mysql_from_file ($ sqlFile ,
133
- $ form ->getValue ('host ' ), $ form ->getValue ('username ' ), $ form ->getValue ('password ' ), $ form ->getValue ('dbname ' ), $ form ->getValue ('port ' ));
134
- $ params = array (
135
- 'host ' => $ form ->getValue ('host ' ),
136
- 'username ' => $ form ->getValue ('username ' ),
137
- 'password ' => $ form ->getValue ('password ' ),
138
- 'dbname ' => $ form ->getValue ('dbname ' ),
139
- 'port ' => $ form ->getValue ('port ' ),
140
- );
141
-
142
- $ databaseConfig ['production ' ]['database.type ' ] = 'pdo ' ;
143
- $ databaseConfig ['development ' ]['database.type ' ] = 'pdo ' ;
144
- $ databaseConfig ['production ' ]['database.adapter ' ] = 'PDO_MYSQL ' ;
145
- $ databaseConfig ['development ' ]['database.adapter ' ] = 'PDO_MYSQL ' ;
146
- $ databaseConfig ['production ' ]['database.params.host ' ] = $ form ->getValue ('host ' );
147
- $ databaseConfig ['development ' ]['database.params.host ' ] = $ form ->getValue ('host ' );
148
- $ databaseConfig ['production ' ]['database.params.username ' ] = $ form ->getValue ('username ' );
149
- $ databaseConfig ['development ' ]['database.params.username ' ] = $ form ->getValue ('username ' );
150
- $ databaseConfig ['production ' ]['database.params.password ' ] = $ form ->getValue ('password ' );
151
- $ databaseConfig ['development ' ]['database.params.password ' ] = $ form ->getValue ('password ' );
152
- $ databaseConfig ['production ' ]['database.params.dbname ' ] = $ form ->getValue ('dbname ' );
153
- $ databaseConfig ['development ' ]['database.params.dbname ' ] = $ form ->getValue ('dbname ' );
154
- $ databaseConfig ['development ' ]['database.params.port ' ] = $ form ->getValue ('port ' );
155
- $ databaseConfig ['production ' ]['database.params.port ' ] = $ form ->getValue ('port ' );
156
-
157
- $ db = Zend_Db::factory ('PDO_MYSQL ' , $ params );
158
- Zend_Db_Table::setDefaultAdapter ($ db );
159
- Zend_Registry::set ('dbAdapter ' , $ db );
160
-
161
- $ dbtype = 'PDO_MYSQL ' ;
162
- break ;
163
- case 'pgsql ' :
164
- $ this ->Component ->Utility ->run_pgsql_from_file ($ sqlFile ,
165
- $ form ->getValue ('host ' ), $ form ->getValue ('username ' ), $ form ->getValue ('password ' ), $ form ->getValue ('dbname ' ), $ form ->getValue ('port ' ));
166
- $ params = array (
167
- 'host ' => $ form ->getValue ('host ' ),
168
- 'username ' => $ form ->getValue ('username ' ),
169
- 'password ' => $ form ->getValue ('password ' ),
170
- 'dbname ' => $ form ->getValue ('dbname ' ),
171
- 'port ' => $ form ->getValue ('port ' ),
172
- );
173
-
174
- $ databaseConfig ['production ' ]['database.type ' ] = 'pdo ' ;
175
- $ databaseConfig ['development ' ]['database.type ' ] = 'pdo ' ;
176
- $ databaseConfig ['production ' ]['database.adapter ' ] = 'PDO_PGSQL ' ;
177
- $ databaseConfig ['development ' ]['database.adapter ' ] = 'PDO_PGSQL ' ;
178
- $ databaseConfig ['production ' ]['database.params.host ' ] = $ form ->getValue ('host ' );
179
- $ databaseConfig ['development ' ]['database.params.host ' ] = $ form ->getValue ('host ' );
180
- $ databaseConfig ['production ' ]['database.params.username ' ] = $ form ->getValue ('username ' );
181
- $ databaseConfig ['development ' ]['database.params.username ' ] = $ form ->getValue ('username ' );
182
- $ databaseConfig ['production ' ]['database.params.password ' ] = $ form ->getValue ('password ' );
183
- $ databaseConfig ['development ' ]['database.params.password ' ] = $ form ->getValue ('password ' );
184
- $ databaseConfig ['production ' ]['database.params.dbname ' ] = $ form ->getValue ('dbname ' );
185
- $ databaseConfig ['development ' ]['database.params.dbname ' ] = $ form ->getValue ('dbname ' );
186
- $ databaseConfig ['development ' ]['database.params.port ' ] = $ form ->getValue ('port ' );
187
- $ databaseConfig ['production ' ]['database.params.port ' ] = $ form ->getValue ('port ' );
188
-
189
- $ db = Zend_Db::factory ('PDO_PGSQL ' , $ params );
190
- Zend_Db_Table::setDefaultAdapter ($ db );
191
- Zend_Registry::set ('dbAdapter ' , $ db );
192
- $ dbtype = 'PDO_PGSQL ' ;
193
- break ;
194
- default :
195
- break ;
162
+ $ params ['unix_socket ' ] = $ unixsocket ;
196
163
}
197
- $ databaseConfig ['production ' ]['version ' ] = str_replace ('.sql ' , '' , basename ($ sqlFile ));
198
- $ databaseConfig ['development ' ]['version ' ] = str_replace ('.sql ' , '' , basename ($ sqlFile ));
164
+ else
165
+ {
166
+ $ params ['host ' ] = $ form ->getValue ('host ' );
167
+ $ params ['port ' ] = $ form ->getValue ('port ' );
168
+ }
169
+
170
+ $ db = Zend_Db::factory ($ dbtype , $ params );
171
+ $ this ->Component ->Utility ->run_sql_from_file ($ db , $ sqlFile );
172
+
173
+ Zend_Db_Table::setDefaultAdapter ($ db );
174
+ Zend_Registry::set ('dbAdapter ' , $ db );
199
175
200
- $ this ->Component ->Utility ->createInitFile (LOCAL_CONFIGS_PATH . '/database.local.ini ' , $ databaseConfig );
176
+ $ this ->Component ->Utility ->createInitFile (LOCAL_CONFIGS_PATH . '/database.local.ini ' , $ configDatabase );
201
177
202
178
// Must generate and store our password salt before we create our first user
203
- $ appConfig = parse_ini_file (CORE_CONFIGS_PATH . '/application.ini ' , true );
204
- $ appConfig ['global ' ]['password.prefix ' ] = UtilityComponent::generateRandomString (32 );
179
+ $ configApplication = parse_ini_file (CORE_CONFIGS_PATH . '/application.ini ' , true );
180
+ $ configApplication ['global ' ]['password.prefix ' ] = UtilityComponent::generateRandomString (32 );
205
181
206
182
// Verify whether the user wants to use gravatars or not
207
- $ appConfig ['global ' ]['gravatar ' ] = $ form ->getValue ('gravatar ' );
183
+ $ configApplication ['global ' ]['gravatar ' ] = $ form ->getValue ('gravatar ' );
208
184
209
185
// Save the new config
210
- $ this ->Component ->Utility ->createInitFile (LOCAL_CONFIGS_PATH . '/application.local.ini ' , $ appConfig );
186
+ $ this ->Component ->Utility ->createInitFile (LOCAL_CONFIGS_PATH . '/application.local.ini ' , $ configApplication );
211
187
$ configGlobal = new Zend_Config_Ini (LOCAL_CONFIGS_PATH . '/application.local.ini ' , 'global ' , true );
212
188
Zend_Registry::set ('configGlobal ' , $ configGlobal );
213
189
@@ -268,6 +244,7 @@ function step3Action()
268
244
269
245
$ this ->view ->form = $ formArray ;
270
246
$ this ->view ->databaseType = Zend_Registry::get ('configDatabase ' )->database ->adapter ;
247
+
271
248
if ($ this ->_request ->isPost () && $ form ->isValid ($ this ->getRequest ()->getPost ()))
272
249
{
273
250
$ allModules = $ this ->Component ->Utility ->getAllModules ();
@@ -279,6 +256,7 @@ function step3Action()
279
256
unlink ($ configLocal );
280
257
}
281
258
}
259
+
282
260
$ applicationConfig ['global ' ]['application.name ' ] = $ form ->getValue ('name ' );
283
261
$ applicationConfig ['global ' ]['application.description ' ] = $ form ->getValue ('description ' );
284
262
$ applicationConfig ['global ' ]['application.keywords ' ] = $ form ->getValue ('keywords ' );
@@ -301,12 +279,23 @@ public function testconnectionAction()
301
279
$ this ->_helper ->viewRenderer ->setNoRender ();
302
280
try
303
281
{
304
- $ db = Zend_Db:: factory ( ' PDO_ ' . strtoupper ( $ this -> _getParam ( ' type ' )), array (
305
- ' host ' => $ this -> _getParam ( ' host ' ),
306
- 'port ' => $ this ->_getParam ('port ' ),
282
+ $ driverOptions = array ();
283
+ $ params = array (
284
+ 'dbname ' => $ this ->_getParam ('dbname ' ),
307
285
'username ' => $ this ->_getParam ('username ' ),
308
286
'password ' => $ this ->_getParam ('password ' ),
309
- 'dbname ' => $ this ->_getParam ('dbname ' )));
287
+ 'driver_options ' => $ driverOptions );
288
+ $ unixsocket = $ this ->_getParam ('unix_socket ' );
289
+ if ($ unixsocket )
290
+ {
291
+ $ params ['unix_socket ' ] = $ this ->_getParam ('unix_socket ' );
292
+ }
293
+ else
294
+ {
295
+ $ params ['host ' ] = $ this ->_getParam ('host ' );
296
+ $ params ['port ' ] = $ this ->_getParam ('port ' );
297
+ }
298
+ $ db = Zend_Db::factory ('PDO_ ' . strtoupper ($ this ->_getParam ('type ' )), $ params );
310
299
$ tables = $ db ->listTables ();
311
300
if (count ($ tables ) > 0 )
312
301
{
@@ -320,7 +309,7 @@ public function testconnectionAction()
320
309
}
321
310
catch (Zend_Exception $ exception )
322
311
{
323
- $ return = array (false , 'Could not connect to the database server: ' . $ exception -> getMessage () );
312
+ $ return = array (false , 'Could not connect to the database ' );
324
313
}
325
314
echo JsonComponent::encode ($ return );
326
315
}
0 commit comments