66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
namespace App\Console\Command;
|
|
|
|
use App\Settings;
|
|
use App\Console\Command\CommandAbstract;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
class MigrateConfigCommand extends CommandAbstract
|
|
{
|
|
public function __invoke(
|
|
SymfonyStyle $io,
|
|
Settings $settings
|
|
) {
|
|
$env_path = $settings[Settings::BASE_DIR] . '/env.ini';
|
|
$iniSettings = [];
|
|
|
|
if (file_exists($env_path)) {
|
|
$iniSettings = parse_ini_file($env_path);
|
|
|
|
if (!empty($iniSettings['db_password'])) {
|
|
$io->writeln(__('Configuration already set up.'));
|
|
return null;
|
|
}
|
|
}
|
|
|
|
if (empty($iniSettings['application_env']) && file_exists($settings[Settings::BASE_DIR] . '/app/.env')) {
|
|
$iniSettings['application_env'] = @file_get_contents($settings[Settings::BASE_DIR] . '/app/.env');
|
|
}
|
|
|
|
if (empty($iniSettings['db_password'])) {
|
|
$legacy_path = $settings[Settings::BASE_DIR] . '/app/env.ini';
|
|
if (file_exists($legacy_path)) {
|
|
$old_settings = parse_ini_file($legacy_path);
|
|
$iniSettings = array_merge($iniSettings, $old_settings);
|
|
}
|
|
|
|
if (file_exists($settings[Settings::BASE_DIR] . '/app/config/db.conf.php')) {
|
|
$db_conf = include($settings[Settings::BASE_DIR] . '/app/config/db.conf.php');
|
|
$iniSettings['db_password'] = $db_conf['password'];
|
|
|
|
if ($db_conf['user'] === 'root') {
|
|
$iniSettings['db_username'] = 'root';
|
|
}
|
|
}
|
|
}
|
|
|
|
$ini_data = [
|
|
';',
|
|
'; AzuraCast Environment Settings',
|
|
';',
|
|
'; This file is automatically generated by AzuraCast.',
|
|
';',
|
|
'[configuration]',
|
|
];
|
|
|
|
foreach ($iniSettings as $setting_key => $setting_val) {
|
|
$ini_data[] = $setting_key . '="' . $setting_val . '"';
|
|
}
|
|
|
|
file_put_contents($env_path, implode("\n", $ini_data));
|
|
|
|
$io->writeln(__('Configuration successfully written.'));
|
|
return null;
|
|
}
|
|
}
|