Write the env using the UpdateConfigCommand
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Bus\Commands\System\Config\UpdateConfigCommand;
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use CachetHQ\Cachet\Settings\Repository;
|
||||
use Dotenv\Dotenv;
|
||||
@@ -259,9 +260,7 @@ class SetupController extends Controller
|
||||
$envData = array_pull($postData, 'env');
|
||||
|
||||
// Write the env to the .env file.
|
||||
foreach ($envData as $envKey => $envValue) {
|
||||
$this->writeEnv($envKey, $envValue);
|
||||
}
|
||||
dispatch(new UpdateConfigCommand($envData));
|
||||
|
||||
if (Request::ajax()) {
|
||||
return Response::json(['status' => 1]);
|
||||
@@ -276,34 +275,4 @@ class SetupController extends Controller
|
||||
|
||||
return cachet_redirect('setup')->withInput()->withErrors($v->getMessageBag());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes to the .env file with given parameters.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function writeEnv($key, $value)
|
||||
{
|
||||
$dir = app()->environmentPath();
|
||||
$file = app()->environmentFile();
|
||||
$path = "{$dir}/{$file}";
|
||||
|
||||
try {
|
||||
(new Dotenv($dir, $file))->load();
|
||||
|
||||
$envKey = strtoupper($key);
|
||||
$envValue = env($envKey) ?: 'null';
|
||||
|
||||
file_put_contents($path, str_replace(
|
||||
$envKey.'='.$envValue,
|
||||
$envKey.'='.$value,
|
||||
file_get_contents($path)
|
||||
));
|
||||
} catch (InvalidPathException $e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user