@@ -352,9 +352,11 @@ private function restorePointData(RestoringPoint $point, RestoringData $data): v
352
352
* @throws SqlDumpException
353
353
*/
354
354
private function restorePointSqlDump (RestoringPoint $ point , RestoringData $ data ): void {
355
+ $ fromConfig = $ this ->getSqlParamsFromConfig ($ point );
356
+
355
357
while (true ) {
356
358
try {
357
- $ sqlParams = $ this ->requestSqlParams ();
359
+ $ sqlParams = $ this ->requestSqlParams ($ fromConfig );
358
360
} catch (RestoringDataNotFoundException $ e ) {
359
361
$ this ->output ->writeln (' * ignoring sqldump ' );
360
362
@@ -432,29 +434,58 @@ private function requestDataRoot(RestoringData $data): string {
432
434
* @return array
433
435
* @throws RestoringDataNotFoundException
434
436
*/
435
- private function requestSqlParams (): array {
437
+ private function requestSqlParams (array $ fromConfig = [] ): array {
436
438
$ sqlParams = $ this ->pointService ->getSqlParams ();
437
439
if ($ this ->input ->getOption ('do-not-ask-sql ' )) {
438
440
return $ sqlParams ;
439
441
}
440
442
443
+ $ options = ['cancel ' , 'yes ' , 'no ' ];
444
+ if (!empty ($ fromConfig )) {
445
+ array_push ($ options , 'load ' );
446
+ }
447
+
441
448
while (true ) {
442
449
$ this ->output ->writeln (' > will be imported in ' . $ this ->displaySqlParams ($ sqlParams , true ));
443
450
451
+ $ this ->output ->writeln ('' );
452
+ $ this ->output ->writeln (' * <comment>Do you want to</comment>: ' );
453
+ $ this ->output ->writeln (' - use this settings and start importing the sqldump (yes) ' );
454
+ $ this ->output ->writeln (' - manually editing the Sql settings (edit) ' );
455
+ if (!empty ($ fromConfig )) {
456
+ $ this ->output ->writeln (
457
+ ' - load the settings from the config/config.php found in the backup (load) '
458
+ );
459
+ $ displayLoad = 'load/ ' ;
460
+ } else {
461
+ $ displayLoad = '' ;
462
+ }
463
+ $ this ->output ->writeln (
464
+ ' - cancel the import of the sqldump, and go on with the restoring process (cancel) '
465
+ );
466
+ $ this ->output ->writeln ('' );
467
+
444
468
$ helper = $ this ->getHelper ('question ' );
445
469
$ question = new Question (
446
- ' - <comment>Do you want to import the dump in the current database, or cancel the import ?</comment> (yes/No/cancel) ' ,
447
- 'no ' ,
470
+ ' * <comment>Do you want to import the sqldump using those settings?</comment> (yes/Edit/ '
471
+ . $ displayLoad . 'cancel) ' ,
472
+ 'edit ' ,
448
473
);
449
- $ question ->setAutocompleterValues ([ ' cancel ' , ' yes ' , ' no ' ] );
474
+ $ question ->setAutocompleterValues ($ options );
450
475
451
- switch (strtolower ($ helper ->ask ($ this ->input , $ this ->output , $ question ))) {
476
+ $ ret = strtolower ($ helper ->ask ($ this ->input , $ this ->output , $ question ));
477
+ switch ($ ret ) {
452
478
case 'yes ' :
453
479
return $ sqlParams ;
454
480
case 'cancel ' :
455
481
throw new RestoringDataNotFoundException ();
456
482
}
457
483
484
+ if ($ ret === 'load ' ) {
485
+ $ sqlParams = $ fromConfig ;
486
+ continue ;
487
+ }
488
+
458
489
$ this ->output ->writeln (' - current configuration: ' );
459
490
$ this ->displaySqlParams ($ sqlParams );
460
491
@@ -534,14 +565,36 @@ private function requestSqlParams(): array {
534
565
}
535
566
536
567
568
+ /**
569
+ * @param RestoringPoint $point
570
+ *
571
+ * @return array
572
+ */
573
+ private function getSqlParamsFromConfig (RestoringPoint $ point ): array {
574
+ $ CONFIG = $ this ->getConfigDirect ($ point );
575
+ if (empty ($ CONFIG )) {
576
+ return [];
577
+ }
578
+
579
+ return [
580
+ ISqlDump::DB_TYPE => $ this ->get (ISqlDump::DB_TYPE , $ CONFIG ),
581
+ ISqlDump::DB_NAME => $ this ->get (ISqlDump::DB_NAME , $ CONFIG ),
582
+ ISqlDump::DB_HOST => $ this ->get (ISqlDump::DB_HOST , $ CONFIG ),
583
+ ISqlDump::DB_PORT => $ this ->get (ISqlDump::DB_PORT , $ CONFIG ),
584
+ ISqlDump::DB_USER => $ this ->get (ISqlDump::DB_USER , $ CONFIG ),
585
+ ISqlDump::DB_PASS => $ this ->get (ISqlDump::DB_PASS , $ CONFIG )
586
+ ];
587
+ }
588
+
589
+
537
590
/**
538
591
* @param RestoringPoint $point
539
592
*/
540
593
private function updateConfig (RestoringPoint $ point ): void {
541
594
$ this ->output ->writeln ('> Refreshing <info>config.php</info> ' );
542
595
543
596
$ sqlParams = [];
544
- $ dataRoot = $ configRoot = '' ;
597
+ $ dataRoot = '' ;
545
598
foreach ($ point ->getRestoringData () as $ data ) {
546
599
if ($ data ->getType () === RestoringData::ROOT_DATA ) {
547
600
if ($ data ->getRestoredRoot () === '' ) {
@@ -550,18 +603,6 @@ private function updateConfig(RestoringPoint $point): void {
550
603
$ dataRoot = $ data ->getRestoredRoot ();
551
604
}
552
605
553
- if ($ data ->getType () === RestoringData::FILE_CONFIG ) {
554
- if ($ data ->getRestoredRoot () === '' ) {
555
- $ this ->output ->writeln (
556
- ' * do not refresh as <info>config/config.php</info> were not restored '
557
- );
558
- $ this ->configService ->maintenanceMode (false );
559
-
560
- return ;
561
- }
562
- $ configRoot = $ data ->getRestoredRoot ();
563
- }
564
-
565
606
if ($ data ->getType () === RestoringData::FILE_SQL_DUMP ) {
566
607
if ($ data ->getRestoredRoot () === '' ) {
567
608
continue ;
@@ -573,9 +614,16 @@ private function updateConfig(RestoringPoint $point): void {
573
614
}
574
615
}
575
616
576
- $ CONFIG = [];
577
- $ configFile = rtrim ($ configRoot , '/ ' ) . '/config.php ' ;
578
- include $ configFile ;
617
+ $ configFile = '' ;
618
+ $ CONFIG = $ this ->getConfigDirect ($ point , $ configFile );
619
+ if (empty ($ CONFIG )) {
620
+ $ this ->output ->writeln (
621
+ ' * do not refresh as <info>config/config.php</info> were not restored '
622
+ );
623
+ $ this ->configService ->maintenanceMode (false );
624
+
625
+ return ;
626
+ }
579
627
580
628
if ($ dataRoot !== '' ) {
581
629
$ this ->compareConfigDataRoot ($ CONFIG , $ dataRoot );
@@ -597,6 +645,30 @@ private function updateConfig(RestoringPoint $point): void {
597
645
}
598
646
599
647
648
+ /**
649
+ * @param RestoringPoint $point
650
+ * @param string $configFile
651
+ *
652
+ * @return array
653
+ */
654
+ private function getConfigDirect (RestoringPoint $ point , string &$ configFile = '' ): array {
655
+ $ dataRoot = $ configRoot = '' ;
656
+ foreach ($ point ->getRestoringData () as $ data ) {
657
+ if ($ data ->getType () === RestoringData::FILE_CONFIG ) {
658
+ if ($ data ->getRestoredRoot () === '' ) {
659
+ return [];
660
+ }
661
+ $ configRoot = $ data ->getRestoredRoot ();
662
+ }
663
+ }
664
+
665
+ $ CONFIG = [];
666
+ $ configFile = rtrim ($ configRoot , '/ ' ) . '/config.php ' ;
667
+ include $ configFile ;
668
+
669
+ return $ CONFIG ;
670
+ }
671
+
600
672
/**
601
673
* @param array $CONFIG
602
674
* @param string $used
@@ -627,6 +699,9 @@ private function compareConfigDataRoot(array &$CONFIG, string $used): void {
627
699
}
628
700
629
701
702
+
703
+ // private function getConfigSqlParams();
704
+
630
705
/**
631
706
* @param array $sqlParams
632
707
* @param array $CONFIG
@@ -797,12 +872,14 @@ private function restoreUniqueFile(
797
872
*/
798
873
private function displaySqlParams (array $ sql , bool $ oneLine = false ): string {
799
874
if ($ oneLine ) {
800
- return '<info> ' . $ this ->get (ISqlDump::DB_USER , $ sql ) . '</info>:****@<info> '
875
+ return '<info> ' . $ this ->get (ISqlDump::DB_TYPE , $ sql ) . '</info>::/<info> '
876
+ . $ this ->get (ISqlDump::DB_USER , $ sql ) . '</info>:****@<info> '
801
877
. $ this ->get (ISqlDump::DB_HOST , $ sql ) . ': ' . $ this ->get (ISqlDump::DB_PORT , $ sql )
802
878
. '</info>/<info> '
803
879
. $ this ->get (ISqlDump::DB_NAME , $ sql ) . '</info> ' ;
804
880
}
805
881
882
+ $ this ->output ->writeln (' . Type: <info> ' . $ this ->get (ISqlDump::DB_TYPE , $ sql ) . '</info> ' );
806
883
$ this ->output ->writeln (' . Host: <info> ' . $ this ->get (ISqlDump::DB_HOST , $ sql ) . '</info> ' );
807
884
$ this ->output ->writeln (' . Port: <info> ' . $ this ->get (ISqlDump::DB_PORT , $ sql ) . '</info> ' );
808
885
$ this ->output ->writeln (' . Database: <info> ' . $ this ->get (ISqlDump::DB_NAME , $ sql ) . '</info> ' );
0 commit comments