From fb9b8a919f92a77f26be6e7f70911315bfac12fc Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 27 Sep 2023 13:58:52 +0200 Subject: [PATCH] Remove the side effect of fetching the license data from the remote --- .../files/acp/update_com.woltlab.wcf_6.0_license.php | 4 ++-- .../lib/acp/form/FirstTimeSetupLicenseForm.class.php | 8 ++++++-- .../install/files/lib/acp/form/LicenseEditForm.class.php | 2 ++ wcfsetup/install/files/lib/acp/page/LicensePage.class.php | 5 ++++- .../files/lib/system/package/license/LicenseApi.class.php | 5 +---- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.0_license.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.0_license.php index c9a4afefd9..4280047a29 100644 --- a/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.0_license.php +++ b/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.0_license.php @@ -13,8 +13,8 @@ use wcf\data\package\update\server\PackageUpdateServerEditor; use wcf\system\package\license\LicenseApi; try { - // Side-effect: Writes the license file. - LicenseApi::fetchFromRemote(); + $licenseApi = LicenseApi::fetchFromRemote(); + $licenseApi->updateLicenseFile(); // If we’re still here it means that the credentials are actually valid. Now // we can check if the credentials for both servers are in sync, because diff --git a/wcfsetup/install/files/lib/acp/form/FirstTimeSetupLicenseForm.class.php b/wcfsetup/install/files/lib/acp/form/FirstTimeSetupLicenseForm.class.php index 374e30ab7f..a0e791341b 100644 --- a/wcfsetup/install/files/lib/acp/form/FirstTimeSetupLicenseForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/FirstTimeSetupLicenseForm.class.php @@ -152,8 +152,12 @@ final class FirstTimeSetupLicenseForm extends AbstractFormBuilderForm Option::getOptionByName('first_time_setup_state')->optionID => 1, ]; - if (isset($this->licenseApi) && isset($this->licenseApi->getData()['license']['authCode'])) { - $optionData[Option::getOptionByName('package_server_auth_code')->optionID] = $this->licenseApi->getData()['license']['authCode']; + if (isset($this->licenseApi)) { + $this->licenseApi->updateLicenseFile(); + + if (isset($this->licenseApi->getData()['license']['authCode'])) { + $optionData[Option::getOptionByName('package_server_auth_code')->optionID] = $this->licenseApi->getData()['license']['authCode']; + } } $objectAction = new OptionAction( diff --git a/wcfsetup/install/files/lib/acp/form/LicenseEditForm.class.php b/wcfsetup/install/files/lib/acp/form/LicenseEditForm.class.php index 4a1d1a831b..df8f4883eb 100644 --- a/wcfsetup/install/files/lib/acp/form/LicenseEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LicenseEditForm.class.php @@ -202,6 +202,8 @@ final class LicenseEditForm extends AbstractFormBuilderForm $authCode = ''; if (isset($this->licenseApi)) { + $this->licenseApi->updateLicenseFile(); + $authCode = $this->licenseApi->getData()['license']['authCode'] ?? ''; } else { LicenseApi::removeLicenseFile(); diff --git a/wcfsetup/install/files/lib/acp/page/LicensePage.class.php b/wcfsetup/install/files/lib/acp/page/LicensePage.class.php index 5811e65e4b..ed489c9d54 100644 --- a/wcfsetup/install/files/lib/acp/page/LicensePage.class.php +++ b/wcfsetup/install/files/lib/acp/page/LicensePage.class.php @@ -59,7 +59,10 @@ final class LicensePage extends AbstractPage (new PackageUpdateAction([], 'refreshDatabase'))->executeAction(); - $this->licenseData = LicenseApi::fetchFromRemote()->getData(); + $licenseApi = LicenseApi::fetchFromRemote(); + $licenseApi->updateLicenseFile(); + + $this->licenseData = $licenseApi->getData(); if (isset($this->licenseData['license']['licenseID'])) { $this->licenseNumber = $this->licenseData['license']['licenseID']; } diff --git a/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php b/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php index dbe9962c34..74a15b4147 100644 --- a/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php +++ b/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php @@ -111,10 +111,7 @@ final class LicenseApi $response = HttpFactory::makeClientWithTimeout(5)->send($request); - $licenseApi = new LicenseApi($response->getBody()); - $licenseApi->updateLicenseFile(); - - return $licenseApi; + return new LicenseApi($response->getBody()); } public static function readFromFile(): ?LicenseApi -- 2.20.1