Displays an error message if the license information couldn't be fetched.
authorCyperghost <olaf_schmitz_1@t-online.de>
Mon, 30 Sep 2024 07:50:13 +0000 (09:50 +0200)
committerCyperghost <olaf_schmitz_1@t-online.de>
Mon, 30 Sep 2024 07:50:13 +0000 (09:50 +0200)
wcfsetup/install/files/lib/system/acp/dashboard/box/ExpiringLicensesAcpDashboardBox.class.php

index 0f69f5c7e7df186f9f1a1cb24dcbac858c794c24..c5b63cf39bcec7eca67264dd86fc8590b3eb9dd5 100644 (file)
@@ -19,6 +19,7 @@ final class ExpiringLicensesAcpDashboardBox extends AbstractAcpDashboardBox
 {
     private ?LicenseData $licenseData;
     private array $expiredLicenses;
+    private bool $fetchLicenseDataFailed = false;
 
     #[\Override]
     public function isAccessible(): bool
@@ -29,7 +30,7 @@ final class ExpiringLicensesAcpDashboardBox extends AbstractAcpDashboardBox
     #[\Override]
     public function hasContent(): bool
     {
-        return $this->getExpiredLicenses() !== [];
+        return $this->getExpiredLicenses() !== [] || $this->fetchLicenseDataFailed;
     }
 
     private function getExpiredLicenses(): array
@@ -61,7 +62,13 @@ final class ExpiringLicensesAcpDashboardBox extends AbstractAcpDashboardBox
     {
         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;
@@ -76,6 +83,15 @@ final class ExpiringLicensesAcpDashboardBox extends AbstractAcpDashboardBox
     #[\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);