From 4db740c131c0f04b2efdce026d154f8b6a5b9a5e Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 31 Aug 2023 11:28:36 +0200 Subject: [PATCH] Replace the hard-wired data for the package server --- .../files/lib/acp/page/LicensePage.class.php | 16 ++++++++-------- .../update/server/PackageUpdateServer.class.php | 9 +++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/page/LicensePage.class.php b/wcfsetup/install/files/lib/acp/page/LicensePage.class.php index ef4fb835bf..0d48b5e080 100644 --- a/wcfsetup/install/files/lib/acp/page/LicensePage.class.php +++ b/wcfsetup/install/files/lib/acp/page/LicensePage.class.php @@ -28,10 +28,14 @@ final class LicensePage extends AbstractPage private array $packageUpdates = []; + private PackageUpdateServer $updateServer; + public function readData() { parent::readData(); + $this->updateServer = PackageUpdateServer::getWoltLabUpdateServer(); + // TODO: We actually need to fetch the data from the official package // update servers first, because we rely on the human readable names. @@ -79,10 +83,6 @@ final class LicensePage extends AbstractPage }); } - // TODO: This might need to use `getAuthData()` to inject the correct - // credentials for the WoltLab Cloud. - $this->licenseNumber = (new PackageUpdateServer(1))->loginUsername; - // TODO: We need the data from the official package update servers to // determine the human readable values for each package and to filter // out those that are incompatible with the installed version. @@ -581,8 +581,8 @@ final class LicensePage extends AbstractPage // latest purchases. private function fetchLicenseData(): array|object { - // TODO: Fixed server id - $pus = new PackageUpdateServer(1); + $authData = $this->updateServer->getAuthData(); + $this->licenseNumber = $authData['username']; $request = new Request( 'POST', @@ -591,8 +591,8 @@ final class LicensePage extends AbstractPage 'content-type' => 'application/x-www-form-urlencoded', ], \http_build_query([ - 'licenseNo' => $pus->loginUsername, - 'serialNo' => $pus->loginPassword, + 'licenseNo' => $this->licenseNumber, + 'serialNo' => $authData['password'], 'instanceId' => \hash_hmac('sha256', 'api.woltlab.com', \WCF_UUID), ], '', '&', \PHP_QUERY_RFC1738) ); diff --git a/wcfsetup/install/files/lib/data/package/update/server/PackageUpdateServer.class.php b/wcfsetup/install/files/lib/data/package/update/server/PackageUpdateServer.class.php index d76cbd9f54..dea4c3e22a 100644 --- a/wcfsetup/install/files/lib/data/package/update/server/PackageUpdateServer.class.php +++ b/wcfsetup/install/files/lib/data/package/update/server/PackageUpdateServer.class.php @@ -151,6 +151,15 @@ class PackageUpdateServer extends DatabaseObject return \current($pluginStoreServer); } + final public static function getWoltLabUpdateServer(): self + { + $pluginStoreServer = \array_filter(self::getActiveUpdateServers(), static function (self $updateServer) { + return $updateServer->isWoltLabUpdateServer(); + }); + + return \current($pluginStoreServer); + } + /** * Restricts the available sources to official package * servers when a secure download is requested. -- 2.20.1