PluginProbe
Booking Package / trunk
Booking Package vtrunk
1.7.28 1.7.27 1.7.26 1.7.24 1.7.25 1.7.23 1.7.22 1.7.21 1.7.20 1.7.19 1.7.18 1.7.17 1.7.16 1.7.15 1.7.14 1.7.13 1.7.12 1.7.11 1.7.10 trunk 1.5.30 1.5.31 1.5.32 1.5.33 1.5.35 All 183 releases
booking-package / lib / Database.php

Database.php in Booking Package trunk, at lib/Database.php

933 lines 39.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if(!defined('ABSPATH')){
3 exit;
4 }
5
6 class booking_package_database {
7
8 public $prefix = null;
9
10 public $db_version = null;
11
12 public $db_list = array();
13
14 public $db_object = array();
15
16 public function __construct($prefix, $db_version){
17
18 $this->prefix = $prefix;
19 $this->db_version = $db_version;
20
21 global $wpdb;
22 global $jal_db_version;
23 $charset_collate = $wpdb->get_charset_collate();
24
25 $table_name = $wpdb->prefix . 'booking_package_calendar_accounts';
26 $this->db_object[$table_name] = array(
27 "table" => $table_name,
28 "old_table_name" => $wpdb->prefix . 'booking_package_calendarAccount',
29 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
30 "columns" => array(
31 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
32 "name" => "`name` VARCHAR(255) NOT NULL",
33 "type" => "`type` VARCHAR(50) DEFAULT 'day'",
34 "schedulesSharing" => "`schedulesSharing` INT(11) DEFAULT 0",
35 "targetSchedules" => "`targetSchedules` INT(11) DEFAULT 0",
36 "cost" => "`cost` INT(11) DEFAULT 0",
37 "hotelChargeOnSunday" => "`hotelChargeOnSunday` INT(11) DEFAULT 0",
38 "hotelChargeOnMonday" => "`hotelChargeOnMonday` INT(11) DEFAULT 0",
39 "hotelChargeOnTuesday" => "`hotelChargeOnTuesday` INT(11) DEFAULT 0",
40 "hotelChargeOnWednesday" => "`hotelChargeOnWednesday` INT(11) DEFAULT 0",
41 "hotelChargeOnThursday" => "`hotelChargeOnThursday` INT(11) DEFAULT 0",
42 "hotelChargeOnFriday" => "`hotelChargeOnFriday` INT(11) DEFAULT 0",
43 "hotelChargeOnSaturday" => "`hotelChargeOnSaturday` INT(11) DEFAULT 0",
44 "hotelChargeOnDayBeforeNationalHoliday" => "`hotelChargeOnDayBeforeNationalHoliday` INT(11) DEFAULT 0",
45 "hotelChargeOnNationalHoliday" => "`hotelChargeOnNationalHoliday` INT(11) DEFAULT 0",
46 "maximumNights" => "`maximumNights` INT(11) DEFAULT 0",
47 "minimumNights" => "`minimumNights` INT(11) DEFAULT 0",
48 "multipleRooms" => "`multipleRooms` INT(11) DEFAULT 0",
49 "maxAccountScheduleDay" => "`maxAccountScheduleDay` INT(11) DEFAULT 30",
50 "unavailableDaysFromToday" => "`unavailableDaysFromToday` INT(11) DEFAULT 1",
51 "autoPublish" => "`autoPublish` INT(11) DEFAULT 0",
52 "numberOfRoomsAvailable" => "`numberOfRoomsAvailable` INT(11) DEFAULT 1",
53 "numberOfPeopleInRoom" => "`numberOfPeopleInRoom` INT(11) DEFAULT 2",
54 "includeChildrenInRoom" => "`includeChildrenInRoom` INT(1) DEFAULT 0",
55 "formatNightDay" => "`formatNightDay` INT(1) DEFAULT 0",
56 "expressionsCheck" => "`expressionsCheck` INT(1) DEFAULT 0",
57 "status" => "`status` VARCHAR(50) DEFAULT NULL",
58 "courseTitle" => "`courseTitle` VARCHAR(255) DEFAULT NULL",
59 "courseBool" => "`courseBool` INT(1) DEFAULT 0",
60 "hasMultipleServices" => "`hasMultipleServices` INT(1) DEFAULT 0",
61 "couponsBool" => "`couponsBool` INT(1) DEFAULT 0",
62 "guestsBool" => "`guestsBool` INT(1) DEFAULT 0",
63 /**
64 "minimumGuests" => "`minimumGuests` VARCHAR(255) DEFAULT '{}'",
65 "maximumGuests" => "`maximumGuests` VARCHAR(255) DEFAULT '{}'",
66 **/
67 "limitNumberOfGuests" => "`limitNumberOfGuests` VARCHAR(255) DEFAULT '{}'",
68 "created" => "`created` INT(11) DEFAULT NULL",
69 "googleCalendarID" => "`googleCalendarID` VARCHAR(255) DEFAULT NULL",
70 "idForGoogleWebhook" => "`idForGoogleWebhook` VARCHAR(255) DEFAULT NULL",
71 "expirationForGoogleWebhook" => "`expirationForGoogleWebhook` INT(1) DEFAULT 0",
72 "uploadDate" => "`uploadDate` INT(11) DEFAULT NULL",
73 "enableFixCalendar" => "`enableFixCalendar` INT(11) DEFAULT 0",
74 "yearForFixCalendar" => "`yearForFixCalendar` INT(11) DEFAULT 0",
75 "monthForFixCalendar" => "`monthForFixCalendar` INT(11) DEFAULT 0",
76 "displayRemainingCapacity" => "`displayRemainingCapacity` INT(11) DEFAULT 0",
77 "subscriptionIdForStripe" => "`subscriptionIdForStripe` VARCHAR(255) DEFAULT ''",
78 "enableSubscriptionForStripe" => "`enableSubscriptionForStripe` INT(11) DEFAULT 0",
79 "termsOfServiceForSubscription" => "`termsOfServiceForSubscription` VARCHAR(255) DEFAULT ''",
80 "enableTermsOfServiceForSubscription" => "`enableTermsOfServiceForSubscription` INT(11) DEFAULT 0",
81 "privacyPolicyForSubscription" => "`privacyPolicyForSubscription` VARCHAR(255) DEFAULT ''",
82 "enablePrivacyPolicyForSubscription" => "`enablePrivacyPolicyForSubscription` INT(11) DEFAULT 0",
83 "displayRemainingCapacityInCalendar" => "`displayRemainingCapacityInCalendar` INT(1) DEFAULT 0",
84 "displayThresholdOfRemainingCapacity" => "`displayThresholdOfRemainingCapacity` INT(3) DEFAULT 50",
85 "displayRemainingCapacityInCalendarAsNumber" => "`displayRemainingCapacityInCalendarAsNumber` INT(1) DEFAULT 0",
86 "displayRemainingCapacityHasMoreThenThreshold" => "`displayRemainingCapacityHasMoreThenThreshold` VARCHAR(255) DEFAULT ''",
87 "displayRemainingCapacityHasLessThenThreshold" => "`displayRemainingCapacityHasLessThenThreshold` VARCHAR(255) DEFAULT ''",
88 "displayRemainingCapacityHas0" => "`displayRemainingCapacityHas0` VARCHAR(255) DEFAULT ''",
89 "startOfWeek" => "`startOfWeek` INT(1) DEFAULT 0",
90 "ical" => "`ical` INT(1) DEFAULT 0",
91 "icalToken" => "`icalToken` VARCHAR(255) DEFAULT '0'",
92 "syncPastCustomersForIcal" => "`syncPastCustomersForIcal` INT(10) DEFAULT 7",
93 "cancellationOfBooking" => "`cancellationOfBooking` INT(1) DEFAULT 0",
94 "displayDetailsOfCanceled" => "`displayDetailsOfCanceled` INT(1) DEFAULT 1",
95 "allowCancellationVisitor" => "`allowCancellationVisitor` INT(1) DEFAULT 0",
96 "allowCancellationUser" => "`allowCancellationUser` INT(1) DEFAULT 0",
97 "refuseCancellationOfBooking" => "`refuseCancellationOfBooking` VARCHAR(20) DEFAULT 'not_refuse'",
98 "preparationTime" => "`preparationTime` INT(1) DEFAULT 0",
99 "positionPreparationTime" => "`positionPreparationTime` VARCHAR(20) DEFAULT 'before_after'",
100 "timezone" => "`timezone` VARCHAR(100) DEFAULT 'none'",
101 "flowOfBooking" => "`flowOfBooking` VARCHAR(100) DEFAULT 'calendar'",
102 "paymentMethod" => "`paymentMethod` TEXT DEFAULT NULL",
103 "email_from" => "`email_from` VARCHAR(255) DEFAULT NULL",
104 "email_to" => "`email_to` VARCHAR(255) DEFAULT NULL",
105 "email_from_title" => "`email_from_title` VARCHAR(255) DEFAULT NULL",
106 "email_to_title" => "`email_to_title` VARCHAR(255) DEFAULT NULL",
107 "servicesPage" => "`servicesPage` INT(11) DEFAULT NULL",
108 "calenarPage" => "`calenarPage` INT(11) DEFAULT NULL",
109 "schedulesPage" => "`schedulesPage` INT(11) DEFAULT NULL",
110 "visitorDetailsPage" => "`visitorDetailsPage` INT(11) DEFAULT NULL",
111 "confirmDetailsPage" => "`confirmDetailsPage` INT(11) DEFAULT NULL",
112 "thanksPage" => "`thanksPage` INT(11) DEFAULT NULL",
113 "redirectPage" => "`redirectPage` INT(11) DEFAULT NULL",
114 "redirectURL" => "`redirectURL` VARCHAR(255) DEFAULT NULL",
115 "redirectMode" => "`redirectMode` VARCHAR(255) DEFAULT 'page'",
116 "blockSameTimeBookingByUser" => "`blockSameTimeBookingByUser` INT(1) DEFAULT 0",
117 "bookingVerificationCode" => "`bookingVerificationCode` VARCHAR(20) DEFAULT 'false'",
118 "bookingVerificationCodeToUser" => "`bookingVerificationCodeToUser` VARCHAR(20) DEFAULT 'false'",
119 "bookingReminder" => "`bookingReminder` INT(11) DEFAULT 60",
120 "insertConfirmedPage" => "`insertConfirmedPage` INT(1) DEFAULT 0",
121 "attachICalendar" => "`attachICalendar` INT(1) DEFAULT 0",
122 "messagingService" => "`messagingService` VARCHAR(255) DEFAULT NULL",
123 "customizeLabelsBool" => "`customizeLabelsBool` INT(1) DEFAULT 0",
124 "customizeLabels" => "`customizeLabels` TEXT DEFAULT NULL",
125 "customizeButtonsBool" => "`customizeButtonsBool` INT(1) DEFAULT 0",
126 "customizeButtons" => "`customizeButtons` TEXT DEFAULT NULL",
127 "customizeLayoutsBool" => "`customizeLayoutsBool` INT(1) DEFAULT 0",
128 "customizeLayouts" => "`customizeLayouts` TEXT DEFAULT NULL",
129 "maxBookingSlotsPerDay" => "`maxBookingSlotsPerDay` TEXT DEFAULT NULL",
130 ),
131 );
132
133 $table_name = $wpdb->prefix . 'booking_package_template_schedules';
134 $this->db_object[$table_name] = array(
135 "table" => $table_name,
136 "old_table_name" => $wpdb->prefix . 'booking_package_templateSchedule',
137 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
138 "columns" => array(
139 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
140 "accountKey" => "`accountKey` INT(11) NOT NULL",
141 "weekKey" => "`weekKey` INT(11) NOT NULL",
142 "hour" => "`hour` INT(11) NOT NULL",
143 "min" => "`min` INT(11) NOT NULL",
144 "title" => "`title` VARCHAR(255) DEFAULT NULL",
145 "cost" => "`cost` INT DEFAULT NULL",
146 "capacity" => "`capacity` INT(11) NOT NULL",
147 "deadlineTime" => "`deadlineTime` INT(11) NOT NULL DEFAULT 0",
148 "stop" => "`stop` VARCHAR(255) DEFAULT NULL",
149 "holiday" => "`holiday` VARCHAR(255) DEFAULT NULL",
150 "uploadDate" => "`uploadDate` INT(11) DEFAULT NULL",
151 ),
152 );
153
154
155 $table_name = $wpdb->prefix . 'booking_package_schedules';
156 $this->db_object[$table_name] = array(
157 "table" => $table_name,
158 "old_table_name" => $wpdb->prefix . 'booking_package_schedule',
159 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
160 "columns" => array(
161 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
162 "accountKey" => "`accountKey` INT(11) NOT NULL",
163 "unixTime" => "`unixTime` INT(11) NOT NULL",
164 "year" => "`year` INT(11) NOT NULL",
165 "month" => "`month` INT(11) NOT NULL",
166 "day" => "`day` INT(11) NOT NULL",
167 "weekKey" => "`weekKey` INT(11) NOT NULL",
168 "hour" => "`hour` INT(11) NOT NULL",
169 "min" => "`min` INT(11) NOT NULL",
170 "title" => "`title` VARCHAR(255) DEFAULT NULL",
171 "status" => "`status` VARCHAR(255) DEFAULT 'open'",
172 "cost" => "`cost` FLOAT DEFAULT NULL",
173 "bookingCount" => "`bookingCount` INT(11) DEFAULT 0",
174 "capacity" => "`capacity` INT(11) NOT NULL",
175 "remainder" => "`remainder` INT(11) NOT NULL",
176 "deadlineTime" => "`deadlineTime` INT(11) NOT NULL DEFAULT 0",
177 "waitingRemainder" => "`waitingRemainder` INT(11) NOT NULL DEFAULT 0",
178 "stop" => "`stop` VARCHAR(255) DEFAULT 'false'",
179 "holiday" => "`holiday` VARCHAR(255) DEFAULT NULL",
180 "uploadDate" => "`uploadDate` INT(11) DEFAULT NULL",
181 "expirationDateTrigger" => "`expirationDateTrigger` VARCHAR(255) DEFAULT 'dateBooked'",
182 "expirationDateStatus" => "`expirationDateStatus` INT(11) DEFAULT 0",
183 "expirationDateFrom" => "`expirationDateFrom` INT(11) DEFAULT 0",
184 "expirationDateTo" => "`expirationDateTo` INT(11) DEFAULT 0",
185 "publishingDate" => "`publishingDate` INT(11) DEFAULT 0",
186 ),
187 );
188
189 $table_name = $wpdb->prefix . 'booking_package_services';
190 $this->db_object[$table_name] = array(
191 "table" => $table_name,
192 "old_table_name" => $wpdb->prefix . 'booking_package_courseData',
193 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
194 "columns" => array(
195 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
196 "accountKey" => "`accountKey` INT(11) NOT NULL",
197 "name" => "`name` VARCHAR(255) DEFAULT NULL",
198 "description" => "`description` TEXT DEFAULT NULL",
199 "time" => "`time` INT(11) DEFAULT NULL",
200 "cost" => "`cost` FLOAT DEFAULT NULL",
201 "cost_1" => "`cost_1` FLOAT DEFAULT NULL",
202 "cost_2" => "`cost_2` FLOAT DEFAULT NULL",
203 "cost_3" => "`cost_3` FLOAT DEFAULT NULL",
204 "cost_4" => "`cost_4` FLOAT DEFAULT NULL",
205 "cost_5" => "`cost_5` FLOAT DEFAULT NULL",
206 "cost_6" => "`cost_6` FLOAT DEFAULT NULL",
207 "active" => "`active` VARCHAR(255) DEFAULT NULL",
208 "target" => "`target` VARCHAR(255) DEFAULT 'visitors_users'",
209 "stopServiceUnderFollowingConditions" => "`stopServiceUnderFollowingConditions` VARCHAR(255) DEFAULT 'doNotStop'",
210 "doNotStopServiceAsException" => "`doNotStopServiceAsException` VARCHAR(255) DEFAULT 'hasNotException'",
211 "stopServiceForDayOfTimes" => "`stopServiceForDayOfTimes` VARCHAR(255) DEFAULT 'timeSlot'",
212 "stopServiceForSpecifiedNumberOfTimes" => "`stopServiceForSpecifiedNumberOfTimes` INT(11) DEFAULT 0",
213 "ranking" => "`ranking` INT(11) NOT NULL",
214 "selectOptions" => "`selectOptions` INT(11) DEFAULT 0",
215 "options" => "`options` TEXT DEFAULT NULL",
216 "timeToProvide" => "`timeToProvide` TEXT DEFAULT NULL",
217 "expirationDateTrigger" => "`expirationDateTrigger` VARCHAR(255) DEFAULT 'dateBooked'",
218 "expirationDateStatus" => "`expirationDateStatus` INT(11) DEFAULT 0",
219 "expirationDateFrom" => "`expirationDateFrom` INT(11) DEFAULT 0",
220 "expirationDateTo" => "`expirationDateTo` INT(11) DEFAULT 0",
221 ),
222 );
223
224 $table_name = $wpdb->prefix . 'booking_package_guests';
225 $this->db_object[$table_name] = array(
226 "table" => $table_name,
227 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
228 "columns" => array(
229 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
230 "accountKey" => "`accountKey` INT(11) NOT NULL",
231 "active" => "`active` VARCHAR(255) DEFAULT 'true'",
232 "name" => "`name` VARCHAR(255) DEFAULT NULL",
233 "costInServices" => "`costInServices` VARCHAR(255) DEFAULT 'cost_1'",
234 "target" => "`target` VARCHAR(255) DEFAULT 'adult'",
235 "guestsInCapacity" => "`guestsInCapacity` VARCHAR(255) DEFAULT 'included'",
236 "reflectService" => "`reflectService` INT(1) DEFAULT 0",
237 "reflectAdditional" => "`reflectAdditional` INT(1) DEFAULT 0",
238 "json" => "`json` TEXT DEFAULT NULL",
239 "ranking" => "`ranking` INT(11) NOT NULL",
240 "required" => "`required` INT(1) DEFAULT 0",
241 "description" => "`description` TEXT DEFAULT NULL",
242 ),
243 );
244
245 $table_name = $wpdb->prefix . 'booking_package_form';
246 $this->db_object[$table_name] = array(
247 "table" => $table_name,
248 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
249 "columns" => array(
250 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
251 "accountKey" => "`accountKey` INT(11) NOT NULL",
252 "data" => "`data` TEXT DEFAULT NULL",
253 ),
254 );
255
256 $table_name = $wpdb->prefix . 'booking_package_email_settings';
257 $this->db_object[$table_name] = array(
258 "table" => $table_name,
259 "old_table_name" => $wpdb->prefix . 'booking_package_emailSetting',
260 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
261 "columns" => array(
262 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
263 "accountKey" => "`accountKey` INT(11) NOT NULL",
264 "mail_id" => "`mail_id` VARCHAR(255) NOT NULL",
265 "enable" => "`enable` INT(1) DEFAULT 1",
266 "enableSMS" => "`enableSMS` INT(1) DEFAULT 0",
267 "format" => "`format` VARCHAR(255) DEFAULT 'text'",
268 "notifyAdministrator" => "`notifyAdministrator` INT(1) DEFAULT 1",
269 "attachICalendar" => "`attachICalendar` INT(1) DEFAULT 0",
270 "subject" => "`subject` VARCHAR(255) DEFAULT NULL",
271 "content" => "`content` TEXT DEFAULT NULL",
272 "subjectForAdmin" => "`subjectForAdmin` VARCHAR(255) DEFAULT NULL",
273 "contentForAdmin" => "`contentForAdmin` TEXT DEFAULT NULL",
274 "subjectForIcalendar" => "`subjectForIcalendar` TEXT DEFAULT NULL",
275 "locationForIcalendar" => "`locationForIcalendar` TEXT DEFAULT NULL",
276 "contentForIcalendar" => "`contentForIcalendar` TEXT DEFAULT NULL",
277 "data" => "`data` TEXT DEFAULT NULL",
278 ),
279 );
280
281 $table_name = $wpdb->prefix . 'booking_package_booked_customers';
282 $this->db_object[$table_name] = array(
283 "table" => $table_name,
284 "old_table_name" => $wpdb->prefix . 'booking_package_userPraivateData',
285 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
286 "columns" => array(
287 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
288 "reserveTime" => "`reserveTime` INT(11) NOT NULL",
289 "remainderTime" => "`remainderTime` INT(11) NULL",
290 "remainderBool" => "`remainderBool` VARCHAR(255) DEFAULT 'false'",
291 "maintenanceTime" => "`maintenanceTime` INT(11) DEFAULT 0",
292 "permission" => "`permission` VARCHAR(255) DEFAULT 'private'",
293 "status" => "`status` VARCHAR(255) DEFAULT NULL",
294 "type" => "`type` VARCHAR(255) DEFAULT 'day'",
295 "accountKey" => "`accountKey` INT(11) NOT NULL",
296 "accountName" => "`accountName` VARCHAR(255) DEFAULT NULL",
297 "accountCost" => "`accountCost` INT(11) DEFAULT NULL",
298 "checkIn" => "`checkIn` INT(11) DEFAULT 0",
299 "checkOut" => "`checkOut` INT(11) DEFAULT 0",
300 "scheduleUnixTime" => "`scheduleUnixTime` INT(11) DEFAULT 0",
301 "scheduleWeek" => "`scheduleWeek` INT(11) DEFAULT 0",
302 "scheduleTitle" => "`scheduleTitle` VARCHAR(255) DEFAULT NULL",
303 "scheduleCost" => "`scheduleCost` INT(11) DEFAULT NULL",
304 "scheduleKey" => "`scheduleKey` INT(11) DEFAULT NULL",
305 "applicantCount" => "`applicantCount` INT(11) DEFAULT 1",
306 "courseKey" => "`courseKey` VARCHAR(255) DEFAULT NULL",
307 "courseTitle" => "`courseTitle` VARCHAR(255) DEFAULT NULL",
308 "courseName" => "`courseName` VARCHAR(255) DEFAULT NULL",
309 "courseTime" => "`courseTime` INT(11) DEFAULT NULL",
310 "courseCost" => "`courseCost` INT(11) DEFAULT NULL",
311 "options" => "`options` TEXT DEFAULT NULL",
312 "tax" => "`tax` INT(11) DEFAULT 0",
313 "payMode" => "`payMode` VARCHAR(255) DEFAULT NULL",
314 "payId" => "`payId` VARCHAR(255) DEFAULT NULL",
315 "payName" => "`payName` VARCHAR(255) DEFAULT NULL",
316 "payToken" => "`payToken` VARCHAR(255) DEFAULT NULL",
317 "currency" => "`currency` VARCHAR(3) DEFAULT 'usd'",
318 "praivateData" => "`praivateData` TEXT DEFAULT NULL",
319 "emails" => "`emails` TEXT DEFAULT NULL",
320 "accommodationDetails" => "`accommodationDetails` TEXT DEFAULT NULL",
321 "guests" => "`guests` TEXT DEFAULT NULL",
322 "iCalUIDforGoogleCalendar" => "`iCalUIDforGoogleCalendar` VARCHAR(60) DEFAULT NULL",
323 "iCalIDforGoogleCalendar" => "`iCalIDforGoogleCalendar` VARCHAR(60) DEFAULT NULL",
324 "resultOfGoogleCalendar" => "`resultOfGoogleCalendar` INT(1) DEFAULT NULL",
325 "resultModeOfGoogleCalendar" => "`resultModeOfGoogleCalendar` VARCHAR(60) DEFAULT NULL",
326 "cancellationToken" => "`cancellationToken` VARCHAR(255) DEFAULT NULL",
327 "permalink" => "`permalink` TEXT DEFAULT NULL",
328 "preparation" => "`preparation` VARCHAR(255) DEFAULT NULL",
329 "taxes" => "`taxes` TEXT DEFAULT NULL",
330 "user_id" => "`user_id` INT(11) NULL",
331 "user_login" => "`user_login` VARCHAR(100) NULL",
332 "couponKey" => "`couponKey` VARCHAR(255) DEFAULT NULL",
333 "coupon" => "`coupon` TEXT DEFAULT NULL",
334 "bookingReminder" => "`bookingReminder` INT(11) DEFAULT 0",
335 "locale" => "`locale` VARCHAR(10) DEFAULT 'en_US'",
336 ),
337 );
338
339
340 $table_name = $wpdb->prefix . 'booking_package_webhook';
341 $this->db_object[$table_name] = array(
342 "table" => $table_name,
343 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
344 "columns" => array(
345 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
346 "target" => "`target` VARCHAR(20) DEFAULT NULL",
347 "server" => "`server` TEXT DEFAULT NULL",
348 "post" => "`post` TEXT DEFAULT NULL",
349 "json" => "`json` TEXT DEFAULT NULL",
350 "date" => "`date` INT(11) NOT NULL",
351 ),
352 );
353
354 $table_name = $wpdb->prefix . 'booking_package_users';
355 $this->db_object[$table_name] = array(
356 "table" => $table_name,
357 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
358 "columns" => array(
359 "key" => "`key` INT(11) NOT NULL PRIMARY KEY",
360 "user_login" => "`user_login` VARCHAR(100) NOT NULL",
361 "status" => "`status` INT(1) DEFAULT NULL",
362 "firstname" => "`firstname` VARCHAR(100) NOT NULL",
363 "lastname" => "`lastname` VARCHAR(100) NOT NULL",
364 "email" => "`email` VARCHAR(100) NOT NULL",
365 "profile" => "`profile` longtext DEFAULT NULL",
366 "value" => "`value` longtext DEFAULT NULL",
367 "user_activation_key" => "`user_activation_key` VARCHAR(100) DEFAULT ''",
368 "subscription_list" => "`subscription_list` longtext NULL",
369 "user_registered" => "`user_registered` VARCHAR(100) DEFAULT 0",
370 "locale" => "`locale` VARCHAR(100) DEFAULT '". get_locale() . "'",
371 ),
372 );
373
374 $table_name = $wpdb->prefix . 'booking_package_regular_holidays';
375 $this->db_object[$table_name] = array(
376 "table" => $table_name,
377 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
378 "columns" => array(
379 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
380 "accountKey" => "`accountKey` VARCHAR(100) NOT NULL",
381 "day" => "`day` INT(1) DEFAULT NULL",
382 "month" => "`month` INT(2) NOT NULL",
383 "year" => "`year` INT(4) NOT NULL",
384 "unixTime" => "`unixTime` VARCHAR(100) NOT NULL",
385 "status" => "`status` VARCHAR(100) NOT NULL",
386 "update" => "`update` VARCHAR(100) DEFAULT ''",
387 ),
388 );
389
390 $table_name = $wpdb->prefix . 'booking_package_subscriptions';
391 $this->db_object[$table_name] = array(
392 "table" => $table_name,
393 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
394 "columns" => array(
395 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
396 "accountKey" => "`accountKey` VARCHAR(100) NOT NULL",
397 "name" => "`name` VARCHAR(255) NOT NULL",
398 "subscription" => "`subscription` VARCHAR(255) NOT NULL",
399 "active" => "`active` VARCHAR(255) DEFAULT NULL",
400 "ranking" => "`ranking` INT(11) DEFAULT 1",
401 "renewal" => "`renewal` INT(11) DEFAULT 1",
402 "limit" => "`limit` INT(11) DEFAULT 1",
403 "numberOfTimes" => "`numberOfTimes` INT(11) DEFAULT 1",
404 ),
405 );
406
407 $table_name = $wpdb->prefix . 'booking_package_taxes';
408 $this->db_object[$table_name] = array(
409 "table" => $table_name,
410 "sql" => "CREATE TABLE ".$table_name." (%s) ".$charset_collate.";",
411 "columns" => array(
412 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
413 "accountKey" => "`accountKey` VARCHAR(100) NOT NULL",
414 "name" => "`name` VARCHAR(255) NOT NULL",
415 "active" => "`active` VARCHAR(255) DEFAULT NULL",
416 "type" => "`type` VARCHAR(20) DEFAULT 'tax'",
417 "tax" => "`tax` VARCHAR(20) DEFAULT 'tax_inclusive'",
418 "method" => "`method` VARCHAR(20) DEFAULT 'addition'",
419 "target" => "`target` VARCHAR(20) DEFAULT 'guest'",
420 "scope" => "`scope` VARCHAR(20) DEFAULT 'day'",
421 "value" => "`value` FLOAT DEFAULT 0",
422 "ranking" => "`ranking` INT(11) NOT NULL",
423 "expirationDateTrigger" => "`expirationDateTrigger` VARCHAR(255) DEFAULT 'dateBooked'",
424 "expirationDateStatus" => "`expirationDateStatus` INT(11) DEFAULT 0",
425 "expirationDateFrom" => "`expirationDateFrom` INT(11) DEFAULT 0",
426 "expirationDateTo" => "`expirationDateTo` INT(11) DEFAULT 0",
427 "generation" => "`generation` INT(11) DEFAULT 1",
428 ),
429 );
430
431 $table_name = $wpdb->prefix . 'booking_package_hotel_options';
432 $this->db_object[$table_name] = array(
433 "table" => $table_name,
434 "old_table_name" => $wpdb->prefix . 'booking_package_optionsForHotel',
435 "sql" => "CREATE TABLE ".$table_name." (%s) ".$charset_collate.";",
436 /** "uniqueKey" => "", **/
437 "columns" => array(
438 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
439 "accountKey" => "`accountKey` VARCHAR(100) NOT NULL",
440 "name" => "`name` VARCHAR(255) NOT NULL",
441 "active" => "`active` VARCHAR(255) DEFAULT NULL",
442 "required" => "`required` INT(1) DEFAULT 0",
443 "description" => "`description` TEXT DEFAULT NULL",
444 "target" => "`target` VARCHAR(20) DEFAULT 'guests'",
445 "range" => "`range` VARCHAR(20) DEFAULT 'allDays'",
446 "chargeForAdults" => "`chargeForAdults` FLOAT DEFAULT 0",
447 "chargeForChildren" => "`chargeForChildren` FLOAT DEFAULT 0",
448 "chargeForRoom" => "`chargeForRoom` FLOAT DEFAULT 0",
449 "json" => "`json` TEXT DEFAULT NULL",
450 "ranking" => "`ranking` INT(11) NOT NULL",
451 ),
452 );
453
454 $table_name = $wpdb->prefix . 'booking_package_coupons';
455 $this->db_object[$table_name] = array(
456 "table" => $table_name,
457 "sql" => "CREATE TABLE ".$table_name." (%s) ".$charset_collate.";",
458 /** "uniqueKey" => "UNIQUE KEY id (`key`)", **/
459 "columns" => array(
460 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
461 "id" => "`id` VARCHAR(255) DEFAULT NULL",
462 "name" => "`name` VARCHAR(255) DEFAULT NULL",
463 "active" => "`active` INT(11) DEFAULT 1",
464 "status" => "`status` VARCHAR(20) DEFAULT 'active'",
465 "value" => "`value` FLOAT DEFAULT 0",
466 "accountKey" => "`accountKey` VARCHAR(100) NOT NULL",
467 "method" => "`method` VARCHAR(20) DEFAULT 'subtraction'",
468 "target" => "`target` VARCHAR(255) DEFAULT 'visitors'",
469 "limited" => "`limited` VARCHAR(255) DEFAULT 'unlimited'",
470 "expirationDateStatus" => "`expirationDateStatus` INT(11) DEFAULT 0",
471 "expirationDateFrom" => "`expirationDateFrom` INT(11) DEFAULT 0",
472 "expirationDateTo" => "`expirationDateTo` INT(11) DEFAULT 0",
473 "description" => "`description` TEXT DEFAULT NULL",
474 ),
475 );
476
477 $table_name = $wpdb->prefix . 'booking_package_block_list';
478 $this->db_object[$table_name] = array(
479 "table" => $table_name,
480 "old_table_name" => $wpdb->prefix . 'booking_package_blockList',
481 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
482 "columns" => array(
483 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
484 "type" => "`type` VARCHAR(255) DEFAULT 'email'",
485 "value" => "`value` VARCHAR(255) NOT NULL",
486 "date" => "`date` INT(11) NOT NULL",
487 ),
488 );
489
490 $table_name = $wpdb->prefix . 'booking_package_error';
491 $this->db_object[$table_name] = array(
492 "table" => $table_name,
493 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
494 "columns" => array(
495 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
496 "file" => "`file` VARCHAR(255) DEFAULT NULL",
497 "url" => "`url` VARCHAR(255) NOT NULL",
498 "line" => "`line` INT(11) NOT NULL",
499 "col" => "`col` INT(11) NOT NULL",
500 "code" => "`code` VARCHAR(255) NOT NULL",
501 "version" => "`version` VARCHAR(255) NOT NULL",
502 "browser" => "`browser` VARCHAR(255) NOT NULL",
503 "message" => "`message` TEXT NOT NULL",
504 "date" => "`date` INT(11) DEFAULT NULL",
505 ),
506 );
507
508 /**
509 $table_name = $wpdb->prefix . 'booking_package_test';
510 $this->db_object[$table_name] = array(
511 "table" => $table_name,
512 "old_table_name" => $wpdb->prefix . 'booking_package_test1',
513 "sql" => "CREATE TABLE " . $table_name . " (%s) " . $charset_collate . ";",
514 "columns" => array(
515 "key" => "`key` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT",
516 "message" => "`message` text NOT NULL",
517 "date" => "`date` int(11) DEFAULT NULL",
518 ),
519 );
520 **/
521
522 }
523
524 public function getTableList() {
525
526 return $this->db_object;
527
528 }
529
530 public function new_create() {
531
532 global $wpdb;
533 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
534
535 $queries = array('tables' => array(), 'columns' => array(), 'lastUpdate' => date('r'));
536 update_option('_' . $this->prefix . 'databaseUpdateErrors', json_encode($queries));
537
538 /**
539 if (is_null(get_option('_' . $this->prefix . 'databaseUpdateErrors', null))) {
540 add_option('_' . $this->prefix . 'databaseUpdateErrors', json_encode($queries));
541 }
542 **/
543
544
545 /**
546 $all_existing_tables = $wpdb->get_col("SHOW TABLES LIKE '" . $wpdb->prefix . "booking_package_%'");
547 foreach ((array) $this->db_object as $new_table_name => $table_object) {
548
549 if (isset($table_object['old_table_name'])) {
550 $old_table_name = $table_object['old_table_name'];
551
552 if (in_array($old_table_name, $all_existing_tables) && in_array($new_table_name, $all_existing_tables) === false) {
553
554 $rename_query = sprintf('RENAME TABLE `%s` TO `%s`;', $old_table_name, $new_table_name);
555 $wpdb->query($rename_query);
556
557 }
558 }
559
560 }
561
562 foreach ((array) $this->db_object as $table_name => $table_object) {
563
564 $table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_name)) === $table_name;
565
566 if (!$table_exists) {
567
568 $columns = array_values($table_object['columns']);
569 if (!empty($table_object['uniqueKey'])) {
570 #$columns[] = $table_object['uniqueKey'];
571 }
572
573 $columns_sql = implode(",\n", $columns);
574 $create_sql = sprintf($table_object['sql'], $columns_sql);
575 $wpdb->query($create_sql);
576
577 } else {
578
579 $defined_column_names = array_keys($table_object['columns']);
580 $existing_columns = $wpdb->get_col("DESCRIBE `" . $table_name . "`;");
581
582 $columns_to_add = array_diff($defined_column_names, $existing_columns);
583 if (!empty($columns_to_add)) {
584 $add_clauses = [];
585 foreach ($columns_to_add as $column_name) {
586
587 $column_sql = $table_object['columns'][$column_name];
588 $add_clauses[] = "ADD COLUMN " . $column_sql;
589
590 }
591 $alter_sql = "ALTER TABLE `" . $table_name . "` " . implode(', ', $add_clauses);
592 $wpdb->query($alter_sql);
593 }
594
595 $columns_to_delete = array_diff($existing_columns, $defined_column_names);
596 if (!empty($columns_to_delete)) {
597 $drop_clauses = [];
598 foreach ($columns_to_delete as $column_name) {
599 $drop_clauses[] = "DROP COLUMN `{$column_name}`";
600 }
601
602 $alter_sql = "ALTER TABLE `" . $table_name . "` " . implode(', ', $drop_clauses);
603 $wpdb->query($alter_sql);
604 }
605
606 $columns_to_modify = array_intersect($defined_column_names, $existing_columns);
607 if (!empty($columns_to_modify)) {
608 foreach ($columns_to_modify as $column_name) {
609
610 if ($column_name === 'key') {
611 continue;
612 }
613
614 $column_sql = $table_object['columns'][$column_name];
615 $alter_sql = "ALTER TABLE `" . $table_name . "` MODIFY COLUMN " . $column_sql;
616 $wpdb->query($alter_sql);
617
618 }
619
620 }
621
622 }
623
624 }
625 **/
626
627 $all_existing_tables = $wpdb->get_col("SHOW TABLES LIKE '" . $wpdb->prefix . "booking_package_%'");
628 $table_columns_map = [];
629 foreach ($all_existing_tables as $table_name) {
630
631 $table_columns_map[$table_name] = $wpdb->get_col("DESCRIBE `" . $table_name . "`");
632
633 }
634
635 $sql_to_execute = [];
636
637 foreach ((array) $this->db_object as $new_table_name => $table_object) {
638
639 if (isset($table_object['old_table_name'])) {
640
641 $old_table_name = $table_object['old_table_name'];
642 if (in_array($old_table_name, $all_existing_tables) && !in_array($new_table_name, $all_existing_tables)) {
643
644 $rename_query = sprintf('RENAME TABLE `%s` TO `%s`;', $old_table_name, $new_table_name);
645 $wpdb->query($rename_query);
646
647 $table_columns_map[$new_table_name] = $table_columns_map[$old_table_name];
648 unset($table_columns_map[$old_table_name]);
649
650 $key = array_search($old_table_name, $all_existing_tables, true);
651 if ($key !== false) {
652
653 unset($all_existing_tables[$key]);
654
655 }
656 $all_existing_tables[] = $new_table_name;
657
658 }
659
660 }
661
662 }
663
664 foreach ((array) $this->db_object as $table_name => $table_object) {
665
666 if (!in_array($table_name, $all_existing_tables)) {
667
668 $columns = implode(", ", array_values($table_object['columns']));
669 $create_sql = sprintf($table_object['sql'], $columns);
670 dbDelta($create_sql);
671
672 } else {
673
674 $defined_columns = $table_object['columns'];
675 $existing_columns = isset($table_columns_map[$table_name]) ? $table_columns_map[$table_name] : [];
676 $columns_to_add = [];
677 foreach ($defined_columns as $column_key => $column_sql) {
678
679
680 if (!in_array($column_key, $existing_columns)) {
681
682 $columns_to_add[] = 'ADD COLUMN ' . str_replace("\t", " ", $column_sql);
683
684 }
685
686 }
687
688 if (!empty($columns_to_add)) {
689
690 $alter_sql = sprintf('ALTER TABLE `%s` %s;', $table_name, implode(', ', $columns_to_add));
691 $result = $wpdb->query($alter_sql);
692 if ($result === false) {
693
694 var_dump($wpdb->last_error);
695 $queries['columns'][$table_name] = 'Table: ' . $table_name . ', ' . $wpdb->last_error;
696 update_option('_' . $this->prefix . 'databaseUpdateErrors', json_encode($queries));
697
698 }
699
700 }
701
702 }
703
704 }
705
706 return $queries;
707
708 }
709
710 public function create() {
711
712 $queries = array('tables' => array(), 'columns' => array(), 'lastUpdate' => date('r'));
713 if (is_null(get_option('_' . $this->prefix . 'databaseUpdateErrors', null))) {
714
715 add_option('_' . $this->prefix . 'databaseUpdateErrors', json_encode($queries));
716
717 }
718
719 $queries = $this->updateTableName($queries);
720
721 global $wpdb;
722 $charset_collate = $wpdb->get_charset_collate();
723 $createdTables = array();
724 $lockTables = array();
725 $rows = $wpdb->get_results("SHOW TABLES;", ARRAY_N);
726 for ($i = 0; $i < count($rows); $i++) {
727
728 array_push($createdTables, $rows[$i][0]);
729 array_push($lockTables, '`' . $rows[$i][0] . '` WRITE');
730
731 }
732
733 $lockTableNames = implode(', ', $lockTables);
734 foreach ((array) $this->db_object as $key => $value) {
735
736 if (array_key_exists($key, $queries['tables']) === false) {
737
738 if (array_search($key, $createdTables) === false) {
739
740 $columns = implode(", ", array_values($value['columns']));
741 $columns = str_replace("\t", " ", $columns);
742 #$columns = str_replace('`', '', $columns);
743 $sql = sprintf($value['sql'], $columns);
744 $wpdb->query('START TRANSACTION');
745 #$wpdb->query("LOCK TABLES `" . $key . "` WRITE");
746 try {
747
748 dbDelta($sql);
749 $wpdb->query('COMMIT');
750
751 } catch (Exception $e) {
752
753 $wpdb->query('ROLLBACK');
754
755 }
756
757 $showSql = $wpdb->prepare(
758 "SHOW TABLES LIKE '%s';",
759 array($value['table'])
760 );
761 $result = $wpdb->get_var($showSql);
762 if (is_null($result) === true) {
763
764 $queries['tables'][$value['table']] = $sql;
765
766 }
767
768 } else {
769
770 $columns = $this->getUncreateColumnsInTable($key, $value['columns']);
771 if (count($columns) > 0) {
772
773 $wpdb->query('START TRANSACTION');
774 #$wpdb->query("LOCK TABLES " . $lockTableNames);
775 try {
776
777 #for ($i = 0; $i < count($columns); $i++) {
778 foreach ((array) $columns as $columnKey => $column) {
779
780 #$sql = sprintf('ALTER TABLE %s ADD COLUMN %s, ALGORITHM=INPLACE, LOCK=DEFAULT;', $value['table'], $column);
781 $sql = sprintf('ALTER TABLE %s ADD COLUMN %s;', $value['table'], $column);
782 $wpdb->query($sql);
783
784 }
785
786 $wpdb->query('COMMIT');
787
788 } catch (Exception $e) {
789
790 $wpdb->query('ROLLBACK');
791
792 }
793
794 foreach ((array) $columns as $columnKey => $column) {
795
796 $result = $wpdb->get_col(sprintf("DESCRIBE %s;", $value['table']));
797 if (in_array($columnKey, $result) === false) {
798
799 #$column = str_replace('`', '', $column);
800 #$sql = sprintf('ALTER TABLE %s ADD COLUMN %s, ALGORITHM=INPLACE, LOCK=DEFAULT;', $value['table'], $column);
801 $sql = sprintf('ALTER TABLE %s ADD COLUMN %s;', $value['table'], $column);
802 $queries['columns'][$value['table'] . '_' . $columnKey] = $sql;
803
804 }
805
806 }
807
808 }
809
810 }
811
812 }
813
814 }
815
816 add_option($this->prefix . "db_version", $this->db_version);
817 update_option('_' . $this->prefix . 'databaseUpdateErrors', sanitize_text_field( json_encode( $queries ) ) );
818 return $queries;
819
820 }
821
822 public function updateTableName($queries) {
823
824 global $wpdb;
825 #$mysqlVersion = $wpdb->get_var("SELECT VERSION()");
826 foreach ((array) $this->db_object as $key => $tableObject) {
827
828 $renameQuery = null;
829 if (array_key_exists('old_table_name', $tableObject) === true) {
830
831 $sql = $wpdb->prepare(
832 "SHOW TABLES LIKE '%s';",
833 array($tableObject['old_table_name'])
834 );
835 $result = $wpdb->get_var($sql);
836 if ($result === $tableObject['old_table_name']) {
837
838 $wpdb->query('START TRANSACTION');
839 try {
840
841 $renameQuery = sprintf('RENAME TABLE %s TO %s;', $tableObject['old_table_name'], $tableObject['table']);
842 $result = $wpdb->query($renameQuery);
843
844 $wpdb->query('COMMIT');
845
846 } catch (Exception $e) {
847
848 $wpdb->query('ROLLBACK');
849
850 }
851
852 $sql = $wpdb->prepare(
853 "SHOW TABLES LIKE '%s';",
854 array($tableObject['table'])
855 );
856 $result = $wpdb->get_var($sql);
857 if (is_null($result) === true) {
858
859 $queries['tables'][$tableObject['table']] = $renameQuery;
860
861 }
862
863 }
864
865 }
866
867 }
868
869 return $queries;
870
871 }
872
873 public function getUncreateColumnsInTable($table_name, $columns){
874
875 global $wpdb;
876 /**
877 $createdColumns = array();
878 $rows = $wpdb->get_results("SHOW COLUMNS FROM `".$table_name."`;", ARRAY_N);
879 for ($i = 0; $i < count($rows); $i++) {
880
881 $key = $rows[$i][0];
882 array_push($createdColumns, $key);
883 if (isset($columns[$key])) {
884
885 unset($columns[$key]);
886
887 }
888
889 }
890
891 return array_values($columns);
892 **/
893
894 $unregisteredColumns = array();
895 $result = $wpdb->get_col(sprintf("DESCRIBE %s;", $table_name));
896 foreach ((array) $columns as $key => $column) {
897
898 if (in_array($key, $result) === false) {
899
900 $column = str_replace("\t", " ", $column);
901 $unregisteredColumns[$key] = $column;
902
903 }
904
905 }
906
907 return $unregisteredColumns;
908
909
910 }
911
912 public function uninstall($delete = true){
913
914 if ($delete === false) {
915
916 return false;
917
918 }
919
920 global $wpdb;
921 $tableList = $this->getTableList();
922 foreach ((array) $tableList as $key => $value) {
923
924 $wpdb->query("DROP TABLE `".$key."`;");
925
926 }
927
928 delete_option($this->prefix . "db_version");
929
930 }
931
932 }
933 ?>