feat: add intervals
This commit is contained in:
@@ -30,25 +30,53 @@ public function handle(): int
|
||||
|
||||
$this->info("Current time: {$now}");
|
||||
$this->info("Current time string: {$currentTime}");
|
||||
|
||||
$reminders = Reminder::with(['user', 'packageName'])
|
||||
->where(function ($query) use ($now, $currentTime) {
|
||||
// For PostgreSQL: Cast datetime to time for comparison
|
||||
|
||||
// time reached today
|
||||
$query->whereRaw('time::time <= ?', [$currentTime])
|
||||
|
||||
->where(function ($sub) use ($now) {
|
||||
// Non-repeatable: send once
|
||||
|
||||
// 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());
|
||||
|
||||
// repeatable with interval
|
||||
->orWhere(function ($repeat) use ($now) {
|
||||
$repeat->where('repeatable', true)
|
||||
->where(function ($interval) use ($now) {
|
||||
$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
|
||||
$this->info("Found {$reminders->count()} reminders");
|
||||
foreach ($reminders as $reminder) {
|
||||
@@ -91,9 +119,7 @@ public function handle(): int
|
||||
);
|
||||
}
|
||||
|
||||
$scheduledTime = Carbon::parse($reminder->time);
|
||||
$scheduledTime->setDate($now->year, $now->month, $now->day);
|
||||
$reminder->last_repeat = $scheduledTime;
|
||||
$reminder->last_repeat = $now;
|
||||
$reminder->save();
|
||||
$this->info("Queued push notification for reminder {$reminder->id}.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user