@@ -25,14 +25,29 @@ public function __construct(
2525 /** @inheritDoc */
2626 public function runInstallation (Command |null $ initCommand , SymfonyStyle $ io ): int
2727 {
28- return $ this ->run ($ initCommand , $ io , isUpdate: false , importedConfig: ImportedConfig::notImported ());
28+ $ initCommandInput = [InitOption::INITIAL_API_KEY ->asCliFlag () => null ];
29+ return $ this ->run ($ initCommand , $ io , $ initCommandInput , ImportedConfig::notImported ());
2930 }
3031
3132 /** @inheritDoc */
3233 public function runUpdate (Command |null $ initCommand , SymfonyStyle $ io ): int
3334 {
3435 $ importConfig = $ this ->assetsHandler ->resolvePreviousConfig ($ io );
35- return $ this ->run ($ initCommand , $ io , isUpdate: true , importedConfig: $ importConfig );
36+
37+ // Check if a cached config file exists and drop it if so
38+ $ this ->assetsHandler ->dropCachedConfigIfAny ($ io );
39+ $ this ->assetsHandler ->importShlinkAssetsFromPath ($ io , $ importConfig ->importPath );
40+
41+ $ initCommandInput = [
42+ InitOption::SKIP_INITIALIZE_DB ->asCliFlag () => null ,
43+ InitOption::CLEAR_DB_CACHE ->asCliFlag () => null ,
44+ ];
45+
46+ if ($ this ->assetsHandler ->roadRunnerBinaryExistsInPath ($ importConfig ->importPath )) {
47+ $ initCommandInput [InitOption::DOWNLOAD_RR_BINARY ->asCliFlag ()] = null ;
48+ }
49+
50+ return $ this ->run ($ initCommand , $ io , $ initCommandInput , $ importConfig );
3651 }
3752
3853 /**
@@ -41,20 +56,14 @@ public function runUpdate(Command|null $initCommand, SymfonyStyle $io): int
4156 private function run (
4257 Command |null $ initCommand ,
4358 SymfonyStyle $ io ,
44- bool $ isUpdate ,
59+ array $ initCommandInput ,
4560 ImportedConfig $ importedConfig ,
4661 ): int {
4762 $ io ->text ([
4863 '<info>Welcome to Shlink!!</info> ' ,
4964 'This tool will guide you through the installation process. ' ,
5065 ]);
5166
52- // Check if a cached config file exists and drop it if so
53- $ this ->assetsHandler ->dropCachedConfigIfAny ($ io );
54-
55- if ($ isUpdate ) {
56- $ this ->assetsHandler ->importShlinkAssetsFromPath ($ io , $ importedConfig ->importPath );
57- }
5867 $ config = $ this ->configGenerator ->generateConfigInteractively ($ io , $ importedConfig ->importedConfig );
5968 $ normalizedConfig = Utils::normalizeAndKeepEnvVarKeys ($ config );
6069
@@ -63,31 +72,12 @@ private function run(
6372 $ io ->text ('<info>Custom configuration properly generated!</info> ' );
6473 $ io ->newLine ();
6574
66- if (! $ this ->execInitCommand ($ initCommand , $ io , $ isUpdate , $ importedConfig )) {
75+ $ initCommandResult = $ initCommand ?->run(new ArrayInput ($ initCommandInput ), $ io );
76+ if ($ initCommandResult !== Command::SUCCESS ) {
6777 return Command::FAILURE ;
6878 }
6979
7080 $ io ->success ('Installation complete! ' );
7181 return Command::SUCCESS ;
7282 }
73-
74- private function execInitCommand (
75- Command |null $ initCommand ,
76- SymfonyStyle $ io ,
77- bool $ isUpdate ,
78- ImportedConfig $ importedConfig ,
79- ): bool {
80- $ input = [
81- InitOption::SKIP_INITIALIZE_DB ->asCliFlag () => $ isUpdate ,
82- InitOption::CLEAR_DB_CACHE ->asCliFlag () => $ isUpdate ,
83- InitOption::DOWNLOAD_RR_BINARY ->asCliFlag () =>
84- $ isUpdate && $ this ->assetsHandler ->roadRunnerBinaryExistsInPath ($ importedConfig ->importPath ),
85- ];
86-
87- if (! $ isUpdate ) {
88- $ input [InitOption::INITIAL_API_KEY ->asCliFlag ()] = null ;
89- }
90-
91- return $ initCommand ?->run(new ArrayInput ($ input ), $ io ) === Command::SUCCESS ;
92- }
9383}
0 commit comments