From 4f33a332b8aaf66e6c2fb1c9919063146c328c56 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 13 May 2022 16:01:16 +0200 Subject: [PATCH] Use Guzzle in PackageAction::searchForPurchasedItems() see #4281 --- wcfsetup/install/files/bootstrap.php | 17 +++++++ .../lib/data/package/PackageAction.class.php | 45 ++++++++++++------- 2 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 wcfsetup/install/files/bootstrap.php diff --git a/wcfsetup/install/files/bootstrap.php b/wcfsetup/install/files/bootstrap.php new file mode 100644 index 0000000000..e7645d67de --- /dev/null +++ b/wcfsetup/install/files/bootstrap.php @@ -0,0 +1,17 @@ + 'POST', - ], [ - 'username' => $this->parameters['username'], - 'password' => $this->parameters['password'], - 'wcfVersion' => WCF_VERSION, - ]); - - $request->execute(); - $reply = $request->getReply(); - $response = JSON::decode($reply['body']); - - $code = $response['status'] ?? 500; + $client = HttpFactory::makeClientWithTimeout(5); + $request = new Request( + 'POST', + 'https://api.woltlab.com/1.1/customer/purchases/list.json', + [ + 'content-type' => 'application/x-www-form-urlencoded', + ], + \http_build_query( + [ + 'username' => $this->parameters['username'], + 'password' => $this->parameters['password'], + 'wcfVersion' => WCF_VERSION, + ], + '', + '&', + \PHP_QUERY_RFC1738 + ) + ); + + $response = $client->send($request); + $payload = JSON::decode((string)$response->getBody()); + + $code = $payload['status'] ?? 500; switch ($code) { case 200: - if (empty($response['products'])) { + if (empty($payload['products'])) { return [ 'noResults' => WCF::getLanguage()->getDynamicVariable('wcf.acp.pluginStore.purchasedItems.noResults'), ]; } else { - WCF::getSession()->register('__pluginStoreProducts', $response['products']); - WCF::getSession()->register('__pluginStoreWcfMajorReleases', $response['wcfMajorReleases']); + WCF::getSession()->register('__pluginStoreProducts', $payload['products']); + WCF::getSession()->register('__pluginStoreWcfMajorReleases', $payload['wcfMajorReleases']); return [ 'redirectURL' => LinkHandler::getInstance()->getLink('PluginStorePurchasedItems'), -- 2.20.1