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

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

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