diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a074804..e8d4851 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,9 +1,10 @@ Changelog ========= -2.1.10 (Unreleased) --------------------------- +2.1.10 (April 13, 2022) +------------------------ - Enh #24: Show current update channel with link to module configuration +- Enh: Removed Zend HTTP requirement 2.1.9 (February 5, 2021) -------------------------- diff --git a/libs/AvailableUpdate.php b/libs/AvailableUpdate.php index 7430167..2a5d830 100644 --- a/libs/AvailableUpdate.php +++ b/libs/AvailableUpdate.php @@ -37,16 +37,36 @@ public function download() // Download Package if (!is_file($targetFile)) { try { - $http = new \Zend\Http\Client($this->downloadUrl, array( - 'adapter' => '\Zend\Http\Client\Adapter\Curl', - 'curloptions' => Yii::$app->getModule('updater')->getCurlOptions(), - 'timeout' => 300 - )); - $http->setStream(); - $response = $http->send(); - copy($response->getStreamName(), $targetFile); - } catch (Exception $ex) { - throw new Exception(Yii::t('UpdaterModule.libs_UpdatePackage', 'Update download failed! (%error%)', array('%error%' => $ex->getMessage()))); + if (class_exists('\yii\httpclient\Client')) { + $fh = fopen($targetFile, 'w'); + $client = new \yii\httpclient\Client([ + 'transport' => 'yii\httpclient\CurlTransport' + ]); + $response = $client->createRequest() + ->setMethod('GET') + ->setUrl($this->downloadUrl) + ->setOutputFile($fh) + ->setOptions(Yii::$app->getModule('updater')->getCurlOptions()) + ->send(); + + if (!$response->isOk) { + Yii::error('Could not download upgrade package: ' . $response->getStatusCode()); + throw new \Exception('Download Response is not ok!'); + } + } else { + // Older Versions + $http = new \Zend\Http\Client($this->downloadUrl, array( + 'adapter' => '\Zend\Http\Client\Adapter\Curl', + 'curloptions' => Yii::$app->getModule('updater')->getCurlOptions(), + 'timeout' => 300 + )); + $http->setStream(); + $response = $http->send(); + copy($response->getStreamName(), $targetFile); + } + + } catch (\Exception $ex) { + throw new \Exception(Yii::t('UpdaterModule.libs_UpdatePackage', 'Update download failed! (%error%)', array('%error%' => $ex->getMessage()))); } }