added install:refresh command

This commit is contained in:
Denis Duliçi 2020-06-17 16:07:47 +03:00
parent 1b8aa23371
commit 43d1dea4a4
2 changed files with 69 additions and 8 deletions

View File

@ -57,7 +57,7 @@ class Install extends Command
public function handle() public function handle()
{ {
if (($missing_options = $this->getMissingOptions()) && $this->option(self::OPT_NO_INTERACTION)) { if (($missing_options = $this->getMissingOptions()) && $this->option(self::OPT_NO_INTERACTION)) {
$this->line('❌ Some options are missing and --no-interaction is present. Please run the following command for more informations :'); $this->line('❌ Some options are missing and --no-interaction is present. Please run the following command for more information :');
$this->line('❌ php artisan help install'); $this->line('❌ php artisan help install');
$this->line('❌ Missing options are : ' . implode(', ', $missing_options)); $this->line('❌ Missing options are : ' . implode(', ', $missing_options));
@ -111,6 +111,8 @@ class Install extends Command
'OPT_ADMIN_PASSWORD' 'OPT_ADMIN_PASSWORD'
]; ];
$allowed_empty = ['db_password', 'db_prefix'];
foreach ($contants as $const) { foreach ($contants as $const) {
$option = constant("self::$const"); $option = constant("self::$const");
@ -118,15 +120,16 @@ class Install extends Command
$this->$property = $this->option($option); $this->$property = $this->option($option);
if (empty($this->$property)) { if (!empty($this->$property)) {
// Allow empty password continue;
if ($property == 'db_password') { }
if (in_array($property, $allowed_empty)) {
continue; continue;
} }
$missing_options[] = $option; $missing_options[] = $option;
} }
}
return $missing_options; return $missing_options;
} }

View File

@ -0,0 +1,58 @@
<?php
namespace App\Console\Commands;
use App\Models\Auth\User;
use App\Models\Common\Company;
use Illuminate\Console\Command;
class InstallRefresh extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'install:refresh {--admin-password=123456}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Allows to refresh Akaunting installation directly through CLI';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$user = User::first();
$company = Company::first();
$this->info('Resetting migrations');
$this->callSilent('migrate:reset', [
'--force' => true,
]);
$this->info('Installing Akaunting');
$this->callSilent('install', [
'--db-host' => env('DB_HOST'),
'--db-port' => env('DB_PORT'),
'--db-name' => env('DB_DATABASE'),
'--db-username' => env('DB_USERNAME'),
'--db-password' => env('DB_PASSWORD'),
'--db-prefix' => env('DB_PREFIX'),
'--company-name' => $company->name,
'--company-email' => $company->email,
'--admin-email' => $user->email,
'--admin-password' => $this->option('admin-password'),
'--locale' => $company->locale,
'--no-interaction' => true,
]);
$this->info('Installation refreshed');
}
}