33
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2025-02-13 17:28:25 +00:00

Merge pull request #256 from richard67/master-use-http-factory-to-fetch-remote-files

Use HttpFactory to fetch zip file from CI server
This commit is contained in:
Roland Dalmulder 2020-03-21 11:33:20 +01:00 committed by GitHub
commit 235e8ad289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,11 +12,13 @@ use Joomla\Archive\Zip;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Http\HttpFactory;
use Joomla\CMS\Http\Response;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Version;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Folder;
use Joomla\Registry\Registry;
use PatchTester\GitHub\Exception\UnexpectedResponse;
use PatchTester\GitHub\GitHub;
use PatchTester\Helper;
@ -218,24 +220,40 @@ class PullModel extends AbstractModel
return false;
}
// Check if zip folder exists on server
$serverHeaders = @get_headers($serverZipPath);
$version = new Version;
$httpOption = new Registry;
$httpOption->set('userAgent', $version->getUserAgent('Joomla', true, false));
if (!$serverHeaders || $serverHeaders[0] != 'HTTP/1.1 200 OK')
// Try to download the zip file
try
{
$http = HttpFactory::getHttp($httpOption);
$result = $http->get($serverZipPath);
}
catch (\RuntimeException $e)
{
$result = null;
}
if ($result === null || ($result->getStatusCode() !== 200 && $result->getStatusCode() !== 310))
{
throw new \RuntimeException(Text::_('COM_PATCHTESTER_SERVER_RESPONDED_NOT_200'));
}
Folder::create($tempPath);
file_put_contents($zipPath, fopen($serverZipPath, "r"));
// Assign to variable to avlod PHP notice "Indirect modification of overloaded property"
$content = (string) $result->getBody();
// Write the file to disk
File::write($zipPath, $content);
// Check if zip folder could have been downloaded
if (!file_exists($zipPath))
{
Folder::delete($tempPath);
throw new \RuntimeException(Text::_('COM_PATCHTESTER_ZIP_DOES_NOT_EXIST'));
}
Folder::create($tempPath);
$zip = new Zip;
if (!$zip->extract($zipPath, $tempPath))