$email], [ 'firstname' => $firstname, 'lastname' => $lastname, 'timezone' => $timezone, 'password' => Hash::make($password), ] ); // fill the sabre-friendly columns $user->update([ 'uri' => 'principals/'.$user->email, 'displayname' => $firstname.' '.$lastname, ]); /** * * calendar and meta */ // sample caldav data $calId = DB::table('calendars')->insertGetId([ 'synctoken' => 1, 'components' => 'VEVENT', ]); $instanceId = DB::table('calendarinstances')->insertGetId([ 'calendarid' => $calId, 'principaluri' => $user->uri, // uses new column 'uri' => Str::uuid(), 'displayname' => 'Sample Calendar', 'description' => 'Seeded calendar', 'calendarorder' => 0, 'calendarcolor' => '#0038ff', 'timezone' => $timezone, ]); DB::table('calendar_meta')->updateOrInsert( ['calendar_id' => $calId], // @todo should this be calendar id or instance id? ['color' => '#0038ff'] ); /** * * create helper function for events to be added **/ $insertEvent = function (Carbon $start, string $summary) use ($calId) { // set base vars $uid = Str::uuid().'@kithkin.lan'; $end = $start->copy()->addHour(); // create UTC copies for the ICS fields $dtstamp = $start->copy()->utc()->format('Ymd\\THis\\Z'); $dtstart = $start->copy()->utc()->format('Ymd\\THis\\Z'); $dtend = $end->copy()->utc()->format('Ymd\\THis\\Z'); $ical = <<insertGetId([ 'calendarid' => $calId, 'uri' => Str::uuid().'.ics', 'lastmodified' => time(), 'etag' => md5($ical), 'size' => strlen($ical), 'componenttype' => 'VEVENT', 'uid' => $uid, 'calendardata' => $ical, ]); DB::table('event_meta')->updateOrInsert( ['event_id' => $eventId], [ 'title' => $summary, 'description' => 'Automatically seeded event', 'location' => 'Home Office', 'all_day' => false, 'category' => 'Demo', 'start_at' => $start->copy()->utc(), 'end_at' => $end->copy()->utc(), 'created_at' => now(), 'updated_at' => now(), ] ); }; /** * * create events */ $now = Carbon::now()->setSeconds(0); // 3 events today $insertEvent($now->copy(), 'Playground with James'); $insertEvent($now->copy()->addHours(2), 'Lunch with Daniel'); $insertEvent($now->copy()->addHours(4), 'Baseball practice'); // 1 event 3 days ago $past = $now->copy()->subDays(3)->setTime(10, 0); $insertEvent($past, 'Kids doctors appointments'); // 1 event 2 days ahead $future2 = $now->copy()->addDays(2)->setTime(14, 0); $insertEvent($future2, 'Teacher conference (Nuthatches)'); // 2 events 5 days ahead $future5a = $now->copy()->addDays(5)->setTime(9, 0); $future5b = $future5a->copy()->addHours(2); $insertEvent($future5a, 'Teacher conference (3rd grade)'); $insertEvent($future5b, 'Family game night'); /** * * address books * */ // create cards $bookId = DB::table('addressbooks')->insertGetId([ 'principaluri' => $user->uri, 'uri' => 'default', 'displayname' => 'Default Address Book', ]); $vcard = <<insert([ 'addressbook_id' => $bookId, 'color' => '#ff40ff', 'is_default' => true, 'settings' => null, 'created_at' => now(), 'updated_at' => now(), ]); $cardId = DB::table('cards')->insertGetId([ 'addressbookid' => $bookId, 'uri' => Str::uuid().'.vcf', 'lastmodified' => now()->timestamp, 'etag' => md5($vcard), 'size' => strlen($vcard), 'carddata' => $vcard, ]); DB::table('contact_meta')->insert([ 'card_id' => $cardId, 'avatar_url' => null, 'tags' => 'demo,seed', 'notes' => 'Seeded contact from DatabaseSeeder.', 'created_at' => now(), 'updated_at' => now(), ]); } }