You've already forked Atomcms-edit
50 lines
1.6 KiB
PHP
Executable File
50 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\NitroUpdateService;
|
|
use App\Services\SettingsService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class SwitchNitroBranch extends Command
|
|
{
|
|
#[\Override]
|
|
protected $signature = 'app:switch-nitro-branch {--branch=main}';
|
|
|
|
#[\Override]
|
|
protected $description = 'Switch Nitro to a specific branch (runs in background)';
|
|
|
|
public function handle(): int
|
|
{
|
|
$branch = $this->option('branch') ?? 'main';
|
|
|
|
$this->info("🔄 Switching Nitro to branch: {$branch}");
|
|
|
|
try {
|
|
$nitroService = new NitroUpdateService;
|
|
$result = $nitroService->updateNitro(true);
|
|
|
|
if ($result['success'] ?? false) {
|
|
$this->info("✅ Switched to {$branch} successfully!");
|
|
$this->info($result['message'] ?? '');
|
|
Log::info('[NitroSwitch] Success', ['branch' => $branch, 'message' => $result['message'] ?? '']);
|
|
} else {
|
|
$this->error('❌ Switch failed: ' . ($result['error'] ?? 'Unknown error'));
|
|
Log::error('[NitroSwitch] Failed', ['branch' => $branch, 'error' => $result['error'] ?? 'Unknown']);
|
|
}
|
|
|
|
Cache::forget('website_settings');
|
|
SettingsService::clearCache();
|
|
|
|
return ($result['success'] ?? false) ? 0 : 1;
|
|
} catch (\Exception $e) {
|
|
$this->error('❌ Exception: ' . $e->getMessage());
|
|
Log::error('[NitroSwitch] Exception', ['branch' => $branch, 'error' => $e->getMessage()]);
|
|
|
|
return 1;
|
|
}
|
|
}
|
|
}
|