diff --git a/client/src/components/Tours/TourGpxPreviewDialog.test.tsx b/client/src/components/Tours/TourGpxPreviewDialog.test.tsx
index eac73169c..4cb876dc8 100644
--- a/client/src/components/Tours/TourGpxPreviewDialog.test.tsx
+++ b/client/src/components/Tours/TourGpxPreviewDialog.test.tsx
@@ -1,4 +1,4 @@
-// FE-GPX-PREVIEW-001 to FE-GPX-PREVIEW-003
+// FE-GPX-PREVIEW-001 to FE-GPX-PREVIEW-004
// The GPX preview as ACT-01 uses it: preset to the tour's type, a city walk
// imported as one, and when a track was recorded shown where it carried times.
import { fireEvent, render, screen } from '@testing-library/react';
@@ -47,6 +47,13 @@ describe('TourGpxPreviewDialog (ACT-01)', () => {
expect(recorded[0]).toHaveTextContent('50 min');
});
+ it('FE-GPX-PREVIEW-004: a track taken over from before Tours reads as one, not as a duplicate (#2810)', () => {
+ render();
+ expect(screen.getByTestId('gpx-preview-track')).not.toHaveAttribute('data-duplicate');
+ expect(screen.getByText(/tours\.import\.previewAdopts|becomes a tour/)).toBeInTheDocument();
+ expect(screen.queryByText(/tours\.import\.previewDuplicate|Already in the trip/)).toBeNull();
+ });
+
it('FE-GPX-PREVIEW-002: imports as the preset type, a paddle tour with its boat and water', () => {
const current = gpxImport([track()]);
render(
diff --git a/client/src/components/Tours/TourGpxPreviewDialog.tsx b/client/src/components/Tours/TourGpxPreviewDialog.tsx
index f7021c131..a0b947f4a 100644
--- a/client/src/components/Tours/TourGpxPreviewDialog.tsx
+++ b/client/src/components/Tours/TourGpxPreviewDialog.tsx
@@ -79,6 +79,7 @@ function PreviewTrackRow({
{track.name || name}
{track.duplicate && {t('tours.import.previewDuplicate')}}
+ {track.adopts_track && {t('tours.import.previewAdopts')}}
{formatDistance(track.distance_km, unit)}
diff --git a/server/src/db/repositories/Places.repository.ts b/server/src/db/repositories/Places.repository.ts
index 2b9d8c2fb..394c0ea83 100644
--- a/server/src/db/repositories/Places.repository.ts
+++ b/server/src/db/repositories/Places.repository.ts
@@ -318,6 +318,21 @@ export class PlacesRepository extends TrekRepository
{
return !!row;
}
+ /**
+ * The trip's tracks that are not tours: places with `route_geometry` and no
+ * `tours` row, oldest first. A GPX file imported before Tours existed (4.x)
+ * left its tracks like this, and the tour import takes one over by name
+ * instead of refusing it as a duplicate (#2810).
+ */
+ async listTracksWithoutTour(trip_id: number | string): Promise<{ id: number; name: string; route_geometry: string }[]> {
+ return this.qb('p')
+ .leftJoin('p.tours', 't')
+ .select(['p.id', 'p.name', 'p.route_geometry'])
+ .where('p.trip_id = ? AND p.route_geometry IS NOT NULL AND t.place_id IS NULL', [trip_id])
+ .orderBy({ 'p.id': 'asc' })
+ .execute<{ id: number; name: string; route_geometry: string }[]>('all', false);
+ }
+
/** PL19/PL21 — `DELETE FROM places WHERE id = ?`, unscoped: every caller proved trip access first. */
async deleteById(id: number): Promise {
await this.nativeDelete({ id });
diff --git a/server/src/nest/places/places.service.ts b/server/src/nest/places/places.service.ts
index 49414aecb..808d2e487 100644
--- a/server/src/nest/places/places.service.ts
+++ b/server/src/nest/places/places.service.ts
@@ -3,7 +3,7 @@ import path from 'node:path';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@mikro-orm/nestjs';
import { resolveCountryCodeSync } from '../atlas/atlas-geo';
-import { TRACK_COLORS, placeMatchStrategies, type PlaceMatchCandidate } from '@trek/shared';
+import { TRACK_COLORS, normalizePlaceName, placeMatchStrategies, type PlaceMatchCandidate } from '@trek/shared';
import type { TrekWsPayload, TrekWsTripEventName } from '@trek/shared';
import { RealtimeService } from '../realtime/realtime.service';
import type { TripAccess } from '../../db/repositories/Trips.repository';
@@ -765,6 +765,28 @@ export class PlacesService {
});
}
+ /**
+ * The rows of a tour import that take over a track already in the trip,
+ * by row index: a place with a track and no tour yet, under the same name,
+ * one place per row. A GPX file imported before Tours existed (4.x) left
+ * its tracks as plain places, and the name alone made every tour import of
+ * the same file a duplicate with no tour to show for it (#2810).
+ */
+ async tracksToAdopt(tripId: string, rows: PreparedGpxPlace[]): Promise