fix : SyncLog

This commit is contained in:
SajjadMahmoody 2026-04-19 01:41:54 +03:30
parent e807773403
commit 90114d4864
1 changed files with 15 additions and 1 deletions

View File

@ -52,7 +52,7 @@ public function sync(): array
$baseUrl = "http://{$this->peerIp}:{$this->peerPort}"; $baseUrl = "http://{$this->peerIp}:{$this->peerPort}";
$peerCursor = (int) \App\Models\OsurgInitial::val('sync_peer_cursor', 0); $peerCursor = (int) \App\Models\OsurgInitial::val('sync_peer_cursor', 0);
$ourLastSync = SyncLog::lastSyncId(); $ourLastSync = (int) \App\Models\OsurgInitial::val('our_sync_cursor', 0);
try { try {
$pullResponse = Http::timeout(30) $pullResponse = Http::timeout(30)
@ -103,6 +103,11 @@ public function sync(): array
} }
$report[] = count($ourChanges) . ' تغییر به سیستم مقابل ارسال شد.'; $report[] = count($ourChanges) . ' تغییر به سیستم مقابل ارسال شد.';
if (! empty($ourChanges)) {
$maxOurId = max(array_column($ourChanges, 'id'));
$this->saveOurCursor($maxOurId);
}
if ($this->isFtpConfigured()) { if ($this->isFtpConfigured()) {
$this->transferFilesViaFtp($ourChanges, 'c2s', $report); $this->transferFilesViaFtp($ourChanges, 'c2s', $report);
} else { } else {
@ -426,6 +431,15 @@ private function applyChange(array $change, string $prefix, array &$report): voi
} }
} }
private function saveOurCursor(int $cursor): void
{
\App\Models\OsurgInitial::updateOrCreate(
['init_parameter' => 'our_sync_cursor'],
['init_value' => $cursor],
);
cache()->forget('osurg_initial.our_sync_cursor');
}
private function savePeerCursor(int $cursor): void private function savePeerCursor(int $cursor): void
{ {
\App\Models\OsurgInitial::updateOrCreate( \App\Models\OsurgInitial::updateOrCreate(