@@ -33,83 +33,78 @@ class InstallController extends AppController
33
33
*/
34
34
function init ()
35
35
{
36
- if (file_exists (BASE_PATH . '/core/configs/database.local.ini ' ) &&
37
- file_exists (BASE_PATH . '/core/configs/application.local.ini ' ) &&
36
+ if (file_exists (BASE_PATH . '/core/configs/database.local.ini ' ) &&
37
+ file_exists (BASE_PATH . '/core/configs/application.local.ini ' ) &&
38
38
Zend_Controller_Front::getInstance ()->getRequest ()->getActionName () != 'step3 ' )
39
39
{
40
- throw new Zend_Exception (" Midas is already installed. " );
40
+ throw new Zend_Exception (' Midas is already installed. ' );
41
41
}
42
- } //end init
42
+ }
43
43
44
44
/**
45
45
* @method indexAction()
46
46
*/
47
47
function indexAction ()
48
48
{
49
- if (file_exists (BASE_PATH . " /core/configs/database.local.ini " ))
49
+ if (file_exists (BASE_PATH . ' /core/configs/database.local.ini ' ))
50
50
{
51
51
$ this ->_redirect ('/install/step3 ' );
52
52
}
53
- $ this ->view ->header = " Step1 : Server Configuration" ;
54
- // Check PHP extension / function
53
+ $ this ->view ->header = ' Step 1 : Server Configuration' ;
54
+ // Check PHP extensions / functions
55
55
$ phpextensions = array (
56
- " simplexml " => array (false , "" ),
56
+ ' simplexml ' => array (false , '' ),
57
57
);
58
58
$ this ->view ->phpextension_missing = $ this ->Component ->Utility ->checkPhpExtensions ($ phpextensions );
59
- $ this ->view ->writable = is_writable (BASE_PATH . '/core/configs ' );
59
+ $ this ->view ->writable = is_writable (BASE_PATH . '/core/configs ' );
60
60
$ this ->view ->basePath = BASE_PATH ;
61
61
if (!empty ($ _POST ) && $ this ->view ->writable )
62
62
{
63
- $ this ->_redirect (" /install/step2 " );
63
+ $ this ->_redirect (' /install/step2 ' );
64
64
}
65
- } // end method indexAction
65
+ }
66
66
67
67
/**
68
68
* @method step2Action()
69
69
*/
70
70
function step2Action ()
71
71
{
72
- if (file_exists (BASE_PATH . " /core/configs/database.local.ini " ))
72
+ if (file_exists (BASE_PATH . ' /core/configs/database.local.ini ' ))
73
73
{
74
74
$ this ->_redirect ('/install/step3 ' );
75
75
}
76
- $ this ->view ->header = "Step2: Database Configuration " ;
77
- // Check PHP extension / function
78
- $ phpextensions = array (
79
- "mysql " => array (false , '' ),
80
- "pgsql " => array (false , '' ),
81
- "oci " => array (false , '' ),
82
- "sqlite " => array (false , '' ),
83
- "ibm " => array (false , '' ),
84
- );
76
+ $ this ->view ->header = 'Step 2: Database Configuration ' ;
85
77
78
+ $ databases = array ('mysql ' , 'pgsql ' );
86
79
$ this ->view ->databaseType = array ();
87
-
88
- foreach ($ phpextensions as $ key => $ t )
80
+ foreach ($ databases as $ database )
89
81
{
90
- if (!file_exists (BASE_PATH . " /core/database/ " . $ key ))
82
+ if (!extension_loaded ( $ database ) || ! file_exists (BASE_PATH . ' /core/database/ ' . $ database ))
91
83
{
92
- unset($ phpextensions [ $ key ] );
84
+ unset($ database );
93
85
}
94
86
else
95
87
{
96
- $ form = $ this ->Form ->Install ->createDBForm ($ key );
88
+ $ form = $ this ->Form ->Install ->createDBForm ($ database );
97
89
$ port = $ form ->getElement ('port ' );
98
- switch ($ key )
90
+ $ username = $ form ->getElement ('username ' );
91
+ switch ($ database )
99
92
{
100
93
case 'mysql ' :
101
94
$ port ->setValue ('3306 ' );
95
+ $ username ->setValue ('root ' );
102
96
break ;
103
97
case 'pgsql ' :
104
98
$ port ->setValue ('5432 ' );
99
+ $ username ->setValue ('postgres ' );
105
100
break ;
106
101
default :
107
102
break ;
108
103
}
109
- $ this ->view ->databaseType [$ key ] = $ this ->getFormAsArray ($ form );
104
+ $ this ->view ->databaseType [$ database ] = $ this ->getFormAsArray ($ form );
110
105
}
111
106
}
112
- $ this -> view -> phpextension_missing = $ this -> Component -> Utility -> checkPhpExtensions ( $ phpextensions );
107
+
113
108
$ this ->view ->writable = is_writable (BASE_PATH );
114
109
$ this ->view ->basePath = BASE_PATH ;
115
110
@@ -119,18 +114,16 @@ function step2Action()
119
114
$ form = $ this ->Form ->Install ->createDBForm ($ type );
120
115
if ($ form ->isValid ($ this ->getRequest ()->getPost ()))
121
116
{
122
- $ databaseConfig = parse_ini_file (BASE_PATH .'/core/configs/database.ini ' , true );
123
- $ MyDirectory = opendir (BASE_PATH ."/core/database/ " .$ type );
124
-
125
- require_once BASE_PATH .'/core/controllers/components/UpgradeComponent.php ' ;
117
+ $ databaseConfig = parse_ini_file (BASE_PATH . '/core/configs/database.ini ' , true );
118
+ require_once BASE_PATH . '/core/controllers/components/UpgradeComponent.php ' ;
126
119
$ upgradeComponent = new UpgradeComponent ();
127
- $ upgradeComponent ->dir = BASE_PATH . " /core/database/ " .$ type ;
120
+ $ upgradeComponent ->dir = BASE_PATH . ' /core/database/ ' .$ type ;
128
121
$ upgradeComponent ->init = true ;
129
122
$ sqlFile = $ upgradeComponent ->getNewestVersion (true );
130
- $ sqlFile = BASE_PATH . " /core/database/ " .$ type ." / " .$ sqlFile .'.sql ' ;
123
+ $ sqlFile = BASE_PATH . ' /core/database/ ' .$ type .' / ' .$ sqlFile .'.sql ' ;
131
124
if (!isset ($ sqlFile ) || !file_exists ($ sqlFile ))
132
125
{
133
- throw new Zend_Exception (" Unable to find sql file " );
126
+ throw new Zend_Exception (' Unable to find sql file ' );
134
127
}
135
128
136
129
switch ($ type )
@@ -161,7 +154,7 @@ function step2Action()
161
154
$ databaseConfig ['development ' ]['database.params.port ' ] = $ form ->getValue ('port ' );
162
155
$ databaseConfig ['production ' ]['database.params.port ' ] = $ form ->getValue ('port ' );
163
156
164
- $ db = Zend_Db::factory (" PDO_MYSQL " , $ params );
157
+ $ db = Zend_Db::factory (' Pdo_Mysql ' , $ params );
165
158
Zend_Db_Table::setDefaultAdapter ($ db );
166
159
Zend_Registry::set ('dbAdapter ' , $ db );
167
160
@@ -193,7 +186,7 @@ function step2Action()
193
186
$ databaseConfig ['development ' ]['database.params.port ' ] = $ form ->getValue ('port ' );
194
187
$ databaseConfig ['production ' ]['database.params.port ' ] = $ form ->getValue ('port ' );
195
188
196
- $ db = Zend_Db::factory (" PDO_PGSQL " , $ params );
189
+ $ db = Zend_Db::factory (' Pdo_Pgsql ' , $ params );
197
190
Zend_Db_Table::setDefaultAdapter ($ db );
198
191
Zend_Registry::set ('dbAdapter ' , $ db );
199
192
$ dbtype = 'PDO_PGSQL ' ;
@@ -204,21 +197,21 @@ function step2Action()
204
197
$ databaseConfig ['production ' ]['version ' ] = str_replace ('.sql ' , '' , basename ($ sqlFile ));
205
198
$ databaseConfig ['development ' ]['version ' ] = str_replace ('.sql ' , '' , basename ($ sqlFile ));
206
199
207
- $ this ->Component ->Utility ->createInitFile (BASE_PATH . '/core/configs/database.local.ini ' , $ databaseConfig );
200
+ $ this ->Component ->Utility ->createInitFile (BASE_PATH . '/core/configs/database.local.ini ' , $ databaseConfig );
208
201
209
202
// Must generate and store our password salt before we create our first user
210
- $ appConfig = parse_ini_file (BASE_PATH . '/core/configs/application.ini ' , true );
203
+ $ appConfig = parse_ini_file (BASE_PATH . '/core/configs/application.ini ' , true );
211
204
$ appConfig ['global ' ]['password.prefix ' ] = UtilityComponent::generateRandomString (32 );
212
205
213
206
// Verify whether the user wants to use gravatars or not
214
207
$ appConfig ['global ' ]['gravatar ' ] = $ form ->getValue ('gravatar ' );
215
208
216
209
// Save the new config
217
- $ this ->Component ->Utility ->createInitFile (BASE_PATH . '/core/configs/application.local.ini ' , $ appConfig );
218
- $ configGlobal = new Zend_Config_Ini (BASE_PATH . '/core/configs/application.local.ini ' , 'global ' , true );
210
+ $ this ->Component ->Utility ->createInitFile (BASE_PATH . '/core/configs/application.local.ini ' , $ appConfig );
211
+ $ configGlobal = new Zend_Config_Ini (BASE_PATH . '/core/configs/application.local.ini ' , 'global ' , true );
219
212
Zend_Registry::set ('configGlobal ' , $ configGlobal );
220
213
221
- require_once BASE_PATH . '/core/controllers/components/UpgradeComponent.php ' ;
214
+ require_once BASE_PATH . '/core/controllers/components/UpgradeComponent.php ' ;
222
215
$ upgradeComponent = new UpgradeComponent ();
223
216
$ db = Zend_Registry::get ('dbAdapter ' );
224
217
@@ -230,36 +223,36 @@ function step2Action()
230
223
$ this ->userSession ->Dao = $ userModel ->createUser ($ form ->getValue ('email ' ), $ form ->getValue ('userpassword1 ' ),
231
224
$ form ->getValue ('firstname ' ), $ form ->getValue ('lastname ' ), 1 );
232
225
233
- //create default assetstrore
226
+ // create default assetstore
234
227
$ assetstoreDao = new AssetstoreDao ();
235
228
$ assetstoreDao ->setName ('Local ' );
236
- $ assetstoreDao ->setPath (BASE_PATH . '/data/assetstore ' );
229
+ $ assetstoreDao ->setPath (BASE_PATH . '/data/assetstore ' );
237
230
$ assetstoreDao ->setType (MIDAS_ASSETSTORE_LOCAL );
238
231
$ this ->Assetstore = new AssetstoreModel (); //reset Database adapter
239
232
$ this ->Assetstore ->save ($ assetstoreDao );
240
- $ this ->_redirect (" /install/step3 " );
233
+ $ this ->_redirect (' /install/step3 ' );
241
234
}
242
235
}
243
- } // end method step2Action
236
+ }
244
237
245
238
/**
246
239
* @method step3Action()
247
240
*/
248
241
function step3Action ()
249
242
{
250
243
$ this ->requireAdminPrivileges ();
251
- if (!file_exists (BASE_PATH . '/core/configs/database.local.ini ' ))
244
+ if (!file_exists (BASE_PATH . '/core/configs/database.local.ini ' ))
252
245
{
253
246
$ this ->_redirect ('/install/index ' );
254
247
}
255
- $ this ->view ->header = 'Step3 : Midas Configuration ' ;
248
+ $ this ->view ->header = 'Step 3 : Midas Server Configuration ' ;
256
249
$ userDao = $ this ->userSession ->Dao ;
257
250
if (!isset ($ userDao ) || !$ userDao ->isAdmin ())
258
251
{
259
- unlink (BASE_PATH . " /core/configs/database.local.ini " );
252
+ unlink (BASE_PATH . ' /core/configs/database.local.ini ' );
260
253
$ this ->_redirect ('/install/index ' );
261
254
}
262
- $ applicationConfig = parse_ini_file (BASE_PATH . '/core/configs/application.local.ini ' , true );
255
+ $ applicationConfig = parse_ini_file (BASE_PATH . '/core/configs/application.local.ini ' , true );
263
256
264
257
$ form = $ this ->Form ->Install ->createConfigForm ();
265
258
$ formArray = $ this ->getFormAsArray ($ form );
@@ -280,7 +273,7 @@ function step3Action()
280
273
$ allModules = $ this ->Component ->Utility ->getAllModules ();
281
274
foreach ($ allModules as $ key => $ module )
282
275
{
283
- $ configLocal = BASE_PATH . '/core/configs/ ' .$ key .'.local.ini ' ;
276
+ $ configLocal = BASE_PATH . '/core/configs/ ' .$ key .'.local.ini ' ;
284
277
if (file_exists ($ configLocal ))
285
278
{
286
279
unlink ($ configLocal );
@@ -295,60 +288,40 @@ function step3Action()
295
288
$ applicationConfig ['global ' ]['smartoptimizer ' ] = $ form ->getValue ('smartoptimizer ' );
296
289
$ applicationConfig ['global ' ]['default.timezone ' ] = $ form ->getValue ('timezone ' );
297
290
298
- $ this ->Component ->Utility ->createInitFile (BASE_PATH . '/core/configs/application.local.ini ' , $ applicationConfig );
299
- $ this ->_redirect (" /admin#tabs-modules " );
291
+ $ this ->Component ->Utility ->createInitFile (BASE_PATH . '/core/configs/application.local.ini ' , $ applicationConfig );
292
+ $ this ->_redirect (' /admin#tabs-modules ' );
300
293
}
301
- } // end method step2Action
294
+ }
302
295
303
296
/** AJAX function which tests connectivity to a database */
304
297
public function testconnectionAction ()
305
298
{
306
299
$ this ->requireAjaxRequest ();
307
300
$ this ->_helper ->layout ->disableLayout ();
308
301
$ this ->_helper ->viewRenderer ->setNoRender ();
309
- $ type = $ this ->_getParam ('type ' );
310
- $ username = $ this ->_getParam ('username ' );
311
- $ password = $ this ->_getParam ('password ' );
312
- $ host = $ this ->_getParam ('host ' );
313
- $ dbname = $ this ->_getParam ('dbname ' );
314
- $ port = $ this ->_getParam ('port ' );
315
- switch ($ type )
302
+ try
316
303
{
317
- case 'mysql ' :
318
- $ link = mysql_connect ($ host .": " .$ port , "$ username " , "$ password " );
319
- if (!$ link )
320
- {
321
- $ return = array (false , "Could not connect to the server ' " . $ host . "': " .mysql_error ());
322
- break ;
323
- }
324
- $ dbcheck = mysql_select_db ("$ dbname " );
325
- if (!$ dbcheck )
326
- {
327
- $ return = array (false , "Could not connect to the server ' " . $ host . "': " .mysql_error ());
328
- break ;
329
- }
330
- $ sql = "SHOW TABLES FROM " .$ dbname ;
331
- $ result = mysql_query ($ sql );
332
- if (mysql_num_rows ($ result ) > 0 )
333
- {
334
- $ return = array (false , "The database is not empty " );
335
- break ;
336
- }
337
- $ return = array (true , "The database is reachable " );
338
- break ;
339
- case 'pgsql ' :
340
- $ link = pg_connect ("host = " .$ host ." port = " .$ port ." dbname = " .$ dbname ." user = " .$ username ." password = " .$ password );
341
- if (!$ link )
342
- {
343
- $ return = array (false , "Could not connect to the server ' " . $ host . "': " .pg_last_error ($ link ));
344
- break ;
345
- }
346
- $ return = array (true , "The database is reachable " );
347
- break ;
348
- default :
349
- $ return = array (false , "Database not defined " );
350
- break ;
304
+ $ db = Zend_Db::factory ('Pdo_ ' . ucfirst ($ this ->_getParam ('type ' )), array (
305
+ 'host ' => $ this ->_getParam ('host ' ),
306
+ 'port ' => $ this ->_getParam ('port ' ),
307
+ 'username ' => $ this ->_getParam ('username ' ),
308
+ 'password ' => $ this ->_getParam ('password ' ),
309
+ 'dbname ' => $ this ->_getParam ('dbname ' )));
310
+ $ tables = $ db ->listTables ();
311
+ if (count ($ tables ) > 0 )
312
+ {
313
+ $ return = array (false , 'The database is not empty ' );
314
+ }
315
+ else
316
+ {
317
+ $ return = array (true , 'The database is reachable ' );
318
+ }
319
+ $ db ->closeConnection ();
320
+ }
321
+ catch (Zend_Exception $ exception )
322
+ {
323
+ $ return = array (false , 'Could not connect to the database server: ' . $ exception ->getMessage ());
351
324
}
352
325
echo JsonComponent::encode ($ return );
353
- }//end getElementInfo
354
- } // end class
326
+ }
327
+ }
0 commit comments