koel/app/Console/Commands/DeactivateLicenseCommand.php

49 lines
1.4 KiB
PHP
Raw Normal View History

2024-01-08 13:02:26 +00:00
<?php
namespace App\Console\Commands;
use App\Services\License\Contracts\LicenseServiceInterface;
2024-01-08 13:02:26 +00:00
use Illuminate\Console\Command;
use Throwable;
class DeactivateLicenseCommand extends Command
{
protected $signature = 'koel:license:deactivate';
protected $description = 'Deactivate the currently active Koel Plus license';
2024-04-18 14:36:28 +00:00
public function __construct(private readonly LicenseServiceInterface $licenseService)
2024-01-08 13:02:26 +00:00
{
parent::__construct();
}
public function handle(): int
{
2024-04-18 14:36:28 +00:00
$status = $this->licenseService->getStatus();
2024-01-08 13:02:26 +00:00
if ($status->hasNoLicense()) {
$this->components->warn('No active Plus license found.');
return self::SUCCESS;
}
if (!$this->confirm('Are you sure you want to deactivate your Koel Plus license?')) {
$this->output->warning('License deactivation aborted.');
return self::SUCCESS;
}
$this->components->info('Deactivating your license…');
try {
2024-04-18 14:36:28 +00:00
$this->licenseService->deactivate($status->license);
2024-01-08 13:02:26 +00:00
$this->components->info('Koel Plus has been deactivated. Plus features are now disabled.');
return self::SUCCESS;
} catch (Throwable $e) {
$this->components->error('Failed to deactivate Koel Plus: ' . $e->getMessage());
return self::FAILURE;
}
}
}