diff --git a/app/Services/SyncService.php b/app/Services/SyncService.php index e1ce46b..afc0056 100644 --- a/app/Services/SyncService.php +++ b/app/Services/SyncService.php @@ -52,7 +52,7 @@ public function sync(): array $baseUrl = "http://{$this->peerIp}:{$this->peerPort}"; $peerCursor = (int) \App\Models\OsurgInitial::val('sync_peer_cursor', 0); - $ourLastSync = SyncLog::lastSyncId(); + $ourLastSync = (int) \App\Models\OsurgInitial::val('our_sync_cursor', 0); try { $pullResponse = Http::timeout(30) @@ -103,6 +103,11 @@ public function sync(): array } $report[] = count($ourChanges) . ' تغییر به سیستم مقابل ارسال شد.'; + if (! empty($ourChanges)) { + $maxOurId = max(array_column($ourChanges, 'id')); + $this->saveOurCursor($maxOurId); + } + if ($this->isFtpConfigured()) { $this->transferFilesViaFtp($ourChanges, 'c2s', $report); } 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 { \App\Models\OsurgInitial::updateOrCreate(