Fix Events mail calendar sync when virtual sessions lack ids.
Deploy Ladill Events / deploy (push) Successful in 52s

Generate session ids before upserting and fall back to the main event date so August events reach Mail calendar.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-04 12:27:48 +00:00
co-authored by Cursor
parent d25682bc6c
commit a00f032b5b
3 changed files with 38 additions and 3 deletions
@@ -9,6 +9,7 @@ use App\Services\Integrations\MailCalendarClient;
use Carbon\CarbonInterface; use Carbon\CarbonInterface;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
class EventMailCalendarSyncService class EventMailCalendarSyncService
{ {
@@ -91,7 +92,9 @@ class EventMailCalendarSyncService
} }
} }
if ($format === 'hybrid' && filled($content['starts_at'] ?? null)) { if ($entries === [] && filled($content['starts_at'] ?? null)) {
$entries[] = $this->mainEventEntry($event, $content);
} elseif ($format === 'hybrid' && filled($content['starts_at'] ?? null)) {
$entries[] = $this->mainEventEntry($event, $content, ' (in person)'); $entries[] = $this->mainEventEntry($event, $content, ' (in person)');
} }
@@ -114,7 +117,7 @@ class EventMailCalendarSyncService
{ {
$sessionId = trim((string) ($session['id'] ?? '')); $sessionId = trim((string) ($session['id'] ?? ''));
if ($sessionId === '') { if ($sessionId === '') {
return null; $sessionId = 'vs-'.Str::lower(Str::random(12));
} }
$starts = $this->parseDate($session['scheduled_at'] ?? $content['starts_at'] ?? null); $starts = $this->parseDate($session['scheduled_at'] ?? $content['starts_at'] ?? null);
+6 -1
View File
@@ -4,6 +4,7 @@ namespace App\Services\Qr;
use App\Models\QrCode; use App\Models\QrCode;
use App\Support\Qr\QrDateFormatter; use App\Support\Qr\QrDateFormatter;
use Illuminate\Support\Str;
use App\Support\Qr\QrTypeCatalog; use App\Support\Qr\QrTypeCatalog;
use Illuminate\Http\UploadedFile; use Illuminate\Http\UploadedFile;
use RuntimeException; use RuntimeException;
@@ -336,6 +337,10 @@ class QrPayloadValidator
} }
$id = trim((string) ($session['id'] ?? '')); $id = trim((string) ($session['id'] ?? ''));
if ($id === '') {
$id = 'vs-'.Str::lower(Str::random(12));
}
$roomType = in_array($session['meet_room_type'] ?? '', ['town_hall', 'webinar'], true) $roomType = in_array($session['meet_room_type'] ?? '', ['town_hall', 'webinar'], true)
? (string) $session['meet_room_type'] ? (string) $session['meet_room_type']
: 'town_hall'; : 'town_hall';
@@ -349,7 +354,7 @@ class QrPayloadValidator
} }
$normalized[] = [ $normalized[] = [
'id' => $id !== '' ? mb_substr($id, 0, 64) : null, 'id' => mb_substr($id, 0, 64),
'title' => mb_substr($title, 0, 120), 'title' => mb_substr($title, 0, 120),
'meet_room_type' => $roomType, 'meet_room_type' => $roomType,
'scheduled_at' => QrDateFormatter::normalize((string) ($session['scheduled_at'] ?? '')), 'scheduled_at' => QrDateFormatter::normalize((string) ($session['scheduled_at'] ?? '')),
@@ -84,6 +84,33 @@ class EventMailCalendarSyncTest extends TestCase
)->count()); )->count());
} }
public function test_virtual_session_without_id_still_syncs_to_mail_calendar(): void
{
$owner = User::factory()->create(['public_id' => 'usr-cal-4', 'email' => 'host@example.com']);
$event = $this->makeEvent($owner, [
'format' => 'virtual',
'name' => 'NextGen Summit 2026',
'starts_at' => '2026-08-26',
'ends_at' => '2026-08-27',
'virtual_sessions' => [[
'id' => null,
'title' => 'NextGen Summit',
'scheduled_at' => '2026-08-26',
'duration_minutes' => 180,
]],
]);
app(EventMailCalendarSyncService::class)->sync($event, $owner);
Http::assertSent(function ($request) use ($event) {
return str_contains($request->url(), '/calendar/events')
&& str_starts_with((string) $request['external_ref'], 'events:'.$event->id.':session:vs-')
&& $request['title'] === 'NextGen Summit';
});
$this->assertNotEmpty(data_get($event->fresh()->payload, 'calendar_sync.items'));
}
public function test_uses_linked_mailbox_when_available(): void public function test_uses_linked_mailbox_when_available(): void
{ {
Http::fake([ Http::fake([