| @@ -4,10 +4,15 @@ | ||
| 4 | 4 | |
| 5 | 5 | namespace Yatra\Services; |
| 6 | 6 | |
| 7 | 7 | use Yatra\Constants\ClassificationTypes; |
| 8 | +use Yatra\Database\Tables\BookingsTable; | |
| 9 | +use Yatra\Database\Tables\ClassificationsTable; | |
| 10 | +use Yatra\Database\Tables\DiscountsTable; | |
| 11 | +use Yatra\Database\Tables\TripItineraryDayEntryTable; | |
| 12 | +use Yatra\Database\Tables\TripItineraryDaysTable; | |
| 13 | +use Yatra\Repositories\ExportImportRepository; | |
| 8 | 14 | use Yatra\Utils\Logger; |
| 9 | -use Yatra\Repositories\ExportImportRepository; | |
| 10 | 15 | |
| 11 | 16 | /** |
| 12 | 17 | * Export/Import Service |
| 13 | 18 | * |
| @@ -23,29 +28,29 @@ | ||
| 23 | 28 | private const JOB_OPTION_PREFIX = 'yatra_job_'; |
| 24 | 29 | private const BATCH_SIZE = 500; |
| 25 | 30 | |
| 26 | 31 | /** |
| 27 | - * Unprefixed physical table names (Yatra 3.x uses yatra_new_* — not legacy yatra_trips, etc.). | |
| 32 | + * Unprefixed physical table names (Yatra 3.x uses yatra_* — not legacy yatra_trips, etc.). | |
| 28 | 33 | * |
| 29 | 34 | * @var array<string, string> |
| 30 | 35 | */ |
| 31 | 36 | private const TABLE_SUFFIX_MAP = [ |
| 32 | - 'trips' => 'yatra_new_trips', | |
| 33 | - 'bookings' => 'yatra_new_bookings', | |
| 34 | - 'customers' => 'yatra_new_customers', | |
| 35 | - 'reviews' => 'yatra_new_reviews', | |
| 36 | - 'payments' => 'yatra_new_booking_payments', | |
| 37 | - 'enquiries' => 'yatra_new_enquiries', | |
| 38 | - 'discounts' => 'yatra_new_discounts', | |
| 39 | - 'travelers' => 'yatra_new_booking_travellers', | |
| 40 | - 'traveler_meta' => 'yatra_new_booking_traveller_meta', | |
| 41 | - 'availability' => 'yatra_new_trip_availability_dates', | |
| 42 | - 'availability_rules' => 'yatra_new_trip_availability_rules', | |
| 43 | - 'departures' => 'yatra_new_trip_departures', | |
| 44 | - 'booking_departures' => 'yatra_new_booking_departures', | |
| 45 | - 'trip_classifications' => 'yatra_new_trip_classifications', | |
| 46 | - 'trip_content' => 'yatra_new_trip_content', | |
| 47 | - 'trip_revisions' => 'yatra_new_trip_revisions', | |
| 37 | + 'trips' => 'yatra_trips', | |
| 38 | + 'bookings' => 'yatra_bookings', | |
| 39 | + 'customers' => 'yatra_customers', | |
| 40 | + 'reviews' => 'yatra_reviews', | |
| 41 | + 'payments' => 'yatra_booking_payments', | |
| 42 | + 'enquiries' => 'yatra_enquiries', | |
| 43 | + 'discounts' => 'yatra_discounts', | |
| 44 | + 'travelers' => 'yatra_booking_travellers', | |
| 45 | + 'traveler_meta' => 'yatra_booking_traveller_meta', | |
| 46 | + 'availability' => 'yatra_trip_availability_dates', | |
| 47 | + 'availability_rules' => 'yatra_trip_availability_rules', | |
| 48 | + 'departures' => 'yatra_trip_departures', | |
| 49 | + 'booking_departures' => 'yatra_booking_departures', | |
| 50 | + 'trip_classifications' => 'yatra_trip_classifications', | |
| 51 | + 'trip_content' => 'yatra_trip_content', | |
| 52 | + 'trip_revisions' => 'yatra_trip_revisions', | |
| 48 | 53 | ]; |
| 49 | 54 | |
| 50 | 55 | /** |
| 51 | 56 | * Free core map + optional suffixes from Yatra Pro (or other add-ons) via |
| @@ -314,10 +319,10 @@ | ||
| 314 | 319 | continue; |
| 315 | 320 | } |
| 316 | 321 | |
| 317 | 322 | if ($dataType === 'itinerary') { |
| 318 | - $daysTable = $wpdb->prefix . 'yatra_new_trip_itinerary_days'; | |
| 319 | - $entriesTable = $wpdb->prefix . 'yatra_new_trip_itinerary_day_entry'; | |
| 323 | + $daysTable = TripItineraryDaysTable::getTableName(); | |
| 324 | + $entriesTable = TripItineraryDayEntryTable::getTableName(); | |
| 320 | 325 | $allDays = []; |
| 321 | 326 | $allEntries = []; |
| 322 | 327 | |
| 323 | 328 | if ($repository->tableExists($daysTable)) { |
| @@ -356,9 +361,9 @@ | ||
| 356 | 361 | } |
| 357 | 362 | |
| 358 | 363 | $classType = self::classificationTypeForDataType($dataType); |
| 359 | 364 | if ($classType !== null) { |
| 360 | - $tableName = $wpdb->prefix . 'yatra_new_classifications'; | |
| 365 | + $tableName = ClassificationsTable::getTableName(); | |
| 361 | 366 | if (!$repository->tableExists($tableName)) { |
| 362 | 367 | $exportData['data'][$dataType] = []; |
| 363 | 368 | continue; |
| 364 | 369 | } |
| @@ -602,10 +607,10 @@ | ||
| 602 | 607 | if (!isset($payload['days'], $payload['entries']) || !is_array($payload['days']) || !is_array($payload['entries'])) { |
| 603 | 608 | Logger::warning('Skipping itinerary: expected { days, entries } from Yatra 3 export; legacy flat arrays are not supported'); |
| 604 | 609 | continue; |
| 605 | 610 | } |
| 606 | - $daysTable = $wpdb->prefix . 'yatra_new_trip_itinerary_days'; | |
| 607 | - $entriesTable = $wpdb->prefix . 'yatra_new_trip_itinerary_day_entry'; | |
| 611 | + $daysTable = TripItineraryDaysTable::getTableName(); | |
| 612 | + $entriesTable = TripItineraryDayEntryTable::getTableName(); | |
| 608 | 613 | $dayTotal = count($payload['days']); |
| 609 | 614 | $entryTotal = count($payload['entries']); |
| 610 | 615 | $importStats['itinerary'] = [ |
| 611 | 616 | 'total' => $dayTotal + $entryTotal, |
| @@ -724,9 +729,9 @@ | ||
| 724 | 729 | |
| 725 | 730 | $mergedMap = self::getMergedTableMap(); |
| 726 | 731 | $classType = self::classificationTypeForDataType($dataType); |
| 727 | 732 | if ($classType !== null) { |
| 728 | - $tableName = $wpdb->prefix . 'yatra_new_classifications'; | |
| 733 | + $tableName = ClassificationsTable::getTableName(); | |
| 729 | 734 | } elseif (isset($mergedMap[$dataType])) { |
| 730 | 735 | $tableName = $wpdb->prefix . $mergedMap[$dataType]; |
| 731 | 736 | } else { |
| 732 | 737 | Logger::warning("Skipping unknown import data type: {$dataType}"); |
| @@ -1297,9 +1302,9 @@ | ||
| 1297 | 1302 | |
| 1298 | 1303 | private static function ensureUniqueDiscountCode(string $code): string |
| 1299 | 1304 | { |
| 1300 | 1305 | global $wpdb; |
| 1301 | - $table = $wpdb->prefix . 'yatra_new_discounts'; | |
| 1306 | + $table = DiscountsTable::getTableName(); | |
| 1302 | 1307 | $base = $code; |
| 1303 | 1308 | $candidate = $base; |
| 1304 | 1309 | for ($n = 0; $n < 5000; $n++) { |
| 1305 | 1310 | $exists = (int) $wpdb->get_var( |
| @@ -1319,9 +1324,9 @@ | ||
| 1319 | 1324 | |
| 1320 | 1325 | private static function ensureUniqueBookingReference(string $reference): string |
| 1321 | 1326 | { |
| 1322 | 1327 | global $wpdb; |
| 1323 | - $table = $wpdb->prefix . 'yatra_new_bookings'; | |
| 1328 | + $table = BookingsTable::getTableName(); | |
| 1324 | 1329 | $base = $reference; |
| 1325 | 1330 | $candidate = $base; |
| 1326 | 1331 | for ($n = 0; $n < 5000; $n++) { |
| 1327 | 1332 | $exists = (int) $wpdb->get_var( |
| @@ -1472,10 +1477,10 @@ | ||
| 1472 | 1477 | if ($dataType === 'settings') { |
| 1473 | 1478 | continue; |
| 1474 | 1479 | } |
| 1475 | 1480 | if ($dataType === 'itinerary') { |
| 1476 | - $daysTable = $wpdb->prefix . 'yatra_new_trip_itinerary_days'; | |
| 1477 | - $entriesTable = $wpdb->prefix . 'yatra_new_trip_itinerary_day_entry'; | |
| 1481 | + $daysTable = TripItineraryDaysTable::getTableName(); | |
| 1482 | + $entriesTable = TripItineraryDayEntryTable::getTableName(); | |
| 1478 | 1483 | if ($repository->tableExists($daysTable)) { |
| 1479 | 1484 | $total += $repository->getRecordCount($daysTable); |
| 1480 | 1485 | } |
| 1481 | 1486 | if ($repository->tableExists($entriesTable)) { |
| @@ -1484,9 +1489,9 @@ | ||
| 1484 | 1489 | continue; |
| 1485 | 1490 | } |
| 1486 | 1491 | $classType = self::classificationTypeForDataType($dataType); |
| 1487 | 1492 | if ($classType !== null) { |
| 1488 | - $tableName = $wpdb->prefix . 'yatra_new_classifications'; | |
| 1493 | + $tableName = ClassificationsTable::getTableName(); | |
| 1489 | 1494 | if ($repository->tableExists($tableName)) { |
| 1490 | 1495 | $total += $repository->getClassificationCount($tableName, $classType); |
| 1491 | 1496 | } |
| 1492 | 1497 | continue; |