Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Prompt for license when installing starter kit #10951

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Console/Commands/StarterKitInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function handle()
return;
}

$licenseManager = StarterKitLicenseManager::validate($package, $this->option('license'), $this);
$licenseManager = StarterKitLicenseManager::validate($package, $this->option('license'), $this, $this->input->isInteractive());

if (! $licenseManager->isValid()) {
return;
Expand Down
22 changes: 17 additions & 5 deletions src/StarterKits/LicenseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,36 @@
use Illuminate\Support\Facades\Http;
use Statamic\Console\NullConsole;

use function Laravel\Prompts\text;

final class LicenseManager
{
const OUTPOST_ENDPOINT = 'https://outpost.statamic.com/v3/starter-kits/';

private $package;
private $licenseKey;
private $console;
private $isInteractive;
private $details;
private $valid = false;

/**
* Instantiate starter kit license manager.
*/
public function __construct(string $package, ?string $licenseKey = null, ?Command $console = null)
public function __construct(string $package, ?string $licenseKey = null, ?Command $console = null, bool $isInteractive = false)
{
$this->package = $package;
$this->licenseKey = $licenseKey ?? config('statamic.system.license_key');
$this->console = $console ?? new NullConsole;
$this->isInteractive = $isInteractive;
}

/**
* Instantiate starter kit license manager.
*/
public static function validate(string $package, ?string $licenceKey = null, ?Command $console = null): self
public static function validate(string $package, ?string $licenceKey = null, ?Command $console = null, bool $isInteractive = false): self
{
return (new self($package, $licenceKey, $console))->performValidation();
return (new self($package, $licenceKey, $console, $isInteractive))->performValidation();
}

/**
Expand Down Expand Up @@ -74,10 +78,18 @@ private function performValidation(): self
$marketplaceUrl = "https://statamic.com/starter-kits/{$sellerSlug}/{$kitSlug}";

if (! $this->licenseKey) {
return $this
->error("License required for [{$this->package}]!")
if (! $this->isInteractive) {
return $this
->error("License required for [{$this->package}]!")
->comment('This is a paid starter kit. If you haven\'t already, you may purchase a license at:')
->comment($marketplaceUrl);
}

$this
->comment('This is a paid starter kit. If you haven\'t already, you may purchase a license at:')
->comment($marketplaceUrl);

$this->licenseKey = text('Please enter your license key', required: true);
}

if ($this->outpostValidatesLicense()) {
Expand Down
Loading