2018-02-10 07:11:55 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Console\Command;
|
2018-02-10 07:11:55 +08:00
|
|
|
use Modules\Installer\Services\ConfigService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a fresh development install
|
|
|
|
* @package App\Console\Commands
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class DevInstall extends Command
|
2018-02-10 07:11:55 +08:00
|
|
|
{
|
2018-02-10 07:16:52 +08:00
|
|
|
protected $signature = 'phpvms:dev-install {--reset-db}';
|
2018-02-10 07:11:55 +08:00
|
|
|
protected $description = 'Run a developer install and run the sample migration';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run dev related commands
|
|
|
|
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2018-03-20 09:50:40 +08:00
|
|
|
if (!$this->option('reset-db')) {
|
2018-02-10 07:16:52 +08:00
|
|
|
$this->rewriteConfigs();
|
|
|
|
}
|
2018-02-10 07:11:55 +08:00
|
|
|
|
|
|
|
# Reload the configuration
|
|
|
|
\App::boot();
|
|
|
|
|
|
|
|
$this->info('Recreating database');
|
|
|
|
\Artisan::call('database:create', [
|
|
|
|
'--reset' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->info(\Artisan::output());
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
$this->info('Running migrations');
|
|
|
|
\Artisan::call('migrate:fresh', [
|
|
|
|
'--seed' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->info(\Artisan::output());
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
$this->info('Importing sample data');
|
2018-05-03 04:14:18 +08:00
|
|
|
\Artisan::call('phpvms:yaml-import', [
|
2018-02-10 07:11:55 +08:00
|
|
|
'files' => ['app/Database/seeds/sample.yml'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->info(\Artisan::output());
|
|
|
|
|
|
|
|
$this->info('Done!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rewrite the configuration files
|
|
|
|
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
|
|
|
*/
|
|
|
|
protected function rewriteConfigs()
|
|
|
|
{
|
|
|
|
$cfgSvc = app(ConfigService::class);
|
|
|
|
|
|
|
|
$this->info('Removing the old config files');
|
|
|
|
|
|
|
|
# Remove the old files
|
|
|
|
$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!');
|
|
|
|
}
|
|
|
|
}
|