PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.7
Yatra – Travel Booking & Tour Operator Software v3.0.7
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 2.0.10 2.0.11 All 82 releases
yatra / app / Scripts / DepartureCapacitySyncFromAvailabilityScript.php

DepartureCapacitySyncFromAvailabilityScript.php in Yatra – Travel Booking & Tour Operator Software 3.0.7, at app/Scripts/DepartureCapacitySyncFromAvailabilityScript.php

109 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Scripts;
6
7 use Yatra\Repositories\DepartureRepository;
8 use Yatra\Services\CapacityService;
9 use Yatra\Models\Departure;
10
11 /**
12 * Comprehensive script to sync all departure capacities from availability
13 * This will update all existing departures and ensure they match availability capacity
14 */
15 class DepartureCapacitySyncFromAvailabilityScript
16 {
17 private DepartureRepository $departureRepository;
18 private CapacityService $capacityService;
19
20 public function __construct()
21 {
22 $this->departureRepository = new DepartureRepository();
23 $this->capacityService = new CapacityService();
24 }
25
26 /**
27 * Run the comprehensive capacity sync process
28 */
29 public function run(): array
30 {
31 $results = [
32 'total_departures' => 0,
33 'updated_departures' => 0,
34 'no_availability_found' => 0,
35 'errors' => []
36 ];
37
38 try {
39 // Get all departures
40 $allDepartures = $this->departureRepository->findAll();
41 $results['total_departures'] = count($allDepartures);
42
43 foreach ($allDepartures as $departure) {
44 $date = $departure->start_date ?: $departure->date;
45
46 // Get correct capacity from availability
47 $correctCapacity = $this->capacityService->getCapacityForDate($departure->trip_id, $date);
48
49 if ($correctCapacity > 0) {
50 // Update if capacity is different
51 if ($departure->max_capacity !== $correctCapacity) {
52 $updated = $this->departureRepository->update($departure->id, [
53 'max_capacity' => $correctCapacity
54 ]);
55
56 if ($updated) {
57 $results['updated_departures']++;
58 }
59 }
60 } else {
61 $results['no_availability_found']++;
62 }
63 }
64
65 } catch (\Throwable $e) {
66 $results['errors'][] = $e->getMessage();
67 }
68
69 return $results;
70 }
71
72 /**
73 * Get a summary of what needs to be updated
74 */
75 public function getSyncSummary(): array
76 {
77 $summary = [
78 'total_departures' => 0,
79 'need_update' => 0,
80 'no_availability' => 0,
81 'already_correct' => 0
82 ];
83
84 try {
85 $allDepartures = $this->departureRepository->findAll();
86 $summary['total_departures'] = count($allDepartures);
87
88 foreach ($allDepartures as $departure) {
89 $date = $departure->start_date ?: $departure->date;
90 $correctCapacity = $this->capacityService->getCapacityForDate($departure->trip_id, $date);
91
92 if ($correctCapacity > 0) {
93 if ($departure->max_capacity !== $correctCapacity) {
94 $summary['need_update']++;
95 } else {
96 $summary['already_correct']++;
97 }
98 } else {
99 $summary['no_availability']++;
100 }
101 }
102 } catch (\Throwable $e) {
103 $summary['errors'][] = $e->getMessage();
104 }
105
106 return $summary;
107 }
108 }
109