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;
|
2024-07-14 12:17:22 +00:00
|
|
|
use App\Models\License;
|
2024-02-23 18:36:02 +00:00
|
|
|
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…');
|
|
|
|
|
2024-07-14 12:17:22 +00:00
|
|
|
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'
|
2024-03-22 14:02:07 +00:00
|
|
|
. 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;
|
|
|
|
}
|
|
|
|
}
|