Skip to content

Commit 510a999

Browse files
committed
Remove unused action argument from progress callback
1 parent a37ce71 commit 510a999

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

app/Services/SftpService.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function syncServerDirectory(Server $server, string $localPath, string $r
135135
$serverConfig,
136136
$localPath,
137137
$remotePath,
138-
Cache::pull($chunkKey) ?? [],
138+
app(self::class)->pullChunkFromCache($chunkKey),
139139
$worker,
140140
$releaseId,
141141
);
@@ -195,7 +195,7 @@ public function syncDirectory(SFTP $sftp, string $localPath, string $remotePath,
195195
}
196196

197197
if ($onProgress) {
198-
$onProgress('upload', $relative);
198+
$onProgress($relative);
199199
}
200200
}
201201

@@ -244,7 +244,7 @@ protected function deleteRemovedFiles(SFTP $sftp, string $localPath, string $rem
244244

245245
if (! $disk->exists($localItem)) {
246246
if ($onProgress) {
247-
$onProgress('delete', $currentRelative);
247+
$onProgress($currentRelative);
248248
}
249249
$sftp->delete($remoteItem, true);
250250
} elseif ($type === 2) { // NET_SFTP_TYPE_DIRECTORY
@@ -284,6 +284,20 @@ protected function ensureLocalDir(string $dir): void
284284
}
285285
}
286286

287+
/**
288+
* @return array<int, string>
289+
*/
290+
public function pullChunkFromCache(string $key): array
291+
{
292+
$chunk = Cache::pull($key);
293+
294+
if (! is_array($chunk)) {
295+
return [];
296+
}
297+
298+
return array_values(array_filter($chunk, 'is_string'));
299+
}
300+
287301
private function normalizeLocalPath(string $path, string $diskRoot): string
288302
{
289303
$normalized = str_replace('\\', '/', $path);
@@ -388,7 +402,7 @@ protected function buildProgressLogger(?int $releaseId, int $worker, array $rela
388402
$logEveryFiles = max(1, $this->requireInt(config('services.sftp.progress_every_files', 100), 'SFTP progress file interval'));
389403
$logEverySeconds = max(0.0, $this->requireFloat(config('services.sftp.progress_every_seconds', 3), 'SFTP progress time interval'));
390404

391-
return static function (string $action, string $relativePath) use ($releaseId, $worker, $totalFiles, &$completedFiles, &$lastLoggedAt, $logEveryFiles, $logEverySeconds): void {
405+
return static function (string $relativePath) use ($releaseId, $worker, $totalFiles, &$completedFiles, &$lastLoggedAt, $logEveryFiles, $logEverySeconds): void {
392406
$completedFiles++;
393407
$now = microtime(true);
394408

tests/Unit/Services/SftpServiceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,9 @@ public function test_upload_relative_file_batch_logs_throttled_progress(): void
549549
->once()
550550
->with($sftp, 'sync', 'remote/path', [], Mockery::type('callable'), ['alpha.txt', 'beta.txt', 'gamma.txt'])
551551
->andReturnUsing(function ($sftp, string $localPath, string $remotePath, array $skipPatterns, callable $onProgress, array $relativeFiles): int {
552-
$onProgress('upload', 'alpha.txt');
553-
$onProgress('upload', 'beta.txt');
554-
$onProgress('upload', 'gamma.txt');
552+
$onProgress('alpha.txt');
553+
$onProgress('beta.txt');
554+
$onProgress('gamma.txt');
555555

556556
return 3;
557557
});

0 commit comments

Comments
 (0)