Add check for null env and attempt to recover

This commit is contained in:
Miguel Nogueira 2020-07-09 09:07:49 +01:00
parent 635f8593d3
commit 4deb882d23
2 changed files with 21 additions and 3 deletions

View File

@ -79,7 +79,6 @@ class Install extends Command
$this->info('>> Configuring application - We\'re going to ask a few questions here!'); $this->info('>> Configuring application - We\'re going to ask a few questions here!');
do do
{ {
$this->call('config:clear');
$this->info('== Database Settings (1/6) =='); $this->info('== Database Settings (1/6) ==');
$settings['DB_USERNAME'] = $this->ask('Database username'); $settings['DB_USERNAME'] = $this->ask('Database username');
@ -116,7 +115,6 @@ class Install extends Command
'value' => $value 'value' => $value
]); ]);
} }
$this->call('config:cache');
$this->info('>> Saved configuration settings!'); $this->info('>> Saved configuration settings!');
$this->info('>> Preparing database...'); $this->info('>> Preparing database...');

View File

@ -42,18 +42,38 @@ class SetEnv extends Command
$value = $this->argument('value'); $value = $this->argument('value');
$originalValue = env($key); $originalValue = env($key);
if (is_null($originalValue))
{
// Attempt to silently fix issue
$this->callSilent('cache:clear');
$originalValue = env($key);
// Still fails? Let the user know
if (is_null($originalValue))
{
$this->error('[!!] Cannot update requested configuration value! This is a known Laravel issue. If you report a bug, keep that in mind.');
return false;
}
}
if (file_exists($path)) if (file_exists($path))
{ {
$file = file_get_contents($path); $file = file_get_contents($path);
$newConfig = str_replace($key . '=' . $originalValue, $key . '=' . $value, $file); $newConfig = str_replace($key . '=' . $originalValue, $key . '=' . $value, $file);
file_put_contents( file_put_contents(
$path, $path,
$newConfig $newConfig
); );
} }
else
{
$this->error('Cannot update a file that doesn\'t exist! Please create .env first.');
return false;
}
$this->info('>> Changed value! It may now be accessed via env() or config() if there\'s a file for it.'); $this->info('>> Changed value! It may now be accessed via env() or config() if there\'s a file for it.');
} }