mirror of
https://github.com/joomla-extensions/patchtester.git
synced 2025-01-12 18:01:13 +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\Component\ComponentHelper;
|
||||||
use Joomla\CMS\Factory;
|
use Joomla\CMS\Factory;
|
||||||
use Joomla\CMS\Filesystem\Path;
|
use Joomla\CMS\Filesystem\Path;
|
||||||
|
use Joomla\CMS\Http\HttpFactory;
|
||||||
use Joomla\CMS\Http\Response;
|
use Joomla\CMS\Http\Response;
|
||||||
use Joomla\CMS\Language\Text;
|
use Joomla\CMS\Language\Text;
|
||||||
use Joomla\CMS\Version;
|
use Joomla\CMS\Version;
|
||||||
use Joomla\Filesystem\File;
|
use Joomla\Filesystem\File;
|
||||||
use Joomla\Filesystem\Folder;
|
use Joomla\Filesystem\Folder;
|
||||||
|
use Joomla\Registry\Registry;
|
||||||
use PatchTester\GitHub\Exception\UnexpectedResponse;
|
use PatchTester\GitHub\Exception\UnexpectedResponse;
|
||||||
use PatchTester\GitHub\GitHub;
|
use PatchTester\GitHub\GitHub;
|
||||||
use PatchTester\Helper;
|
use PatchTester\Helper;
|
||||||
@ -218,24 +220,40 @@ class PullModel extends AbstractModel
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if zip folder exists on server
|
$version = new Version;
|
||||||
$serverHeaders = @get_headers($serverZipPath);
|
$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'));
|
throw new \RuntimeException(Text::_('COM_PATCHTESTER_SERVER_RESPONDED_NOT_200'));
|
||||||
}
|
}
|
||||||
|
|
||||||
Folder::create($tempPath);
|
// Assign to variable to avlod PHP notice "Indirect modification of overloaded property"
|
||||||
file_put_contents($zipPath, fopen($serverZipPath, "r"));
|
$content = (string) $result->getBody();
|
||||||
|
|
||||||
|
// Write the file to disk
|
||||||
|
File::write($zipPath, $content);
|
||||||
|
|
||||||
// Check if zip folder could have been downloaded
|
// Check if zip folder could have been downloaded
|
||||||
if (!file_exists($zipPath))
|
if (!file_exists($zipPath))
|
||||||
{
|
{
|
||||||
Folder::delete($tempPath);
|
|
||||||
throw new \RuntimeException(Text::_('COM_PATCHTESTER_ZIP_DOES_NOT_EXIST'));
|
throw new \RuntimeException(Text::_('COM_PATCHTESTER_ZIP_DOES_NOT_EXIST'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Folder::create($tempPath);
|
||||||
|
|
||||||
$zip = new Zip;
|
$zip = new Zip;
|
||||||
|
|
||||||
if (!$zip->extract($zipPath, $tempPath))
|
if (!$zip->extract($zipPath, $tempPath))
|
||||||
|
Loading…
Reference in New Issue
Block a user