koel/app/Console/Commands/CheckLicenseStatusCommand.php

62 lines
2.1 KiB
PHP
Raw Normal View History

2024-01-05 16:42:50 +00:00
<?php
namespace App\Console\Commands;
use App\Services\License\Contracts\LicenseServiceInterface;
2024-01-05 16:42:50 +00:00
use App\Values\LicenseStatus;
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…');
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) {
case LicenseStatus::STATUS_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;
case LicenseStatus::STATUS_NO_LICENSE:
$this->components->info(
'No license found. You can purchase one at https://store.koel.dev/checkout/buy/'
. config('lemonsqueezy.plus_product_id')
2024-01-05 16:42:50 +00:00
);
break;
case LicenseStatus::STATUS_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;
}
}