Add initial Todo items and CalDAV sync
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Services\CaldavService;
|
||||
use App\Models\Todo;
|
||||
use App\Models\TodoType;
|
||||
use Sabre\VObject\Component\VCalendar;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CaldavSyncCommand extends Command
|
||||
{
|
||||
protected $signature = 'caldav:sync {--calendar= : optional calendar path}';
|
||||
protected $description = 'Sync CalDAV VTODOs into local todos table';
|
||||
|
||||
public function handle(CaldavService $service)
|
||||
{
|
||||
$this->info('Starting CalDAV sync...');
|
||||
|
||||
$todos = $service->getTodos();
|
||||
|
||||
$count = 0;
|
||||
foreach ($todos as $todo) {
|
||||
Todo::upsert($todo->attributesToArray(), 'id');
|
||||
$count++;
|
||||
}
|
||||
|
||||
$this->info("Synced " . count($todos) . " todos.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Register the Artisan commands for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
\App\Console\Commands\CaldavSyncCommand::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
// Beispiel: CalDAV Sync jede Stunde
|
||||
$schedule->command('caldav:sync')->hourly();
|
||||
|
||||
// Alternativen:
|
||||
// $schedule->command('caldav:sync')->daily();
|
||||
// $schedule->command('caldav:sync --calendar=/calendars/me/default/')->dailyAt('02:00');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*/
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__ . '/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user