Use Guzzle in PackageAction::searchForPurchasedItems()
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 13 May 2022 14:01:16 +0000 (16:01 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 13 May 2022 14:01:50 +0000 (16:01 +0200)
see #4281

wcfsetup/install/files/bootstrap.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/package/PackageAction.class.php

diff --git a/wcfsetup/install/files/bootstrap.php b/wcfsetup/install/files/bootstrap.php
new file mode 100644 (file)
index 0000000..e7645d6
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+// try to set a time-limit to infinite
+@\set_time_limit(0);
+
+// define current unix timestamp
+\define('TIME_NOW', \time());
+
+// fix timezone warning issue
+if (!@\ini_get('date.timezone')) {
+       @\date_default_timezone_set('Europe/London');
+}
+
+require_once(WCF_DIR . 'lib/system/api/autoload.php');
+require_once(WCF_DIR . 'lib/core.functions.php');
+
+
index d68575bb2b227b8c8635f51bb03193d619ff3d84..dc17b8aebd90e3d78c5c88625d9f8743d9cb14dc 100644 (file)
@@ -2,12 +2,13 @@
 
 namespace wcf\data\package;
 
+use GuzzleHttp\Psr7\Request;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\SystemException;
+use wcf\system\io\HttpFactory;
 use wcf\system\request\LinkHandler;
 use wcf\system\WCF;
-use wcf\util\HTTPRequest;
 use wcf\util\JSON;
 
 /**
@@ -96,28 +97,38 @@ class PackageAction extends AbstractDatabaseObjectAction
             ];
         }
 
-        $request = new HTTPRequest('https://api.woltlab.com/1.1/customer/purchases/list.json', [
-            'method' => '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'),