Skip to content

feat: Add Cms\License::delete() & ::root() #7211

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

Draft
wants to merge 1 commit into
base: v5/develop
Choose a base branch
from
Draft
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
38 changes: 30 additions & 8 deletions src/Cms/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class License

protected const SALT = 'kwAHMLyLPBnHEskzH9pPbJsBxQhKXZnX';

protected App $kirby;

// cache
protected LicenseStatus $status;
protected LicenseType $type;
Expand All @@ -51,6 +53,8 @@ public function __construct(
if ($email !== null) {
$this->email = $this->normalizeEmail($email);
}

$this->kirby = App::instance();
}

/**
Expand Down Expand Up @@ -101,6 +105,15 @@ public function date(
return $this->date !== null ? Str::date(strtotime($this->date), $format, $handler) : null;
}

/**
* Deletes the license file if it exists
* @since 5.0.0
*/
public function delete(): bool
{
return F::remove($this->root());
}

/**
* Returns the activation domain if available
*/
Expand Down Expand Up @@ -180,7 +193,7 @@ public function isLegacy(): bool
}

// get release date of current major version
$major = Str::before(App::instance()->version(), '.');
$major = Str::before($this->kirby->version(), '.');
$release = strtotime(static::HISTORY[$major] ?? '');

// if there's no matching version in the history
Expand Down Expand Up @@ -220,7 +233,7 @@ public function isOnCorrectDomain(): bool
}

// compare domains
if ($this->normalizeDomain(App::instance()->system()->indexUrl()) !== $this->normalizeDomain($this->domain)) {
if ($this->normalizeDomain($this->kirby->system()->indexUrl()) !== $this->normalizeDomain($this->domain)) {
return false;
}

Expand All @@ -237,7 +250,7 @@ public function isSigned(): bool
}

// get the public key
$pubKey = F::read(App::instance()->root('kirby') . '/kirby.pub');
$pubKey = F::read($this->kirby->root('kirby') . '/kirby.pub');

// verify the license signature
$data = json_encode($this->signatureData());
Expand Down Expand Up @@ -329,7 +342,7 @@ public static function polyfill(array $license): array
public static function read(): static
{
try {
$license = Json::read(App::instance()->root('license'));
$license = Json::read(static::root());
} catch (Throwable) {
return new static();
}
Expand Down Expand Up @@ -410,6 +423,15 @@ public function request(string $path, array $data): array
// @codeCoverageIgnoreEnd
}

/**
* Returns the root path to the license file
* @since 5.0.0
*/
public static function root(): string
{
return App::instance()->root('license');
}

/**
* Saves the license in the config folder
*/
Expand All @@ -421,11 +443,11 @@ public function save(): bool
);
}

// where to store the license file
$file = App::instance()->root('license');

// save the license information
return Json::write($file, $this->content());
return Json::write(
file: $this->root(),
data: $this->content()
);
}

/**
Expand Down
Loading
Loading