Two month of work

This commit is contained in:
2026-02-17 10:35:03 +01:00
parent 0ffbeeedff
commit d9fd3d1ccb
158 changed files with 5637 additions and 1512 deletions
@@ -33,6 +33,31 @@ public function handle(CaldavService $service)
Todo::upsert($todo->attributesToArray(), 'id');
$count++;
}
// Collect hrefs/URLs returned by the CalDAV server so we can remove local
// todos that belong to this calendar but were deleted on the server.
$hrefs = array_values(array_filter(array_map(function ($t) {
return $t->url ?? null;
}, $todos)));
// Remove local todos that have a URL in this calendar but weren't returned
// by the server (i.e. they were deleted remotely). Scope deletion by
// calendar prefix to avoid touching other calendars.
$calendarId = $service->getCalendarId();
$username = config('caldav.username') ?? '';
$calendarPrefix = 'calendars/' . $username . '/' . $calendarId;
if ($calendarId && $username) {
Todo::whereNotNull('url')
->where('url', 'like', '%' . $calendarPrefix . "%")
->whereNotIn('url', $hrefs ?: [''])
->delete();
}
// Remove old todos
Todo::where('status', 'COMPLETED')
->where('last_modified', '<', now()->subDays(30)) // TODO: get from settings
->where('due_date', '<', now()->subDays(30))
->delete();
Log::info("Synced " . count($todos) . " todos.");
$this->info("Synced " . count($todos) . " todos.");