koel/app/Console/Commands/CheckLicenseStatusCommand.php

67 lines
2.3 KiB
PHP
Raw Normal View History

2024-01-05 16:42:50 +00:00
<?php
namespace App\Console\Commands;
2024-04-18 17:20:14 +00:00
use App\Enums\LicenseStatus;
use App\Models\License;
use App\Services\License\Contracts\LicenseServiceInterface;
2024-01-05 16:42:50 +00:00
use Illuminate\Console\Command;
use Throwable;
class CheckLicenseStatusCommand extends Command
{
protected $signature = 'koel:license:status';
2024-03-09 12:20:36 +00:00
protected $description = 'Check the current Koel Plus license status';
2024-01-05 16:42:50 +00:00
2024-04-18 14:36:28 +00:00
public function __construct(private readonly LicenseServiceInterface $licenseService)
2024-01-05 16:42:50 +00:00
{
parent::__construct();
}
public function handle(): int
{
$this->components->info('Checking your Koel Plus license status…');
if (License::count() > 1) {
$this->components->warn('Multiple licenses found. This can cause unexpected behaviors.');
}
2024-01-05 16:42:50 +00:00
try {
2024-01-08 13:02:26 +00:00
$status = $this->licenseService->getStatus(checkCache: false);
2024-01-05 16:42:50 +00:00
switch ($status->status) {
2024-04-18 17:20:14 +00:00
case LicenseStatus::VALID:
2024-01-08 13:02:26 +00:00
$this->output->success('You have a valid Koel Plus license. All Plus features are enabled.');
2024-01-05 16:42:50 +00:00
$this->components->twoColumnDetail('License Key', $status->license->short_key);
$this->components->twoColumnDetail(
'Registered To',
"{$status->license->meta->customerName} <{$status->license->meta->customerEmail}>"
);
$this->components->twoColumnDetail('Expires On', 'Never ever');
2024-01-07 12:43:10 +00:00
$this->newLine();
2024-01-05 16:42:50 +00:00
break;
2024-04-18 17:20:14 +00:00
case LicenseStatus::NO_LICENSE:
2024-01-05 16:42:50 +00:00
$this->components->info(
2024-04-18 17:20:14 +00:00
'No license found. You can purchase one at https://store.koel.dev'
. config('lemonsqueezy.plus_product_id')
2024-01-05 16:42:50 +00:00
);
break;
2024-04-18 17:20:14 +00:00
case LicenseStatus::INVALID:
2024-01-08 13:02:26 +00:00
$this->components->error('Your license is invalid. Plus features will not be available.');
2024-01-05 16:42:50 +00:00
break;
default:
$this->components->warn('Your license status is unknown. Please try again later.');
}
} catch (Throwable $e) {
$this->output->error($e->getMessage());
}
return self::SUCCESS;
}
}