diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index 8c6bfe22..69bcd6f9 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -12,11 +12,13 @@ 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 @@ private function applyWithCIServer($id) 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))