Skip to content

Commit

Permalink
Refactor image synchronization in ClientTransfer class (#753)
Browse files Browse the repository at this point in the history
* Refactor image synchronization in ClientTransfer class

* Refactor error message in ClientTransfer.php

* Enhanced error handling for proxy command file synchronization
  • Loading branch information
nadar authored Feb 7, 2024
1 parent 6bad156 commit cb1f959
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE
+ [#749](https://github.com/luyadev/luya-module-admin/pull/749) Added a new property, `luya\admin\Module::$apiUserTrackLastActivity`, which controls the update of the last activity timestamp for API users. By default, this feature is enabled to maintain backward compatibility. For larger systems, disabling this property can prevent unnecessary database writes.
+ [#751](https://github.com/luyadev/luya-module-admin/pull/751) Fixed parameter placeholders in translations (hu, nl, pl).
+ [#752](https://github.com/luyadev/luya-module-admin/pull/752) Updated links to new guide.
+ [#753](https://github.com/luyadev/luya-module-admin/pull/753) Enhanced error handling for scenarios where the proxy command attempts to synchronize a non-existent file.

## 5.0.0 (30. November 2023)

Expand Down
40 changes: 22 additions & 18 deletions src/proxy/ClientTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,30 @@ protected function startImages()
$imageCount = 0;
// sync images
foreach ((new \luya\admin\image\Query())->all() as $image) {
/** @var Item $image */
if (!$image->fileExists) {
$curl = new Curl();
$curl->setOpt(CURLOPT_RETURNTRANSFER, true);
$curl->get($this->build->imageProviderUrl, [
'buildToken' => $this->build->buildToken,
'machine' => $this->build->machineIdentifier,
'imageId' => $image->id,
]);

if (!$curl->error) {
if ($this->storageUpload($image->systemFileName, $curl->response)) {
$imageCount++;
$this->build->command->outputInfo('[+] Image ' . $image->source.' downloaded.');
try {
/** @var Item $image */
if (!$image->fileExists) {
$curl = new Curl();
$curl->setOpt(CURLOPT_RETURNTRANSFER, true);
$curl->get($this->build->imageProviderUrl, [
'buildToken' => $this->build->buildToken,
'machine' => $this->build->machineIdentifier,
'imageId' => $image->id,
]);

if (!$curl->error) {
if ($this->storageUpload($image->systemFileName, $curl->response)) {
$imageCount++;
$this->build->command->outputInfo('[+] Image ' . $image->source.' downloaded.');
}
}
}

$curl->close();
unset($curl);
gc_collect_cycles();
$curl->close();
unset($curl);
gc_collect_cycles();
}
} catch (Exception $e) {
$this->build->command->outputError('[!] Unable to download image due to error: ' . $e->getMessage());
}
}

Expand Down

0 comments on commit cb1f959

Please sign in to comment.