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

Displays an error message if the license information couldn't be fetched #6003

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class ExpiringLicensesAcpDashboardBox extends AbstractAcpDashboardBox
{
private ?LicenseData $licenseData;
private array $expiredLicenses;
private bool $fetchLicenseDataFailed = false;

#[\Override]
public function isAccessible(): bool
Expand All @@ -29,7 +30,7 @@ public function isAccessible(): bool
#[\Override]
public function hasContent(): bool
{
return $this->getExpiredLicenses() !== [];
return $this->getExpiredLicenses() !== [] || $this->fetchLicenseDataFailed;
}

private function getExpiredLicenses(): array
Expand Down Expand Up @@ -61,7 +62,13 @@ private function getLicenseData(): ?LicenseData
{
if (!isset($this->licenseData)) {
$licenseApi = new LicenseApi();
$this->licenseData = $licenseApi->getUpToDateLicenseData();

try {
$this->licenseData = $licenseApi->getUpToDateLicenseData();
} catch (\Throwable) {
$this->licenseData = null;
$this->fetchLicenseDataFailed = true;
}
}

return $this->licenseData;
Expand All @@ -76,6 +83,15 @@ public function getTitle(): string
#[\Override]
public function getContent(): string
{
if ($this->fetchLicenseDataFailed) {
return \sprintf(
'<woltlab-core-notice type="error">%s</woltlab-core-notice>',
WCF::getLanguage()->getDynamicVariable('wcf.acp.license.error.parsingFailed', [
'licenseData' => null,
])
);
}

$packages = [];
foreach (\array_keys($this->getExpiredLicenses()) as $packageName) {
$packages[$packageName] = PackageCache::getInstance()->getPackageByIdentifier($packageName);
Expand Down
Loading