PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.16
Yatra – Travel Booking & Tour Operator Software v3.0.16
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
← All changes | app/Repositories/SampleDataRepository.php +80 -13 3.0.2.6 → 3.0.16 View file →
@@ -75,9 +75,8 @@
75 75 {
76 76 $file_path = $this->get_sample_data_dir() . $filename;
77 77
78 78 if (!file_exists($file_path)) {
79 - error_log('Yatra Sample Data: File not found: ' . $file_path);
80 79 return [];
81 80 }
82 81
83 82 $json_content = file_get_contents($file_path);
@@ -83,9 +82,8 @@
83 82 $json_content = file_get_contents($file_path);
84 83 $data = json_decode($json_content, true);
85 84
86 85 if (json_last_error() !== JSON_ERROR_NONE) {
87 - error_log('Yatra Sample Data: JSON decode error in ' . $filename . ': ' . json_last_error_msg());
88 86 return [];
89 87 }
90 88
91 89 return $data;
@@ -163,9 +161,8 @@
163 161 $this->classification_ids[$type . ':' . $slug] = $id;
164 162 $this->slug_to_id[$slug] = $id;
165 163 }
166 164 } else {
167 - error_log('Yatra Sample Data: Failed to insert classification: ' . $slug . ' - ' . $this->wpdb->last_error);
168 165 }
169 166 }
170 167
171 168 return $inserted;
@@ -192,9 +189,8 @@
192 189 $item['parent_id'] = $this->classification_ids[$parent_key];
193 190 } else {
194 191 $item['parent_id'] = null;
195 192 if ($parent_slug) {
196 - error_log('Yatra Sample Data: Item type not found for item parent_slug: ' . $parent_slug);
197 193 }
198 194 }
199 195
200 196 $item['created_at'] = $item['created_at'] ?? $now;
@@ -264,9 +260,8 @@
264 260 ));
265 261 if ($existing) {
266 262 $this->classification_ids[$composite_key] = (int) $existing;
267 263 } else {
268 - error_log('Yatra Sample Data: Classification not found: ' . $composite_key);
269 264 continue;
270 265 }
271 266 }
272 267
@@ -436,9 +431,8 @@
436 431
437 432 if ($result && $this->wpdb->insert_id) {
438 433 $trip_ids[$trip_slug] = $this->wpdb->insert_id;
439 434 } else {
440 - error_log('Yatra Sample Data: Failed to insert trip: ' . $trip_slug . ' - ' . $this->wpdb->last_error);
441 435 }
442 436 }
443 437
444 438 return $trip_ids;
@@ -473,23 +467,33 @@
473 467 return $inserted;
474 468 }
475 469
476 470 /**
477 - * Insert availability rules
471 + * Insert availability rules.
472 + *
473 + * Sample JSON only knows the legacy columns (`recurrence_type`,
474 + * `capacity_value`, `interval`, `day_of_month`). The new admin React UI
475 + * binds to a parallel set (`rule_type`, `seats_total`, `interval_days`,
476 + * `interval_start_date`). We populate both so a freshly imported sample
477 + * dataset is immediately editable in the new UI without needing the
478 + * idempotent {@see InstallerService::maybeNormalizeAvailabilityRulesLegacyData()}
479 + * heal-step to fix it on next admin_init.
478 480 */
479 481 public function insert_availability_rules($data, $trip_ids)
480 482 {
481 483 $inserted = 0;
482 -
484 +
483 485 foreach ($data as $item) {
484 486 $trip_slug = $item['trip_slug'];
485 487 unset($item['trip_slug']);
486 -
488 +
487 489 if (!isset($trip_ids[$trip_slug])) {
488 490 continue;
489 491 }
490 492 $item['trip_id'] = $trip_ids[$trip_slug];
491 -
493 +
494 + $item = $this->mapLegacyAvailabilityRuleToNewSchema($item);
495 +
492 496 // Convert arrays to JSON
493 497 if (isset($item['days_of_week']) && is_array($item['days_of_week'])) {
494 498 $item['days_of_week'] = json_encode($item['days_of_week']);
495 499 }
@@ -495,19 +499,83 @@
495 499 }
496 500 if (isset($item['recurrence_pattern']) && is_array($item['recurrence_pattern'])) {
497 501 $item['recurrence_pattern'] = json_encode($item['recurrence_pattern']);
498 502 }
499 -
503 +
500 504 $result = $this->wpdb->insert($this->availability_rules_table, $item);
501 505 if ($result) {
502 506 $inserted++;
503 507 }
504 508 }
505 -
509 +
506 510 return $inserted;
507 511 }
508 512
509 513 /**
514 + * Map a sample-data row written against the legacy availability-rule
515 + * schema onto the new-schema columns the admin UI reads.
516 + *
517 + * Mirrors the heal logic in
518 + * {@see InstallerService::maybeNormalizeAvailabilityRulesLegacyData()}
519 + * so write-time and read-time-repair stay in lock-step.
520 + *
521 + * @param array<string, mixed> $item
522 + * @return array<string, mixed>
523 + */
524 + private function mapLegacyAvailabilityRuleToNewSchema(array $item): array
525 + {
526 + $recurrence = isset($item['recurrence_type']) ? (string) $item['recurrence_type'] : 'weekly';
527 + $intervalRaw = isset($item['interval']) ? (int) $item['interval'] : 1;
528 + $intervalNorm = $intervalRaw > 0 ? $intervalRaw : 1;
529 +
530 + if (!isset($item['rule_type']) || $item['rule_type'] === '' || $item['rule_type'] === null) {
531 + switch ($recurrence) {
532 + case 'daily':
533 + $item['rule_type'] = 'interval';
534 + if (!isset($item['interval_days'])) {
535 + $item['interval_days'] = $intervalNorm;
536 + }
537 + if (!isset($item['interval_start_date']) && !empty($item['start_date'])) {
538 + $item['interval_start_date'] = $item['start_date'];
539 + }
540 + break;
541 + case 'monthly':
542 + case 'yearly':
543 + $item['rule_type'] = 'monthly';
544 + break;
545 + case 'custom':
546 + $item['rule_type'] = 'interval';
547 + if (!isset($item['interval_days'])) {
548 + $item['interval_days'] = $intervalNorm;
549 + }
550 + if (!isset($item['interval_start_date']) && !empty($item['start_date'])) {
551 + $item['interval_start_date'] = $item['start_date'];
552 + }
553 + break;
554 + case 'weekly':
555 + default:
556 + $item['rule_type'] = 'weekly';
557 + break;
558 + }
559 + }
560 +
561 + // seats_total mirrors capacity_value when capacity is fixed (the
562 + // sample dataset doesn't model percentage capacity). CapacityService
563 + // and the React table read seats_total directly.
564 + $capacityType = $item['capacity_type'] ?? 'fixed';
565 + if (
566 + !isset($item['seats_total'])
567 + && isset($item['capacity_value'])
568 + && (int) $item['capacity_value'] > 0
569 + && $capacityType === 'fixed'
570 + ) {
571 + $item['seats_total'] = (int) $item['capacity_value'];
572 + }
573 +
574 + return $item;
575 + }
576 +
577 + /**
510 578 * Insert itinerary days. Returns composite key => day_id mapping.
511 579 */
512 580 public function insert_itinerary_days($data, $trip_ids)
513 581 {
@@ -603,9 +671,8 @@
603 671 $result = $this->wpdb->insert($this->itinerary_entries_table, $item);
604 672 if ($result) {
605 673 $inserted++;
606 674 } else {
607 - error_log('Yatra Sample Data: Failed to insert itinerary entry: ' . ($item['title'] ?? 'unknown') . ' - ' . $this->wpdb->last_error);
608 675 }
609 676 }
610 677
611 678 return $inserted;