From: Tim Düsterhus Date: Fri, 29 Sep 2023 13:51:45 +0000 (+0200) Subject: Merge pull request #5673 from WoltLab/license-page-graceful X-Git-Tag: 6.0.0~32 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c65c41771ba2b401d32b449b8750231bdca541b7;p=GitHub%2FWoltLab%2FWCF.git Merge pull request #5673 from WoltLab/license-page-graceful Gracefully handle failed license update requests in LicensePage --- c65c41771ba2b401d32b449b8750231bdca541b7 diff --cc wcfsetup/install/files/lib/acp/page/LicensePage.class.php index 1bfaad9bf4,3b468064d0..74ca898fc6 --- a/wcfsetup/install/files/lib/acp/page/LicensePage.class.php +++ b/wcfsetup/install/files/lib/acp/page/LicensePage.class.php @@@ -9,9 -9,11 +9,11 @@@ use wcf\data\package\update\PackageUpda 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\package\PackageUpdateDispatcher; use wcf\system\request\LinkHandler; use wcf\system\WCF; @@@ -58,11 -60,32 +60,32 @@@ final class LicensePage extends Abstrac ); } - (new PackageUpdateAction([], 'refreshDatabase'))->executeAction(); + PackageUpdateDispatcher::getInstance()->refreshPackageDatabase(); $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),