mirror of
https://github.com/joomla-extensions/patchtester.git
synced 2025-01-12 09:51:18 +00:00
Use HttpFactory to download zip file
This commit is contained in:
parent
fa314fbcc0
commit
7e47be334b
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user