PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.9
Yatra – Travel Booking & Tour Operator Software v3.0.9
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 2.0.10 All 83 releases
yatra / app / Scripts / DepartureCapacitySyncScript.php

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

66 lines 1.9 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 * Script to update departure capacities from availability dates
13 */
14 class DepartureCapacitySyncScript
15 {
16 private DepartureRepository $departureRepository;
17 private CapacityService $capacityService;
18
19 public function __construct()
20 {
21 $this->departureRepository = new DepartureRepository();
22 $this->capacityService = new CapacityService();
23 }
24
25 /**
26 * Run the capacity sync process
27 */
28 public function run(): array
29 {
30 $results = [
31 'total_departures' => 0,
32 'updated_departures' => 0,
33 'errors' => []
34 ];
35
36 try {
37 // Get all departures
38 $allDepartures = $this->departureRepository->findAll();
39 $results['total_departures'] = count($allDepartures);
40
41 foreach ($allDepartures as $departure) {
42 $date = $departure->start_date ?: $departure->date;
43
44 // Get correct capacity from availability
45 $correctCapacity = $this->capacityService->getCapacityForDate($departure->trip_id, $date);
46
47 // Only update if capacity is different and correct capacity > 0
48 if ($correctCapacity > 0 && $departure->max_capacity !== $correctCapacity) {
49 $updated = $this->departureRepository->update($departure->id, [
50 'max_capacity' => $correctCapacity
51 ]);
52
53 if ($updated) {
54 $results['updated_departures']++;
55 }
56 }
57 }
58
59 } catch (\Throwable $e) {
60 $results['errors'][] = $e->getMessage();
61 }
62
63 return $results;
64 }
65 }
66