2018-02-10 07:11:55 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2019-09-17 01:08:26 +08:00
|
|
|
use App\Contracts\Command;
|
2021-01-03 20:39:02 +08:00
|
|
|
use App\Services\Installer\ConfigService;
|
2018-02-10 07:11:55 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a fresh development install
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class DevInstall extends Command
|
2018-02-10 07:11:55 +08:00
|
|
|
{
|
2018-05-10 23:22:45 +08:00
|
|
|
protected $signature = 'phpvms:dev-install {--reset-db} {--reset-configs}';
|
2018-02-10 07:11:55 +08:00
|
|
|
protected $description = 'Run a developer install and run the sample migration';
|
|
|
|
|
2019-08-05 20:27:53 +08:00
|
|
|
private $databaseSeeder;
|
|
|
|
|
|
|
|
public function __construct(\DatabaseSeeder $databaseSeeder)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
2019-08-11 08:42:35 +08:00
|
|
|
|
2019-08-05 20:27:53 +08:00
|
|
|
$this->databaseSeeder = $databaseSeeder;
|
|
|
|
}
|
|
|
|
|
2018-02-10 07:11:55 +08:00
|
|
|
/**
|
|
|
|
* Run dev related commands
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-10 07:11:55 +08:00
|
|
|
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2018-05-10 23:22:45 +08:00
|
|
|
if ($this->option('reset-configs')) {
|
2018-02-10 07:16:52 +08:00
|
|
|
$this->rewriteConfigs();
|
|
|
|
}
|
2018-02-10 07:11:55 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Reload the configuration
|
2018-02-10 07:11:55 +08:00
|
|
|
\App::boot();
|
|
|
|
|
|
|
|
$this->info('Recreating database');
|
2018-05-10 23:22:45 +08:00
|
|
|
$this->call('database:create', [
|
2018-02-10 07:11:55 +08:00
|
|
|
'--reset' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->info('Running migrations');
|
2018-05-10 23:22:45 +08:00
|
|
|
$this->call('migrate:fresh', [
|
2018-02-10 07:11:55 +08:00
|
|
|
'--seed' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->info('Done!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rewrite the configuration files
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-10 07:11:55 +08:00
|
|
|
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
|
|
|
*/
|
|
|
|
protected function rewriteConfigs()
|
|
|
|
{
|
|
|
|
$cfgSvc = app(ConfigService::class);
|
|
|
|
|
|
|
|
$this->info('Removing the old config files');
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Remove the old files
|
2018-02-10 07:11:55 +08:00
|
|
|
$config_file = base_path('config.php');
|
2018-03-20 09:50:40 +08:00
|
|
|
if (file_exists($config_file)) {
|
2018-02-10 07:11:55 +08:00
|
|
|
unlink($config_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
$env_file = base_path('env.php');
|
2018-03-20 09:50:40 +08:00
|
|
|
if (file_exists($env_file)) {
|
2018-02-10 07:11:55 +08:00
|
|
|
unlink($env_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->info('Removing the sqlite db');
|
|
|
|
$db_file = storage_path('db.sqlite');
|
2018-03-20 09:50:40 +08:00
|
|
|
if (file_exists($db_file)) {
|
2018-02-10 07:11:55 +08:00
|
|
|
unlink($db_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->info('Regenerating the config files');
|
|
|
|
$cfgSvc->createConfigFiles([
|
2018-03-20 09:50:40 +08:00
|
|
|
'APP_ENV' => 'dev',
|
2018-02-10 07:11:55 +08:00
|
|
|
'SITE_NAME' => 'phpvms test',
|
2018-03-20 09:50:40 +08:00
|
|
|
'DB_CONN' => 'sqlite',
|
2018-02-10 07:11:55 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->info('Config files generated!');
|
|
|
|
}
|
|
|
|
}
|