From 13ac425c8c9ad758baae347dcee91fab6485d2e7 Mon Sep 17 00:00:00 2001 From: rendygaafk Date: Sat, 17 May 2025 01:48:03 +0700 Subject: [PATCH] delet sync schedule auto --- app/Http/Controllers/belController.php | 40 ++++---------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/app/Http/Controllers/belController.php b/app/Http/Controllers/belController.php index 9e83cc8..8ed9a31 100644 --- a/app/Http/Controllers/belController.php +++ b/app/Http/Controllers/belController.php @@ -238,7 +238,7 @@ public function store(Request $request) try { $schedule = JadwalBel::create($validated); - $this->syncSchedules(); + $this->syncSchedule(); $this->logActivity('Jadwal dibuat', $schedule); return redirect() @@ -268,7 +268,7 @@ public function update(Request $request, $id) try { $schedule->update($validated); - $this->syncSchedules(); + $this->syncSchedule(); $this->logActivity('Jadwal diperbarui', $schedule); return redirect() @@ -288,7 +288,7 @@ public function destroy($id) try { $schedule = JadwalBel::findOrFail($id); $schedule->delete(); - $this->syncSchedules(); + $this->syncSchedule(); $this->logActivity('Jadwal dihapus', $schedule); return redirect() @@ -304,7 +304,7 @@ public function deleteAll() { try { JadwalBel::truncate(); - $this->syncSchedules(); + $this->syncSchedule(); return redirect() ->route('bel.index') @@ -339,7 +339,7 @@ public function activateAll() { try { JadwalBel::query()->update(['is_active' => true]); - $this->syncSchedules(); + $this->syncSchedule(); return response()->json([ 'success' => true, @@ -358,7 +358,7 @@ public function deactivateAll() { try { JadwalBel::query()->update(['is_active' => false]); - $this->syncSchedules(); + $this->syncSchedule(); return response()->json([ 'success' => true, @@ -502,35 +502,7 @@ public function syncSchedule() ]); } - protected function syncSchedules(): void - { - try { - $schedules = JadwalBel::active() - ->get() - ->map(fn($item) => [ - 'hari' => $item->hari, - 'waktu' => Carbon::parse($item->waktu)->format('H:i:s'), - 'file_number' => $item->file_number, - 'volume' => $item->volume ?? 15, // Add this - 'repeat' => $item->repeat ?? 1, // Add this - 'is_active' => $item->is_active // Add this - ]); - $this->mqttService->publish( - $this->mqttConfig['topics']['commands']['sync'], - json_encode([ - 'action' => 'sync', - 'timestamp' => Carbon::now()->toDateTimeString(), - 'schedules' => $schedules - ]), - 1 - ); - - Log::info("Auto sync: " . count($schedules) . " jadwal"); - } catch (\Exception $e) { - Log::error('Gagal auto sync: ' . $e->getMessage()); - } - } public function getNextSchedule() {