Files

56 lines
1.9 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class DeployTenantCommand extends Command
{
protected $signature = 'deploy:tenant
{database?* : نام دیتابیس برای settings:deploy (پیش‌فرض DB_DATABASE)}
{--preserve : deploy_settings_const_preserve_value_sync_can_edit.sql}
{--file= : مسیر SQL سفارشی برای settings:deploy}
{--skip-migrate : فقط settings:deploy}
{--skip-settings : فقط migrate}';
protected $description = 'migrate + deploy_settings_const.sql — دیپلوی DB tenant با یک دستور';
public function handle(): int
{
if (! $this->option('skip-migrate')) {
$this->info('==> 1/2 php artisan migrate --force');
if ($this->call('migrate', ['--force' => true]) !== self::SUCCESS) {
$this->error('migrate ناموفق بود.');
return self::FAILURE;
}
}
if (! $this->option('skip-settings')) {
$this->info('==> 2/2 php artisan settings:deploy');
$settingsArgs = [];
$databases = $this->argument('database');
if ($databases !== [] && $databases !== null) {
$settingsArgs['database'] = $databases;
}
if ($this->option('preserve')) {
$settingsArgs['--preserve'] = true;
}
if ($this->option('file')) {
$settingsArgs['--file'] = $this->option('file');
}
if ($this->call('settings:deploy', $settingsArgs) !== self::SUCCESS) {
$this->error('settings:deploy ناموفق بود.');
return self::FAILURE;
}
}
$this->info('==> deploy:tenant done');
return self::SUCCESS;
}
}