delet sync schedule auto
This commit is contained in:
parent
4448c83266
commit
13ac425c8c
|
@ -238,7 +238,7 @@ public function store(Request $request)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$schedule = JadwalBel::create($validated);
|
$schedule = JadwalBel::create($validated);
|
||||||
$this->syncSchedules();
|
$this->syncSchedule();
|
||||||
$this->logActivity('Jadwal dibuat', $schedule);
|
$this->logActivity('Jadwal dibuat', $schedule);
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
|
@ -268,7 +268,7 @@ public function update(Request $request, $id)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$schedule->update($validated);
|
$schedule->update($validated);
|
||||||
$this->syncSchedules();
|
$this->syncSchedule();
|
||||||
$this->logActivity('Jadwal diperbarui', $schedule);
|
$this->logActivity('Jadwal diperbarui', $schedule);
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
|
@ -288,7 +288,7 @@ public function destroy($id)
|
||||||
try {
|
try {
|
||||||
$schedule = JadwalBel::findOrFail($id);
|
$schedule = JadwalBel::findOrFail($id);
|
||||||
$schedule->delete();
|
$schedule->delete();
|
||||||
$this->syncSchedules();
|
$this->syncSchedule();
|
||||||
$this->logActivity('Jadwal dihapus', $schedule);
|
$this->logActivity('Jadwal dihapus', $schedule);
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
|
@ -304,7 +304,7 @@ public function deleteAll()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
JadwalBel::truncate();
|
JadwalBel::truncate();
|
||||||
$this->syncSchedules();
|
$this->syncSchedule();
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('bel.index')
|
->route('bel.index')
|
||||||
|
@ -339,7 +339,7 @@ public function activateAll()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
JadwalBel::query()->update(['is_active' => true]);
|
JadwalBel::query()->update(['is_active' => true]);
|
||||||
$this->syncSchedules();
|
$this->syncSchedule();
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
|
@ -358,7 +358,7 @@ public function deactivateAll()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
JadwalBel::query()->update(['is_active' => false]);
|
JadwalBel::query()->update(['is_active' => false]);
|
||||||
$this->syncSchedules();
|
$this->syncSchedule();
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => true,
|
'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()
|
public function getNextSchedule()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue