33 lines
805 B
PHP
33 lines
805 B
PHP
|
|
<?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;
|
||
|
|
}
|
||
|
|
}
|