feat: add intervals

This commit is contained in:
2025-12-15 09:43:07 +03:30
parent a7b55b0b6d
commit ca946b2aae
+37 -11
View File
@@ -30,25 +30,53 @@ 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
// time reached today
$query->whereRaw('time::time <= ?', [$currentTime]) $query->whereRaw('time::time <= ?', [$currentTime])
->where(function ($sub) use ($now) { ->where(function ($sub) use ($now) {
// Non-repeatable: send once
// non-repeatable (send once)
$sub->where('repeatable', false) $sub->where('repeatable', false)
->whereNull('last_repeat') ->whereNull('last_repeat')
// OR repeatable: not sent today
->orWhere('repeatable', true) // repeatable with interval
->where(function ($inner) use ($now) { ->orWhere(function ($repeat) use ($now) {
$inner->whereNull('last_repeat') $repeat->where('repeatable', true)
->orWhereDate('last_repeat', '<', $now->toDateString()); ->where(function ($interval) use ($now) {
$interval
->whereNull('last_repeat')
->orWhereRaw(
"last_repeat + (COALESCE(repeat_days, 1) || ' days')::interval <= ?",
[$now]
);
});
}); });
}); });
}) })
->get(); ->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");
foreach ($reminders as $reminder) { foreach ($reminders as $reminder) {
@@ -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}.");
} }