PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.6
Yatra – Travel Booking & Tour Operator Software v3.0.2.6
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 / Core / Database.php

Database.php in Yatra – Travel Booking & Tour Operator Software 3.0.2.6, at app/Core/Database.php

165 lines 5.7 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\Core;
6
7 use Yatra\Database\Tables\TripsTable;
8 use Yatra\Database\Tables\BookingsTable;
9 use Yatra\Database\Tables\CustomersTable;
10 use Yatra\Database\Tables\ReviewsTable;
11 use Yatra\Database\Tables\DiscountsTable;
12 use Yatra\Database\Tables\EnquiriesTable;
13 use Yatra\Database\Tables\BookingPaymentsTable;
14 use Yatra\Database\Tables\ScheduledPaymentsTable;
15 use Yatra\Database\Tables\PaymentTokensTable;
16 use Yatra\Database\Tables\BookingTravellersTable;
17 use Yatra\Database\Tables\BookingTravellerMetaTable;
18 use Yatra\Database\Tables\BookingDeparturesTable;
19 use Yatra\Database\Tables\DeparturesTable;
20 use Yatra\Database\Tables\TripRevisionsTable;
21
22 // Optimized Tables
23 use Yatra\Database\Tables\ClassificationsTable;
24 use Yatra\Database\Tables\TripClassificationsTable;
25 use Yatra\Database\Tables\TripContentTable;
26 use Yatra\Database\Tables\TripItineraryDaysTable;
27 use Yatra\Database\Tables\TripItineraryDayEntryTable;
28
29 // Traditional Availability Tables
30 use Yatra\Database\Tables\TripAvailabilityDatesTable;
31 use Yatra\Database\Tables\TripAvailabilityRulesTable;
32
33 class Database
34 {
35 /**
36 * Create optimized database tables
37 */
38 public static function createTables(): void
39 {
40 global $wpdb;
41
42 // Ensure dbDelta function is available
43 if (!function_exists('\dbDelta')) {
44 if (defined('ABSPATH') && file_exists(ABSPATH . 'wp-admin/includes/upgrade.php')) {
45 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
46 } else {
47 throw new \Exception('WordPress upgrade.php file not found. Cannot create database tables.');
48 }
49 }
50
51 // ============================================
52 // CORE BUSINESS TABLES (Essential - Keep as-is)
53 // ============================================
54
55 // Main trips table
56 dbDelta(TripsTable::getSchema());
57
58 // Bookings and payment tables
59 dbDelta(BookingsTable::getSchema());
60 dbDelta(BookingPaymentsTable::getSchema());
61 dbDelta(ScheduledPaymentsTable::getSchema());
62 dbDelta(PaymentTokensTable::getSchema());
63
64 // Customer and traveller management
65 dbDelta(CustomersTable::getSchema());
66 dbDelta(BookingTravellersTable::getSchema());
67 dbDelta(BookingTravellerMetaTable::getSchema());
68 dbDelta(BookingDeparturesTable::getSchema());
69
70 // Reviews and ratings
71 dbDelta(ReviewsTable::getSchema());
72
73 // Discounts and promotions
74 dbDelta(DiscountsTable::getSchema());
75
76 // Enquiries and contact
77 dbDelta(EnquiriesTable::getSchema());
78
79 // Traditional availability tables (2-table system)
80 dbDelta(TripAvailabilityDatesTable::getSchema());
81 dbDelta(TripAvailabilityRulesTable::getSchema());
82
83 // Trip revisions
84 dbDelta(TripRevisionsTable::getSchema());
85
86 // ============================================
87 // DEPARTURES SYSTEM
88 // ============================================
89
90 // Trip departures table - stores scheduled departure instances
91 dbDelta(DeparturesTable::getSchema());
92
93 // ============================================
94 // OPTIMIZED CONSOLIDATED TABLES (v2.0.0)
95 // ============================================
96
97 // New itinerary system (2-table structure)
98 dbDelta(TripItineraryDaysTable::getSchema());
99 dbDelta(TripItineraryDayEntryTable::getSchema());
100
101 // Unified classification system (consolidates 5 old tables)
102 dbDelta(ClassificationsTable::getSchema());
103
104 // Polymorphic trip relationships (consolidates 4 old tables)
105 dbDelta(TripClassificationsTable::getSchema());
106
107 // Unified content management (consolidates 4 old tables)
108 dbDelta(TripContentTable::getSchema());
109
110 // ============================================
111 // DATABASE VERSION TRACKING
112 // ============================================
113
114 update_option('yatra_db_version', YATRA_VERSION);
115 }
116
117 /**
118 * Update database tables (alias for createTables for backward compatibility)
119 */
120 public static function updateTables(): void
121 {
122 self::createTables();
123 }
124
125 /**
126 * Drop all Yatra database tables
127 */
128 public static function dropTables(): void
129 {
130 global $wpdb;
131
132 // Drop children before parents (FK-safe). Trips last.
133 $tables = [
134 TripAvailabilityDatesTable::getTableName(),
135 TripAvailabilityRulesTable::getTableName(),
136 BookingTravellerMetaTable::getTableName(),
137 BookingTravellersTable::getTableName(),
138 BookingDeparturesTable::getTableName(),
139 DeparturesTable::getTableName(),
140 BookingPaymentsTable::getTableName(),
141 ScheduledPaymentsTable::getTableName(),
142 PaymentTokensTable::getTableName(),
143 BookingsTable::getTableName(),
144 CustomersTable::getTableName(),
145 ReviewsTable::getTableName(),
146 DiscountsTable::getTableName(),
147 EnquiriesTable::getTableName(),
148 TripRevisionsTable::getTableName(),
149 TripItineraryDayEntryTable::getTableName(),
150 TripItineraryDaysTable::getTableName(),
151 TripClassificationsTable::getTableName(),
152 TripContentTable::getTableName(),
153 ClassificationsTable::getTableName(),
154 TripsTable::getTableName(),
155 ];
156
157 foreach ($tables as $table) {
158 $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
159 }
160
161 // Remove database version
162 delete_option('yatra_db_version');
163 }
164 }
165