@@ -46,9 +46,9 @@ function __construct($argv)
4646 $ tmp = array_map ('trim ' , explode ('= ' , $ arg ));
4747 if (count ($ tmp ) === 2 ) {
4848 $ k = ltrim ($ tmp [0 ], '- ' );
49-
50- $ cli_variables [ $ k ] = $ tmp [ 1 ];
51- if (isset ($ this ->{ $ k } )) {
49+
50+ // Check if property exists and set it
51+ if (property_exists ($ this , $ k )) {
5252 $ this ->{$ k } = $ tmp [1 ];
5353 }
5454 }
@@ -189,67 +189,85 @@ public function install()
189189 public function checkDatabaseType ()
190190 {
191191 $ dbTypes = ['pgsql ' , 'mysql ' ];
192- while (!in_array ($ this ->databaseType , $ dbTypes )) {
193- $ this ->databaseType = $ this ->choice (
194- 'Please choose your database type: ' ,
195- $ dbTypes
196- );
192+ if (!in_array ($ this ->databaseType , $ dbTypes )) {
193+ while (!in_array ($ this ->databaseType , $ dbTypes )) {
194+ $ this ->databaseType = $ this ->choice (
195+ 'Please choose your database type: ' ,
196+ $ dbTypes
197+ );
198+ }
197199 }
198200 }
199201
200202 public function checkDatabaseServer ()
201203 {
202- while ($ this ->databaseServer === '' ) {
203- $ this ->databaseServer = $ this ->ask ('Please enter database server: ' , 'localhost ' );
204+ if ($ this ->databaseServer === '' ) {
205+ while ($ this ->databaseServer === '' ) {
206+ $ this ->databaseServer = $ this ->ask ('Please enter database server: ' , 'localhost ' );
207+ }
204208 }
205209 }
206210
207211 public function checkDatabase ()
208212 {
209- while ($ this ->database === '' ) {
210- $ this ->database = $ this ->ask ('Please enter database: ' , '' );
213+ if ($ this ->database === '' ) {
214+ while ($ this ->database === '' ) {
215+ $ this ->database = $ this ->ask ('Please enter database: ' , '' );
216+ }
211217 }
212218 }
213219
214220 public function checkDatabaseUser ()
215221 {
216- while ($ this ->databaseUser === '' ) {
217- $ this ->databaseUser = $ this ->ask ('Please enter database user: ' , '' );
222+ if ($ this ->databaseUser === '' ) {
223+ while ($ this ->databaseUser === '' ) {
224+ $ this ->databaseUser = $ this ->ask ('Please enter database user: ' , '' );
225+ }
218226 }
219227 }
220228
221229 public function checkDatabasePassword ()
222230 {
223- while ($ this ->databasePassword === '' ) {
224- $ this ->databasePassword = $ this ->ask ('Please enter database password: ' , '' );
231+ if ($ this ->databasePassword === '' ) {
232+ while ($ this ->databasePassword === '' ) {
233+ $ this ->databasePassword = $ this ->ask ('Please enter database password: ' , '' );
234+ }
225235 }
226236 }
227237
228238 public function checkTablePrefix ()
229239 {
230- while ($ this ->tablePrefix === '' ) {
231- $ this ->tablePrefix = $ this ->ask ('Please enter table_prefix: ' , 'evo_ ' );
240+ if ($ this ->tablePrefix === '' ) {
241+ while ($ this ->tablePrefix === '' ) {
242+ $ this ->tablePrefix = $ this ->ask ('Please enter table_prefix: ' , 'evo_ ' );
243+ }
232244 }
233245 }
234246
235247 public function checkCmsAdmin ()
236248 {
237- while ($ this ->cmsAdmin === '' ) {
238- $ this ->cmsAdmin = $ this ->ask ('Please enter you login for access to manager: ' , '' );
249+ if ($ this ->cmsAdmin === '' ) {
250+ while ($ this ->cmsAdmin === '' ) {
251+ $ this ->cmsAdmin = $ this ->ask ('Please enter you login for access to manager: ' , '' );
252+ }
239253 }
240254 }
241255
242256 public function checkCmsAdminEmail ()
243257 {
244- while ($ this ->cmsAdminEmail === '' ) {
245- $ this ->cmsAdminEmail = $ this ->ask ('Please enter you email: ' , '' );
258+ if ($ this ->cmsAdminEmail === '' ) {
259+ while ($ this ->cmsAdminEmail === '' ) {
260+ $ this ->cmsAdminEmail = $ this ->ask ('Please enter you email: ' , '' );
261+ }
246262 }
247263 }
248264
249265 public function checkCmsPassword ()
250266 {
251- while ($ this ->cmsPassword === '' ) {
252- $ this ->cmsPassword = $ this ->ask ('Please enter you password for access to manager: ' , '' );
267+ if ($ this ->cmsPassword === '' ) {
268+ while ($ this ->cmsPassword === '' ) {
269+ $ this ->cmsPassword = $ this ->ask ('Please enter you password for access to manager: ' , '' );
270+ }
253271 }
254272 }
255273
@@ -305,6 +323,12 @@ public function checkConnectToDatabase()
305323 $ this ->dbh = false ;
306324 }
307325 if ($ this ->dbh === false ) {
326+ // In CLI mode, don't reset values and restart - just exit with error
327+ if (defined ('MODX_CLI ' ) && MODX_CLI ) {
328+ error ('✖ Database connection failed. Please check your database settings and try again. ' );
329+ exit (1 );
330+ }
331+ // For interactive mode, reset values and restart
308332 $ this ->databaseType = '' ;
309333 $ this ->databaseServer = '' ;
310334 $ this ->databaseUser = '' ;
@@ -361,6 +385,12 @@ public function checkConnectToDatabaseWithBase()
361385 }
362386 }
363387 if ($ this ->dbh === false ) {
388+ // In CLI mode, don't reset values and restart - just exit with error
389+ if (defined ('MODX_CLI ' ) && MODX_CLI ) {
390+ error ('✖ Database connection failed. Please check your database settings and try again. ' );
391+ exit (1 );
392+ }
393+ // For interactive mode, reset values and restart
364394 $ this ->database = '' ;
365395 $ this ->checkDatabase ();
366396 $ this ->checkConnectToDatabaseWithBase ();
@@ -375,6 +405,12 @@ public function checkIssetTablePrefix()
375405 $ result = $ this ->dbh ->query ("SELECT COUNT(*) FROM {$ this ->tablePrefix }site_content " );
376406 if ($ result !== false ) {
377407 error ('✖ Table prefix already exists ' );
408+ // In CLI mode, exit with error instead of asking user
409+ if (defined ('MODX_CLI ' ) && MODX_CLI ) {
410+ error ('✖ Table prefix already exists. Please choose a different prefix or remove existing tables. ' );
411+ exit (1 );
412+ }
413+ // For interactive mode, reset and ask user
378414 $ this ->tablePrefix = '' ;
379415 $ this ->checkTablePrefix ();
380416 $ this ->checkIssetTablePrefix ();
0 commit comments