feat: add intervals
This commit is contained in:
@@ -30,24 +30,52 @@ public function handle(): int
|
|||||||
|
|
||||||
$this->info("Current time: {$now}");
|
$this->info("Current time: {$now}");
|
||||||
$this->info("Current time string: {$currentTime}");
|
$this->info("Current time string: {$currentTime}");
|
||||||
|
|
||||||
$reminders = Reminder::with(['user', 'packageName'])
|
$reminders = Reminder::with(['user', 'packageName'])
|
||||||
->where(function ($query) use ($now, $currentTime) {
|
->where(function ($query) use ($now, $currentTime) {
|
||||||
// For PostgreSQL: Cast datetime to time for comparison
|
|
||||||
$query->whereRaw('time::time <= ?', [$currentTime])
|
// time reached today
|
||||||
->where(function ($sub) use ($now) {
|
$query->whereRaw('time::time <= ?', [$currentTime])
|
||||||
// Non-repeatable: send once
|
|
||||||
$sub->where('repeatable', false)
|
->where(function ($sub) use ($now) {
|
||||||
->whereNull('last_repeat')
|
|
||||||
// OR repeatable: not sent today
|
// non-repeatable (send once)
|
||||||
->orWhere('repeatable', true)
|
$sub->where('repeatable', false)
|
||||||
->where(function ($inner) use ($now) {
|
->whereNull('last_repeat')
|
||||||
$inner->whereNull('last_repeat')
|
|
||||||
->orWhereDate('last_repeat', '<', $now->toDateString());
|
// repeatable with interval
|
||||||
});
|
->orWhere(function ($repeat) use ($now) {
|
||||||
});
|
$repeat->where('repeatable', true)
|
||||||
})
|
->where(function ($interval) use ($now) {
|
||||||
->get();
|
$interval
|
||||||
|
->whereNull('last_repeat')
|
||||||
|
->orWhereRaw(
|
||||||
|
"last_repeat + (COALESCE(repeat_days, 1) || ' days')::interval <= ?",
|
||||||
|
[$now]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
->get();
|
||||||
|
|
||||||
|
|
||||||
|
// $reminders = Reminder::with(['user', 'packageName'])
|
||||||
|
// ->where(function ($query) use ($now, $currentTime) {
|
||||||
|
// // For PostgreSQL: Cast datetime to time for comparison
|
||||||
|
// $query->whereRaw('time::time <= ?', [$currentTime])
|
||||||
|
// ->where(function ($sub) use ($now) {
|
||||||
|
// // Non-repeatable: send once
|
||||||
|
// $sub->where('repeatable', false)
|
||||||
|
// ->whereNull('last_repeat')
|
||||||
|
// // OR repeatable: not sent today
|
||||||
|
// ->orWhere('repeatable', true)
|
||||||
|
// ->where(function ($inner) use ($now) {
|
||||||
|
// $inner->whereNull('last_repeat')
|
||||||
|
// ->orWhereDate('last_repeat', '<', $now->toDateString());
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// })
|
||||||
|
// ->get();
|
||||||
|
|
||||||
// Debug: Show what reminders were found
|
// Debug: Show what reminders were found
|
||||||
$this->info("Found {$reminders->count()} reminders");
|
$this->info("Found {$reminders->count()} reminders");
|
||||||
@@ -91,9 +119,7 @@ public function handle(): int
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$scheduledTime = Carbon::parse($reminder->time);
|
$reminder->last_repeat = $now;
|
||||||
$scheduledTime->setDate($now->year, $now->month, $now->day);
|
|
||||||
$reminder->last_repeat = $scheduledTime;
|
|
||||||
$reminder->save();
|
$reminder->save();
|
||||||
$this->info("Queued push notification for reminder {$reminder->id}.");
|
$this->info("Queued push notification for reminder {$reminder->id}.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user