koel/app/Console/Commands/DeactivateLicenseCommand.php

49 lines
1.3 KiB
PHP
Raw Normal View History

2024-01-08 13:02:26 +00:00
<?php
namespace App\Console\Commands;
2024-01-09 18:34:40 +00:00
use App\Services\License\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-01-09 18:34:40 +00:00
public function __construct(private LicenseServiceInterface $plusService)
2024-01-08 13:02:26 +00:00
{
parent::__construct();
}
public function handle(): int
{
$status = $this->plusService->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-01-09 18:34:40 +00:00
$this->plusService->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;
}
}
}