PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.27
Booktics – Appointment Booking Calendar for Service Businesses v1.0.27
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
← All changes | base/installer.php +129 -16 1.0.3 → 1.0.27 View file →
@@ -1,8 +1,12 @@
1 1 <?php
2 2
3 3 namespace Booktics;
4 4
5 +if ( ! defined( 'ABSPATH' ) ) {
6 + exit;
7 +}
8 +
5 9 use Booktics\Dummy_Data\Dummy_Data_Manager;
6 10
7 11 class Installer {
8 12 /**
@@ -31,9 +35,9 @@
31 35 *
32 36 * Also handles table structure updates by adding missing columns to existing tables
33 37 * and performing necessary column modifications.
34 38 */
35 - private static function create_tables(): void {
39 + public static function create_tables(): void {
36 40 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
37 41
38 42 global $wpdb;
39 43 $charset_collate = $wpdb->get_charset_collate();
@@ -38,9 +42,8 @@
38 42 global $wpdb;
39 43 $charset_collate = $wpdb->get_charset_collate();
40 44
41 45 $table_prefix = $wpdb->prefix;
42 - error_log( $table_prefix );
43 46 $table_schema = array(
44 47 "CREATE TABLE IF NOT EXISTS {$table_prefix}booktics_schedules (
45 48 id mediumint(9) NOT NULL AUTO_INCREMENT,
46 49 team_member_id int(11) NOT NULL,
@@ -71,8 +74,9 @@
71 74 uuid varchar(36) NOT NULL,
72 75 cart_id mediumint(9) NOT NULL,
73 76 team_member_id int(11) DEFAULT NULL,
74 77 service_id int(11) DEFAULT NULL,
78 + location_id int(11) DEFAULT NULL,
75 79 date date DEFAULT NULL,
76 80 start_time varchar(100) DEFAULT NULL,
77 81 end_time varchar(100) DEFAULT NULL,
78 82 price VARCHAR(100) DEFAULT NULL,
@@ -88,8 +92,9 @@
88 92 customer_note VARCHAR(100) DEFAULT NULL,
89 93 status VARCHAR(50) DEFAULT 'pending',
90 94 payment_status VARCHAR(50) DEFAULT NULL,
91 95 timezone VARCHAR(50) DEFAULT 'UTC',
96 + currency VARCHAR(10) DEFAULT NULL,
92 97 price_breakdown JSON DEFAULT NULL,
93 98 tax_total VARCHAR(100) DEFAULT NULL,
94 99 coupon_code VARCHAR(100) DEFAULT NULL,
95 100 coupon_discount VARCHAR(100) DEFAULT NULL,
@@ -97,12 +102,14 @@
97 102 total VARCHAR(100) DEFAULT 0,
98 103 payment_method VARCHAR(50) DEFAULT NULL,
99 104 payment_intent_id VARCHAR(250) DEFAULT NULL,
100 105 payment_transaction_id VARCHAR(250) DEFAULT NULL,
106 + directorist_id BIGINT UNSIGNED DEFAULT NULL,
101 107 created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
102 108 updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
103 109 PRIMARY KEY (id),
104 - INDEX (order_no)
110 + INDEX (order_no),
111 + INDEX (directorist_id)
105 112 ) $charset_collate;",
106 113
107 114 "CREATE TABLE IF NOT EXISTS {$table_prefix}booktics_payments (
108 115 id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
@@ -122,14 +129,100 @@
122 129 INDEX (customer_id),
123 130 INDEX (intent_id),
124 131 INDEX (transaction_id)
125 132 ) $charset_collate;",
133 +
134 + "CREATE TABLE IF NOT EXISTS {$table_prefix}booktics_guests (
135 + id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
136 + wp_user_id BIGINT UNSIGNED DEFAULT NULL,
137 + first_name VARCHAR(100) DEFAULT NULL,
138 + last_name VARCHAR(100) DEFAULT NULL,
139 + user_login VARCHAR(100) DEFAULT NULL,
140 + email VARCHAR(100) DEFAULT NULL,
141 + phone VARCHAR(10) DEFAULT NULL,
142 + description VARCHAR(250) DEFAULT NULL,
143 + image VARCHAR(250) DEFAULT NULL,
144 + status INT DEFAULT 0,
145 + created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
146 + updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
147 + INDEX (wp_user_id),
148 + INDEX (email),
149 + INDEX (first_name)
150 + ) $charset_collate;",
126 151 );
127 -
128 152 foreach ( $table_schema as $table_sql ) {
129 153 dbDelta( $table_sql );
130 154 }
131 155
156 + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.NotPrepared -- Schema migration; direct DB access required, caching inappropriate for DDL, identifiers sanitized via esc_sql().
157 +
158 + // Add currency column to existing orders table if it doesn't exist
159 + $orders_table = "{$table_prefix}booktics_orders";
160 + $column_exists = $wpdb->get_results(
161 + "SHOW COLUMNS FROM `" . \esc_sql( $orders_table ) . "` LIKE 'currency'"
162 + );
163 + if ( empty( $column_exists ) ) {
164 + $wpdb->query(
165 + "ALTER TABLE `" . \esc_sql( $orders_table ) . "` ADD COLUMN currency VARCHAR(10) DEFAULT NULL AFTER timezone"
166 + );
167 + }
168 +
169 + // Handle booktics_guests table
170 + $guests_table = "{$table_prefix}booktics_guests";
171 + $guests_columns = $wpdb->get_col( 'DESC `' . \esc_sql( $guests_table ) . '`', 0 );
172 +
173 + // Drop index on first_name if it exists
174 + $indexes = $wpdb->get_results( "SHOW INDEX FROM `" . \esc_sql( $guests_table ) . "` WHERE Key_name = 'first_name'", ARRAY_A );
175 + if ( ! empty( $indexes ) ) {
176 + $wpdb->query(
177 + sprintf(
178 + 'ALTER TABLE `%s` DROP INDEX `first_name`',
179 + \esc_sql( $guests_table )
180 + )
181 + );
182 + }
183 +
184 + // Rename first_name to name if first_name exists and name does not
185 + if ( in_array( 'first_name', $guests_columns, true ) && ! in_array( 'name', $guests_columns, true ) ) {
186 + $wpdb->query(
187 + sprintf(
188 + 'ALTER TABLE `%s` CHANGE COLUMN `first_name` `name` VARCHAR(100) DEFAULT NULL',
189 + \esc_sql( $guests_table )
190 + )
191 + );
192 + }
193 +
194 + // Remove last_name column if it exists
195 + if ( in_array( 'last_name', $guests_columns, true ) ) {
196 + $wpdb->query(
197 + sprintf(
198 + 'ALTER TABLE `%s` DROP COLUMN `last_name`',
199 + \esc_sql( $guests_table )
200 + )
201 + );
202 + }
203 +
204 + // Add index on name if it does not exist
205 + $indexes_name = $wpdb->get_results( "SHOW INDEX FROM `" . \esc_sql( $guests_table ) . "` WHERE Key_name = 'name'", ARRAY_A );
206 + if ( empty( $indexes_name ) && in_array( 'name', $guests_columns, true ) ) {
207 + $wpdb->query(
208 + sprintf(
209 + 'ALTER TABLE `%s` ADD INDEX (`name`)',
210 + \esc_sql( $guests_table )
211 + )
212 + );
213 + }
214 +
215 + // Alter first_name column if it exists
216 + if ( in_array( 'first_name', $guests_columns, true ) ) {
217 + $wpdb->query(
218 + sprintf(
219 + 'ALTER TABLE `%s` MODIFY COLUMN `first_name` VARCHAR(100) DEFAULT NULL',
220 + \esc_sql( $guests_table )
221 + )
222 + );
223 + }
224 +
132 225 // Add missing columns to booktics_orders table
133 226 $orders_table = "{$table_prefix}booktics_orders";
134 227 $orders_columns = $wpdb->get_col( 'DESC `' . esc_sql( $orders_table ) . '`', 0 );
135 228
@@ -136,22 +229,37 @@
136 229 $orders_columns_to_add = array(
137 230 'payment_method' => 'VARCHAR(50) DEFAULT NULL',
138 231 'payment_intent_id' => 'VARCHAR(250) DEFAULT NULL',
139 232 'payment_transaction_id' => 'VARCHAR(250) DEFAULT NULL',
233 + 'custom_fields' => 'TEXT DEFAULT NULL',
234 + 'directorist_id' => 'BIGINT UNSIGNED DEFAULT NULL',
140 235 );
141 236
142 237 foreach ( $orders_columns_to_add as $column => $definition ) {
143 238 if ( ! in_array( $column, $orders_columns, true ) ) {
144 - $query = sprintf(
145 - 'ALTER TABLE `%s` ADD COLUMN `%s` %s',
146 - esc_sql( $orders_table ),
147 - esc_sql( $column ),
148 - $definition
239 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.NotPrepared -- Schema migration; identifiers sanitized via esc_sql().
240 + $wpdb->query(
241 + sprintf(
242 + 'ALTER TABLE `%s` ADD COLUMN `%s` %s',
243 + esc_sql( $orders_table ),
244 + esc_sql( $column ),
245 + $definition
246 + )
149 247 );
150 - $wpdb->query( $query );
151 248 }
152 249 }
153 250
251 + // Add index for directorist_id if it doesn't exist
252 + $indexes = $wpdb->get_results( "SHOW INDEX FROM `" . esc_sql( $orders_table ) . "` WHERE Key_name = 'directorist_id'", ARRAY_A );
253 + if ( empty( $indexes ) && in_array( 'directorist_id', $orders_columns, true ) ) {
254 + $wpdb->query(
255 + sprintf(
256 + 'ALTER TABLE `%s` ADD INDEX (`directorist_id`)',
257 + esc_sql( $orders_table )
258 + )
259 + );
260 + }
261 +
154 262 // Handle booktics_cart_items table
155 263 $cart_items_table = "{$table_prefix}booktics_cart_items";
156 264 $cart_items_columns = $wpdb->get_col( 'DESC `' . esc_sql( $cart_items_table ) . '`', 0 );
157 265
@@ -176,19 +284,24 @@
176 284 'extra_services' => 'TEXT DEFAULT NULL',
177 285 'total' => 'VARCHAR(20) NOT NULL',
178 286 'additional_duration_id' => 'VARCHAR(100) NOT NULL',
179 287 'group_booking' => 'TEXT DEFAULT NULL',
288 + 'time_format' => 'VARCHAR(10) DEFAULT NULL',
180 289 );
181 290
182 291 foreach ( $cart_items_columns_to_add as $column => $definition ) {
183 292 if ( ! in_array( $column, $cart_items_columns, true ) ) {
184 - $query = sprintf(
185 - 'ALTER TABLE `%s` ADD COLUMN `%s` %s',
186 - esc_sql( $cart_items_table ),
187 - esc_sql( $column ),
188 - $definition
293 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.NotPrepared -- Schema migration; identifiers sanitized via esc_sql().
294 + $wpdb->query(
295 + sprintf(
296 + 'ALTER TABLE `%s` ADD COLUMN `%s` %s',
297 + esc_sql( $cart_items_table ),
298 + esc_sql( $column ),
299 + $definition
300 + )
189 301 );
190 - $wpdb->query( $query );
191 302 }
192 303 }
304 +
305 + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.NotPrepared
193 306 }
194 307 }