Use Guzzle to download package archives
authorjoshuaruesweg <ruesweg@woltlab.com>
Wed, 21 Oct 2020 17:10:42 +0000 (19:10 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 23 Oct 2020 11:30:08 +0000 (13:30 +0200)
wcfsetup/install/files/lib/system/package/PackageArchive.class.php

index 1e9d5008835f50481a4a50ad4fe31cf873046c4e..7945a375692b770f13c9e0f9d6516d1aef1659d2 100644 (file)
@@ -1,7 +1,10 @@
 <?php
 namespace wcf\system\package;
+use GuzzleHttp\Psr7\Request;
 use wcf\data\package\Package;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\io\File;
+use wcf\system\io\HttpFactory;
 use wcf\system\package\validation\PackageValidationException;
 use wcf\system\io\Tar;
 use wcf\system\WCF;
@@ -426,13 +429,20 @@ class PackageArchive {
         * @return      string          path to the dowloaded file
         */
        public function downloadArchive() {
-               $prefix = 'package';
+               $tmpFile = FileUtil::getTemporaryFilename('package_');
                
-               // file transfer via hypertext transfer protocol.
-               $this->archive = FileUtil::downloadFileFromHttp($this->archive, $prefix);
+               $client = HttpFactory::getDefaultClient();
+               $request = new Request('GET', $this->archive);
+               $response = $client->send($request);
+               
+               $file = new File($tmpFile);
+               while (!$response->getBody()->eof()) {
+                       $file->write($response->getBody()->read(4096));
+               }
+               $file->close();
                
                // unzip tar
-               $this->archive = self::unzipPackageArchive($this->archive);
+               $this->archive = self::unzipPackageArchive($tmpFile);
                
                return $this->archive;
        }