Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
Limit the events sitemap to upcoming and recently ended events (#1446)
Dave Earley2d52b3042f69
diff --git a/.gitignore b/.gitignoreindex 1299f2b5a..791177d87 100644--- a/.gitignore+++ b/.gitignore@@ -34,3 +34,4 @@ test_results//release-notes.md.amp/portals/*+.cloudflare/diff --git a/backend/app/Repository/Eloquent/EventRepository.php b/backend/app/Repository/Eloquent/EventRepository.phpindex d2ac8882c..e18c6b80d 100644--- a/backend/app/Repository/Eloquent/EventRepository.php+++ b/backend/app/Repository/Eloquent/EventRepository.php@@ -11,6 +11,7 @@ use HiEvents\DomainObjects\EventStatisticDomainObject;use HiEvents\DomainObjects\Generated\EventDomainObjectAbstract;use HiEvents\DomainObjects\Generated\EventSettingDomainObjectAbstract;use HiEvents\DomainObjects\OrganizerDomainObject;+use HiEvents\DomainObjects\Status\EventOccurrenceStatus;use HiEvents\DomainObjects\Status\EventStatus;use HiEvents\DomainObjects\Status\OrderStatus;use HiEvents\Http\DTO\QueryParamsDTO;@@ -27,6 +28,8 @@ use Illuminate\Support\Facades\DB;*/class EventRepository extends BaseRepository implements EventRepositoryInterface{+ private const SITEMAP_ENDED_EVENT_RETENTION_DAYS = 120;+protected function getModel(): string{return Event::class;@@ -204,16 +207,12 @@ class EventRepository extends BaseRepository implements EventRepositoryInterfacepublic function getSitemapEvents(int $page, int $perPage): LengthAwarePaginator{- return $this->handleResults($this->model+ return $this->handleResults($this->sitemapEventsQuery()->select(['events.'.EventDomainObjectAbstract::ID,'events.'.EventDomainObjectAbstract::TITLE,'events.'.EventDomainObjectAbstract::UPDATED_AT,])- ->join('event_settings', 'events.id', '=', 'event_settings.event_id')- ->where('events.'.EventDomainObjectAbstract::STATUS, EventStatus::LIVE->name)- ->where('event_settings.'.EventSettingDomainObjectAbstract::ALLOW_SEARCH_ENGINE_INDEXING, true)- ->whereNull('events.'.EventDomainObjectAbstract::DELETED_AT)->orderBy('events.'.EventDomainObjectAbstract::ID)->paginate($perPage, ['*'], 'page', $page));}@@ -229,6 +228,11 @@ class EventRepository extends BaseRepository implements EventRepositoryInterface}public function getSitemapEventCount(): int+ {+ return $this->sitemapEventsQuery()->count();+ }++ private function sitemapEventsQuery(): Builder{return $this->model->newQuery()@@ -236,7 +240,17 @@ class EventRepository extends BaseRepository implements EventRepositoryInterface->where('events.'.EventDomainObjectAbstract::STATUS, EventStatus::LIVE->name)->where('event_settings.'.EventSettingDomainObjectAbstract::ALLOW_SEARCH_ENGINE_INDEXING, true)->whereNull('events.'.EventDomainObjectAbstract::DELETED_AT)- ->count();+ ->whereExists(function ($query) {+ $query->select(DB::raw(1))+ ->from('event_occurrences')+ ->whereColumn('event_occurrences.event_id', 'events.id')+ ->whereNull('event_occurrences.deleted_at')+ ->where('event_occurrences.status', '!=', EventOccurrenceStatus::CANCELLED->name)+ ->whereRaw(+ 'COALESCE(event_occurrences.end_date, event_occurrences.start_date) >= ?',+ [now()->subDays(self::SITEMAP_ENDED_EVENT_RETENTION_DAYS)]+ );+ });}public function getUpcomingEventsWithCompletedOrders(int $accountId): Collectiondiff --git a/backend/app/Services/Domain/Sitemap/SitemapGeneratorService.php b/backend/app/Services/Domain/Sitemap/SitemapGeneratorService.phpindex 38f187fda..5feafccba 100644--- a/backend/app/Services/Domain/Sitemap/SitemapGeneratorService.php+++ b/backend/app/Services/Domain/Sitemap/SitemapGeneratorService.php@@ -21,16 +21,6 @@ class SitemapGeneratorServiceprivate const INDENT_STRING = ' ';- private const CHANGEFREQ_DAILY = 'daily';-- private const CHANGEFREQ_WEEKLY = 'weekly';-- private const PRIORITY_HIGH = '0.8';-- private const PRIORITY_MEDIUM = '0.6';-- private const PRIORITY_LOW = '0.5';-private const DEFAULT_EVENT_SLUG = 'event';private const DEFAULT_ORGANIZER_SLUG = 'organizer';@@ -88,10 +78,8 @@ class SitemapGeneratorService$writer->startElement('urlset');$writer->writeAttribute('xmlns', self::SITEMAP_NAMESPACE);- $now = now();-foreach ($events as $event) {- $this->writeEventUrl($writer, $event, $baseUrl, $now);+ $this->writeEventUrl($writer, $event, $baseUrl);}$writer->endElement();@@ -110,27 +98,12 @@ class SitemapGeneratorServicereturn $writer;}- private function writeEventUrl(XMLWriter $writer, EventDomainObject $event, string $baseUrl, Carbon $now): void+ private function writeEventUrl(XMLWriter $writer, EventDomainObject $event, string $baseUrl): void{$slug = Str::slug($event->getTitle()) ?: self::DEFAULT_EVENT_SLUG;$eventUrl = $baseUrl.sprintf(self::EVENT_URL_PATTERN, $event->getId(), $slug);- $isUpcoming = $this->isEventUpcoming($event, $now);- $lastMod = Carbon::parse($event->getUpdatedAt())->toAtomString();-- $writer->startElement('url');- $writer->writeElement('loc', $eventUrl);- $writer->writeElement('lastmod', $lastMod);- $writer->writeElement('changefreq', $isUpcoming ? self::CHANGEFREQ_DAILY : self::CHANGEFREQ_WEEKLY);- $writer->writeElement('priority', $isUpcoming ? self::PRIORITY_HIGH : self::PRIORITY_LOW);- $writer->endElement();- }-- private function isEventUpcoming(EventDomainObject $event, Carbon $now): bool- {- $startDate = $event->getStartDate();-- return $startDate !== null && Carbon::parse($startDate)->gte($now);+ $this->writeUrlEntry($writer, $eventUrl, $event->getUpdatedAt());}/**@@ -158,13 +131,15 @@ class SitemapGeneratorService{$slug = Str::slug($organizer->getName()) ?: self::DEFAULT_ORGANIZER_SLUG;$organizerUrl = $baseUrl.sprintf(self::ORGANIZER_URL_PATTERN, $organizer->getId(), $slug);- $lastMod = Carbon::parse($organizer->getUpdatedAt())->toAtomString();+ $this->writeUrlEntry($writer, $organizerUrl, $organizer->getUpdatedAt());+ }++ private function writeUrlEntry(XMLWriter $writer, string $loc, string $updatedAt): void+ {$writer->startElement('url');- $writer->writeElement('loc', $organizerUrl);- $writer->writeElement('lastmod', $lastMod);- $writer->writeElement('changefreq', self::CHANGEFREQ_WEEKLY);- $writer->writeElement('priority', self::PRIORITY_MEDIUM);+ $writer->writeElement('loc', $loc);+ $writer->writeElement('lastmod', Carbon::parse($updatedAt)->toAtomString());$writer->endElement();}}diff --git a/backend/tests/Feature/Repository/Eloquent/EventRepositoryTest.php b/backend/tests/Feature/Repository/Eloquent/EventRepositoryTest.phpindex ded1263ef..b6bbcf138 100644--- a/backend/tests/Feature/Repository/Eloquent/EventRepositoryTest.php+++ b/backend/tests/Feature/Repository/Eloquent/EventRepositoryTest.php@@ -194,6 +194,70 @@ class EventRepositoryTest extends TestCase$this->assertLessThan(array_search($olderId, $ids, true), array_search($newerId, $ids, true));}+ public function test_sitemap_includes_live_indexable_events_with_upcoming_or_recently_ended_occurrences(): void+ {+ $countBefore = $this->app->make(EventRepository::class)->getSitemapEventCount();++ $upcomingId = $this->createSitemapEvent();+ $this->createOccurrence($upcomingId, now()->addDay(), now()->addDay()->addHours(2));++ $recentlyEndedId = $this->createSitemapEvent();+ $this->createOccurrence($recentlyEndedId, now()->subDays(100), null);++ $longEndedId = $this->createSitemapEvent();+ $this->createOccurrence($longEndedId, now()->subDays(130), now()->subDays(130)->addHours(2));++ $cancelledId = $this->createSitemapEvent();+ $this->createOccurrence($cancelledId, now()->addDay(), now()->addDay()->addHours(2), status: 'CANCELLED');++ $withoutOccurrencesId = $this->createSitemapEvent();++ $ids = $this->sitemapEventIds();++ $this->assertContains($upcomingId, $ids);+ $this->assertContains($recentlyEndedId, $ids);+ $this->assertNotContains($longEndedId, $ids);+ $this->assertNotContains($cancelledId, $ids);+ $this->assertNotContains($withoutOccurrencesId, $ids);+ $this->assertSame($countBefore + 2, $this->app->make(EventRepository::class)->getSitemapEventCount());+ }++ public function test_sitemap_excludes_unpublished_and_non_indexable_events(): void+ {+ $draftId = $this->createSitemapEvent(status: 'DRAFT');+ $this->createOccurrence($draftId, now()->addDay(), now()->addDay()->addHours(2));++ $noIndexId = $this->createSitemapEvent(allowIndexing: false);+ $this->createOccurrence($noIndexId, now()->addDay(), now()->addDay()->addHours(2));++ $ids = $this->sitemapEventIds();++ $this->assertNotContains($draftId, $ids);+ $this->assertNotContains($noIndexId, $ids);+ }++ private function sitemapEventIds(): array+ {+ return collect($this->app->make(EventRepository::class)->getSitemapEvents(1, 10000)->items())+ ->map(fn (EventDomainObject $event) => $event->getId())+ ->all();+ }++ private function createSitemapEvent(string $status = 'LIVE', bool $allowIndexing = true): int+ {+ $eventId = $this->createEvent('Sitemap event '.uniqid(), status: $status);+ $now = now()->toDateTimeString();++ DB::table('event_settings')->insert([+ 'event_id' => $eventId,+ 'allow_search_engine_indexing' => $allowIndexing,+ 'created_at' => $now,+ 'updated_at' => $now,+ ]);++ return $eventId;+ }+private function findEventIds(string $eventsStatus, string $sortBy = 'created_at', string $sortDirection = 'desc'): array{$params = QueryParamsDTO::fromArray([@@ -234,7 +298,7 @@ class EventRepositoryTest extends TestCase]);}- private function createOccurrence(int $eventId, $startDate, $endDate): void+ private function createOccurrence(int $eventId, $startDate, $endDate, string $status = 'ACTIVE'): void{$now = now()->toDateTimeString();@@ -243,7 +307,7 @@ class EventRepositoryTest extends TestCase'event_id' => $eventId,'start_date' => $startDate->toDateTimeString(),'end_date' => $endDate?->toDateTimeString(),- 'status' => 'ACTIVE',+ 'status' => $status,'used_capacity' => 0,'is_overridden' => false,'created_at' => $now,diff --git a/backend/tests/Unit/Services/Domain/Sitemap/SitemapGeneratorServiceTest.php b/backend/tests/Unit/Services/Domain/Sitemap/SitemapGeneratorServiceTest.phpindex 4c2ad15d7..638c91985 100644--- a/backend/tests/Unit/Services/Domain/Sitemap/SitemapGeneratorServiceTest.php+++ b/backend/tests/Unit/Services/Domain/Sitemap/SitemapGeneratorServiceTest.php@@ -4,7 +4,6 @@ declare(strict_types=1);namespace Tests\Unit\Services\Domain\Sitemap;-use Carbon\Carbon;use HiEvents\DomainObjects\EventDomainObject;use HiEvents\DomainObjects\OrganizerDomainObject;use HiEvents\Services\Domain\Sitemap\SitemapGeneratorService;@@ -63,14 +62,11 @@ class SitemapGeneratorServiceTest extends TestCase$this->assertTrue($result, 'Generated XML should be valid');}- public function test_generate_events_sitemap_with_upcoming_event(): void+ public function test_generate_events_sitemap_with_event(): void{- Carbon::setTestNow('2025-01-15 10:00:00');-$event = $this->createMockEvent(id: 123,title: 'My Amazing Event',- startDate: '2025-02-01 18:00:00',updatedAt: '2025-01-10 12:00:00');@@ -82,33 +78,8 @@ class SitemapGeneratorServiceTest extends TestCase$this->assertStringContainsString('<?xml version="1.0" encoding="UTF-8"?>', $xml);$this->assertStringContainsString('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">', $xml);$this->assertStringContainsString('<loc>https://example.com/event/123/my-amazing-event</loc>', $xml);- $this->assertStringContainsString('<changefreq>daily</changefreq>', $xml);- $this->assertStringContainsString('<priority>0.8</priority>', $xml);-- Carbon::setTestNow();- }-- public function test_generate_events_sitemap_with_past_event(): void- {- Carbon::setTestNow('2025-01-15 10:00:00');-- $event = $this->createMockEvent(- id: 456,- title: 'Past Concert',- startDate: '2024-12-01 18:00:00',- updatedAt: '2024-11-15 12:00:00'- );-- $events = new Collection([$event]);- $baseUrl = 'https://example.com';-- $xml = $this->service->generateEventsSitemap($events, $baseUrl);-- $this->assertStringContainsString('<loc>https://example.com/event/456/past-concert</loc>', $xml);- $this->assertStringContainsString('<changefreq>weekly</changefreq>', $xml);- $this->assertStringContainsString('<priority>0.5</priority>', $xml);-- Carbon::setTestNow();+ $this->assertStringNotContainsString('<changefreq>', $xml);+ $this->assertStringNotContainsString('<priority>', $xml);}public function test_generate_events_sitemap_with_special_characters_in_title(): void@@ -116,7 +87,6 @@ class SitemapGeneratorServiceTest extends TestCase$event = $this->createMockEvent(id: 789,title: 'Event with Special <Characters> & "Quotes"',- startDate: '2025-02-01 18:00:00',updatedAt: '2025-01-10 12:00:00');@@ -135,7 +105,6 @@ class SitemapGeneratorServiceTest extends TestCase$event = $this->createMockEvent(id: 101,title: '日本語タイトル',- startDate: '2025-02-01 18:00:00',updatedAt: '2025-01-10 12:00:00');@@ -148,34 +117,11 @@ class SitemapGeneratorServiceTest extends TestCase$this->assertTrue($dom->loadXML($xml));}- public function test_generate_events_sitemap_with_null_start_date(): void- {- Carbon::setTestNow('2025-01-15 10:00:00');-- $event = $this->createMockEvent(- id: 202,- title: 'TBD Event',- startDate: null,- updatedAt: '2025-01-10 12:00:00'- );-- $events = new Collection([$event]);- $xml = $this->service->generateEventsSitemap($events, 'https://example.com');-- $this->assertStringContainsString('<changefreq>weekly</changefreq>', $xml);- $this->assertStringContainsString('<priority>0.5</priority>', $xml);-- Carbon::setTestNow();- }-public function test_generate_events_sitemap_includes_last_mod_from_updated_at(): void{- Carbon::setTestNow(Carbon::parse('2025-01-15 10:00:00', 'UTC'));-$event = $this->createMockEvent(id: 303,title: 'New Event',- startDate: '2025-02-01 18:00:00',updatedAt: '2025-01-12 15:30:00');@@ -187,8 +133,6 @@ class SitemapGeneratorServiceTest extends TestCase$dom = new \DOMDocument;$this->assertTrue($dom->loadXML($xml));-- Carbon::setTestNow();}public function test_generate_events_sitemap_with_empty_collection(): void@@ -206,12 +150,10 @@ class SitemapGeneratorServiceTest extends TestCasepublic function test_generate_events_sitemap_with_multiple_events(): void{- Carbon::setTestNow('2025-01-15 10:00:00');-$events = new Collection([- $this->createMockEvent(1, 'Event One', '2025-02-01 18:00:00', '2025-01-10 12:00:00'),- $this->createMockEvent(2, 'Event Two', '2025-03-01 18:00:00', '2025-01-11 12:00:00'),- $this->createMockEvent(3, 'Event Three', '2024-12-01 18:00:00', '2024-11-15 12:00:00'),+ $this->createMockEvent(1, 'Event One', '2025-01-10 12:00:00'),+ $this->createMockEvent(2, 'Event Two', '2025-01-11 12:00:00'),+ $this->createMockEvent(3, 'Event Three', '2024-11-15 12:00:00'),]);$xml = $this->service->generateEventsSitemap($events, 'https://example.com');@@ -224,8 +166,6 @@ class SitemapGeneratorServiceTest extends TestCase$dom->loadXML($xml);$urls = $dom->getElementsByTagName('url');$this->assertEquals(3, $urls->length);-- Carbon::setTestNow();}public function test_generate_organizers_sitemap_with_organizer(): void@@ -244,8 +184,8 @@ class SitemapGeneratorServiceTest extends TestCase$this->assertStringContainsString('<?xml version="1.0" encoding="UTF-8"?>', $xml);$this->assertStringContainsString('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">', $xml);$this->assertStringContainsString('<loc>https://example.com/events/123/my-amazing-organizer</loc>', $xml);- $this->assertStringContainsString('<changefreq>weekly</changefreq>', $xml);- $this->assertStringContainsString('<priority>0.6</priority>', $xml);+ $this->assertStringNotContainsString('<changefreq>', $xml);+ $this->assertStringNotContainsString('<priority>', $xml);}public function test_generate_organizers_sitemap_with_special_characters_in_name(): void@@ -334,12 +274,11 @@ class SitemapGeneratorServiceTest extends TestCase$this->assertTrue($dom->loadXML($xml));}- private function createMockEvent(int $id, string $title, ?string $startDate, ?string $updatedAt): EventDomainObject+ private function createMockEvent(int $id, string $title, string $updatedAt): EventDomainObject{$event = m::mock(EventDomainObject::class);$event->shouldReceive('getId')->andReturn($id);$event->shouldReceive('getTitle')->andReturn($title);- $event->shouldReceive('getStartDate')->andReturn($startDate);$event->shouldReceive('getUpdatedAt')->andReturn($updatedAt);return $event;diff --git a/e2e/tests/management/recurring-occurrences.spec.ts b/e2e/tests/management/recurring-occurrences.spec.tsindex fea1ac340..ca1b00340 100644--- a/e2e/tests/management/recurring-occurrences.spec.ts+++ b/e2e/tests/management/recurring-occurrences.spec.ts@@ -1,6 +1,6 @@import { test, expect } from '../../fixtures';import { OccurrencePage } from '../../pages/occurrence.page';-import { createRecurringLiveEvent } from '../../api/factory';+import { createRecurringLiveEvent, tomorrowUtcDate } from '../../api/factory';import { uniqueName } from '../../utils/unique';const WEEKDAY_LABELS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];@@ -33,6 +33,41 @@ test.describe('recurring occurrences', () => {await expect(occurrences.occurrenceRows()).toHaveCount(4);});+ test('an organizer edits a schedule whose end date was saved through the API with a time', async ({ authedPage, api, account }) => {+ const event = await api.createEvent({+ title: uniqueName('E2E Recurring API until'),+ type: 'RECURRING',+ organizer_id: account.organizerId,+ start_date: new Date(Date.now() + 86_400_000).toISOString(),+ category: 'MUSIC',+ currency: 'USD',+ timezone: 'UTC',+ });+ const start = tomorrowUtcDate();+ const until = new Date(`${start}T00:00:00Z`);+ until.setUTCDate(until.getUTCDate() + 27);+ const untilDate = until.toISOString().slice(0, 10);+ await api.generateOccurrences(event.id, {+ frequency: 'weekly',+ range: { type: 'until', start: `${start}T00:00:00`, until: `${untilDate}T23:59:00` },+ days_of_week: ['monday', 'thursday'],+ times_of_day: ['07:00'],+ duration_minutes: 60,+ });++ await authedPage.goto(`/manage/event/${event.id}/occurrences`);+ await authedPage.getByRole('button', { name: 'Add Dates' }).click();+ await authedPage.getByRole('menuitem', { name: /Edit Schedule/i }).click();++ const drawer = authedPage.getByRole('dialog');+ await expect(drawer.getByText('Edit schedule')).toBeVisible();+ await expect(drawer.getByText('Until a date')).toBeVisible();+ await expect(authedPage.getByText('Something went wrong')).toHaveCount(0);+ const [y, m, d] = untilDate.split('-').map(Number);+ const shown = new Date(Date.UTC(y, m - 1, d)).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', timeZone: 'UTC' });+ await expect(drawer.locator(`input[value="${shown}"], button:has-text("${shown}")`).first()).toBeVisible();+ });+test('an organizer cancels and reactivates an occurrence', async ({ authedPage, api, account }) => {const event = await createRecurringLiveEvent(api, account.organizerId, { count: 3 });diff --git a/frontend/src/components/routes/event/OccurrencesTab/RecurrenceScheduleDrawer/index.tsx b/frontend/src/components/routes/event/OccurrencesTab/RecurrenceScheduleDrawer/index.tsxindex e1e8449fc..b1852bd66 100644--- a/frontend/src/components/routes/event/OccurrencesTab/RecurrenceScheduleDrawer/index.tsx+++ b/frontend/src/components/routes/event/OccurrencesTab/RecurrenceScheduleDrawer/index.tsx@@ -581,7 +581,7 @@ export const RecurrenceScheduleDrawer = ({onClose, onGenerationStarted}: Recurretime_slots: parseTimeSlotsFromRule(rule),range_start: startFromRule ? startFromRule.slice(0, 10) : fallbackStart,range_type: rule.range?.type || 'until',- range_until: rule.range?.until || '',+ range_until: rule.range?.until ? rule.range.until.slice(0, 10) : '',range_count: rule.range?.count || 10,default_capacity: rule.default_capacity ?? undefined,monthly_pattern: rule.monthly_pattern || 'by_day_of_month',