Gracefully handle failed license update requests in LicensePage
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 29 Sep 2023 13:19:37 +0000 (15:19 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 29 Sep 2023 13:19:37 +0000 (15:19 +0200)
wcfsetup/install/files/lib/acp/page/LicensePage.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 6ecb670e6e95ee8e66bd57e869fc74d9f16f6a49..3b468064d0fd611f4d3208071f1cc2d57b91de91 100644 (file)
@@ -10,6 +10,8 @@ use wcf\data\package\update\PackageUpdateAction;
 use wcf\data\package\update\server\PackageUpdateServer;
 use wcf\page\AbstractPage;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\exception\NamedUserException;
+use wcf\system\package\license\exception\ParsingFailed;
 use wcf\system\package\license\LicenseApi;
 use wcf\system\package\license\LicenseData;
 use wcf\system\request\LinkHandler;
@@ -61,8 +63,29 @@ final class LicensePage extends AbstractPage
         (new PackageUpdateAction([], 'refreshDatabase'))->executeAction();
 
         $licenseApi = new LicenseApi();
-        $this->licenseData = $licenseApi->fetchFromRemote();
-        $licenseApi->updateLicenseFile($this->licenseData);
+        try {
+            $this->licenseData = $licenseApi->readFromFile();
+
+            if (
+                $this->licenseData === null
+                // Cache valid license data for 2 minutes.
+                || $this->licenseData->creationDate->getTimestamp() < (\TIME_NOW - 2 * 60)
+            ) {
+                $this->licenseData = $licenseApi->fetchFromRemote();
+                $licenseApi->updateLicenseFile($this->licenseData);
+            }
+        } catch (ParsingFailed $e) {
+            if (\ENABLE_DEBUG_MODE && \ENABLE_DEVELOPER_TOOLS) {
+                throw $e;
+            }
+
+            throw new NamedUserException(WCF::getLanguage()->getDynamicVariable(
+                'wcf.acp.license.error.parsingFailed',
+                [
+                    'licenseData' => $this->licenseData,
+                ]
+            ));
+        }
 
         $identifiers = \array_merge(
             \array_keys($this->licenseData->woltlab),
index 8302a4237d5af3b032e45ecdb0eb6b216971b5f0..f421141f91540c0308c033421edb2aebee52e83e 100644 (file)
@@ -1079,6 +1079,7 @@ Die Entwickler-Lizenz gestattet ausschließlich den Einsatz während der Entwick
                <item name="wcf.acp.license.package.installed"><![CDATA[Bereits installiert]]></item>
                <item name="wcf.acp.license.package.outdated"><![CDATA[Bis Version {$accessibleVersion}]]></item>
                <item name="wcf.acp.license.package.version"><![CDATA[Version]]></item>
+               <item name="wcf.acp.license.error.parsingFailed"><![CDATA[Die Aktualisierung der Lizenzinformationen ist fehlgeschlagen. Bitte <a href="{link controller="LicenseEdit"}{/link}">{if LANGUAGE_USE_INFORMAL_VARIANT}kontrolliere und aktualisiere{else}kontrollieren und aktualisieren Sie{/if} die Lizenzdaten</a>.{if $licenseData !== null} Der letzte erfolgreiche Abruf der Lizenzinformationen erfolgte am {time type='plainTime' time=$licenseData->creationDate}.{/if}]]></item>
        </category>
        <category name="wcf.acp.menu">
                <item name="wcf.acp.menu.link.management"><![CDATA[Verwaltung]]></item>
index 97278e2ccfc5304b117c8d9ad81996393ed7d2e8..18fb37b18d1979d84b7601eabde9d57a122d9fcc 100644 (file)
@@ -1057,6 +1057,7 @@ The developer license permits exclusively the use during the development as well
                <item name="wcf.acp.license.package.installed"><![CDATA[Already installed]]></item>
                <item name="wcf.acp.license.package.outdated"><![CDATA[Up to version {$accessibleVersion}]]></item>
                <item name="wcf.acp.license.package.version"><![CDATA[Version]]></item>
+               <item name="wcf.acp.license.error.parsingFailed"><![CDATA[Updating the license metadata failed. Please <a href="{link controller="LicenseEdit"}{/link}">verify and update the license credentials</a>.{if $licenseData !== null} The metadata was last updated on {time type='plainTime' time=$licenseData->creationDate}.{/if}]]></item>
        </category>
        <category name="wcf.acp.menu">
                <item name="wcf.acp.menu.link.management"><![CDATA[Management]]></item>