| @@ -46,9 +46,9 @@ | ||
| 46 | 46 | $existingTripId = null; |
| 47 | 47 | |
| 48 | 48 | if ($this->isForceMigration()) { |
| 49 | 49 | // Force migration: Always insert new (create duplicates) |
| 50 | - $slug = $this->generateUniqueSlug($baseSlug, 'yatra_new_trips'); | |
| 50 | + $slug = $this->generateUniqueSlug($baseSlug, 'yatra_trips'); | |
| 51 | 51 | } else { |
| 52 | 52 | // Regular migration: Check if already exists |
| 53 | 53 | $existingTripId = $this->wpdb->get_var($this->wpdb->prepare( |
| 54 | 54 | "SELECT id FROM " . TripsTable::getTableName() . " WHERE slug = %s", |
| @@ -56,9 +56,9 @@ | ||
| 56 | 56 | )); |
| 57 | 57 | |
| 58 | 58 | if (!$existingTripId) { |
| 59 | 59 | // Generate unique slug for new insert |
| 60 | - $slug = $this->generateUniqueSlug($baseSlug, 'yatra_new_trips'); | |
| 60 | + $slug = $this->generateUniqueSlug($baseSlug, 'yatra_trips'); | |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // Raw SQL: get_post_thumbnail_id internally calls get_post_meta for _thumbnail_id |
| @@ -131,14 +131,16 @@ | ||
| 131 | 131 | $customFields['external_booking_button_text'] = sanitize_text_field((string) $extBtn); |
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | + $mainBodyHtml = $this->resolveLegacyTourMainBodyHtml($oldTrip, $meta); | |
| 136 | + | |
| 135 | 137 | $tripData = [ |
| 136 | 138 | 'title' => $oldTrip->post_title, |
| 137 | 139 | 'slug' => $slug, |
| 138 | - 'description' => $oldTrip->post_content, | |
| 140 | + 'description' => $mainBodyHtml, | |
| 139 | 141 | 'short_description' => $oldTrip->post_excerpt, |
| 140 | - 'trip_details' => $oldTrip->post_content, | |
| 142 | + 'trip_details' => $mainBodyHtml, | |
| 141 | 143 | 'trip_type' => $tripType, |
| 142 | 144 | 'duration_days' => $durationDays, |
| 143 | 145 | 'duration_nights' => $durationNights, |
| 144 | 146 | 'min_travelers' => $minTravelers, |
| @@ -1123,6 +1125,65 @@ | ||
| 1123 | 1125 | } |
| 1124 | 1126 | |
| 1125 | 1127 | if ($created > 0) { |
| 1126 | 1128 | } |
| 1129 | + } | |
| 1130 | + | |
| 1131 | + /** | |
| 1132 | + * Resolve main trip HTML for description / trip_details. | |
| 1133 | + * | |
| 1134 | + * Legacy Yatra 2.x rendered the “Overview” tab from the `overview_description` post meta field | |
| 1135 | + * (see `Yatra_Frontend_Tour_Tabs::overview()` in Yatra 2.3.x), | |
| 1136 | + * while the block editor / post_content was often left empty. Migration previously copied only | |
| 1137 | + * post_content, which dropped that body. We prefer meta when present and merge with post_content | |
| 1138 | + * when both differ so unique content in either place is kept. | |
| 1139 | + */ | |
| 1140 | + private function resolveLegacyTourMainBodyHtml(object $oldTrip, array $meta): string | |
| 1141 | + { | |
| 1142 | + $overviewKeys = [ | |
| 1143 | + 'overview_description', | |
| 1144 | + 'yatra_tour_meta_overview_description', | |
| 1145 | + 'yatra_overview_description', | |
| 1146 | + ]; | |
| 1147 | + | |
| 1148 | + $fromMeta = ''; | |
| 1149 | + foreach ($overviewKeys as $key) { | |
| 1150 | + $fromMeta = $this->legacyMetaTrimmedString($meta, $key); | |
| 1151 | + if ($fromMeta !== '') { | |
| 1152 | + break; | |
| 1153 | + } | |
| 1154 | + } | |
| 1155 | + | |
| 1156 | + $fromPost = isset($oldTrip->post_content) ? trim((string) $oldTrip->post_content) : ''; | |
| 1157 | + | |
| 1158 | + if ($fromMeta !== '' && $fromPost !== '' && $fromMeta !== $fromPost) { | |
| 1159 | + return $fromMeta . "\n\n" . $fromPost; | |
| 1160 | + } | |
| 1161 | + | |
| 1162 | + if ($fromMeta !== '') { | |
| 1163 | + return $fromMeta; | |
| 1164 | + } | |
| 1165 | + | |
| 1166 | + return $fromPost; | |
| 1167 | + } | |
| 1168 | + | |
| 1169 | + /** | |
| 1170 | + * @param array<string, mixed> $meta | |
| 1171 | + */ | |
| 1172 | + private function legacyMetaTrimmedString(array $meta, string $key): string | |
| 1173 | + { | |
| 1174 | + if (!array_key_exists($key, $meta) || $meta[$key] === null || $meta[$key] === '') { | |
| 1175 | + return ''; | |
| 1176 | + } | |
| 1177 | + | |
| 1178 | + $value = $meta[$key]; | |
| 1179 | + if (is_string($value)) { | |
| 1180 | + $value = maybe_unserialize($value); | |
| 1181 | + } | |
| 1182 | + | |
| 1183 | + if (!is_string($value)) { | |
| 1184 | + return ''; | |
| 1185 | + } | |
| 1186 | + | |
| 1187 | + return trim($value); | |
| 1127 | 1188 | } |
| 1128 | 1189 | } |