PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.3
Booktics – Appointment Booking Calendar for Service Businesses v1.0.3
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
booktics / base / installer.php

installer.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.3, at base/installer.php

195 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Booktics;
4
5 use Booktics\Dummy_Data\Dummy_Data_Manager;
6
7 class Installer {
8 /**
9 * Initializes the Booktics plugin by performing necessary setup tasks.
10 *
11 * This method performs the following setup operations:
12 * - Creates or updates required database tables
13 * - Initializes user roles and capabilities
14 * - Generates initial onboarding data using dummy data manager
15 */
16 public static function run(): void {
17 self::create_tables();
18 ( new Role() )->init();
19 ( new Dummy_Data_Manager() )->generate_onboarding_data();
20 }
21
22 /**
23 * Creates and updates database tables required for the Booktics plugin.
24 *
25 * Creates the following tables if they don't exist:
26 * - booktics_schedules: Stores scheduling information for team members and services
27 * - booktics_carts: Stores shopping cart information
28 * - booktics_cart_items: Stores individual items in shopping carts
29 * - booktics_orders: Stores order information and payment details
30 * - booktics_payments: Stores payment transaction records
31 *
32 * Also handles table structure updates by adding missing columns to existing tables
33 * and performing necessary column modifications.
34 */
35 private static function create_tables(): void {
36 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
37
38 global $wpdb;
39 $charset_collate = $wpdb->get_charset_collate();
40
41 $table_prefix = $wpdb->prefix;
42 error_log( $table_prefix );
43 $table_schema = array(
44 "CREATE TABLE IF NOT EXISTS {$table_prefix}booktics_schedules (
45 id mediumint(9) NOT NULL AUTO_INCREMENT,
46 team_member_id int(11) NOT NULL,
47 service_id int(11) NOT NULL,
48 location_id int(11) NOT NULL,
49 start_time varchar(100) NOT NULL,
50 end_time varchar(100) NOT NULL,
51 week_day varchar(100) NOT NULL,
52 custom_date varchar(100) NOT NULL,
53 created_at datetime DEFAULT NULL,
54 updated_at datetime DEFAULT NULL,
55 PRIMARY KEY (id)
56 ) $charset_collate;",
57
58 "CREATE TABLE IF NOT EXISTS {$table_prefix}booktics_carts (
59 id mediumint(9) NOT NULL AUTO_INCREMENT,
60 uuid varchar(36) NOT NULL,
61 user_id int(11) NOT NULL,
62 coupon_code varchar(100) DEFAULT NULL,
63 total decimal(10,2) DEFAULT NULL,
64 created_at datetime DEFAULT NULL,
65 updated_at datetime DEFAULT NULL,
66 PRIMARY KEY (id)
67 ) $charset_collate;",
68
69 "CREATE TABLE IF NOT EXISTS {$table_prefix}booktics_cart_items (
70 id mediumint(9) NOT NULL AUTO_INCREMENT,
71 uuid varchar(36) NOT NULL,
72 cart_id mediumint(9) NOT NULL,
73 team_member_id int(11) DEFAULT NULL,
74 service_id int(11) DEFAULT NULL,
75 date date DEFAULT NULL,
76 start_time varchar(100) DEFAULT NULL,
77 end_time varchar(100) DEFAULT NULL,
78 price VARCHAR(100) DEFAULT NULL,
79 created_at datetime DEFAULT NULL,
80 updated_at datetime DEFAULT NULL,
81 PRIMARY KEY (id)
82 ) $charset_collate;",
83
84 "CREATE TABLE IF NOT EXISTS {$table_prefix}booktics_orders (
85 id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
86 order_no VARCHAR(100) NOT NULL,
87 customer_id BIGINT UNSIGNED NOT NULL,
88 customer_note VARCHAR(100) DEFAULT NULL,
89 status VARCHAR(50) DEFAULT 'pending',
90 payment_status VARCHAR(50) DEFAULT NULL,
91 timezone VARCHAR(50) DEFAULT 'UTC',
92 price_breakdown JSON DEFAULT NULL,
93 tax_total VARCHAR(100) DEFAULT NULL,
94 coupon_code VARCHAR(100) DEFAULT NULL,
95 coupon_discount VARCHAR(100) DEFAULT NULL,
96 subtotal VARCHAR(100) DEFAULT 0,
97 total VARCHAR(100) DEFAULT 0,
98 payment_method VARCHAR(50) DEFAULT NULL,
99 payment_intent_id VARCHAR(250) DEFAULT NULL,
100 payment_transaction_id VARCHAR(250) DEFAULT NULL,
101 created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
102 updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
103 PRIMARY KEY (id),
104 INDEX (order_no)
105 ) $charset_collate;",
106
107 "CREATE TABLE IF NOT EXISTS {$table_prefix}booktics_payments (
108 id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
109 order_id BIGINT UNSIGNED NOT NULL,
110 customer_id BIGINT UNSIGNED NOT NULL,
111 amount VARCHAR(20) NOT NULL,
112 currency VARCHAR(10) DEFAULT 'usd',
113 intent_id VARCHAR(255),
114 transaction_id VARCHAR(255),
115 status varchar(100) NOT NULL DEFAULT 'pending',
116 payment_method VARCHAR(50) NOT NULL,
117 refunded_amount VARCHAR(20) DEFAULT '0.00',
118 failure_reason TEXT,
119 date DATE NOT NULL,
120 date_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
121 INDEX (order_id),
122 INDEX (customer_id),
123 INDEX (intent_id),
124 INDEX (transaction_id)
125 ) $charset_collate;",
126 );
127
128 foreach ( $table_schema as $table_sql ) {
129 dbDelta( $table_sql );
130 }
131
132 // Add missing columns to booktics_orders table
133 $orders_table = "{$table_prefix}booktics_orders";
134 $orders_columns = $wpdb->get_col( 'DESC `' . esc_sql( $orders_table ) . '`', 0 );
135
136 $orders_columns_to_add = array(
137 'payment_method' => 'VARCHAR(50) DEFAULT NULL',
138 'payment_intent_id' => 'VARCHAR(250) DEFAULT NULL',
139 'payment_transaction_id' => 'VARCHAR(250) DEFAULT NULL',
140 );
141
142 foreach ( $orders_columns_to_add as $column => $definition ) {
143 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
149 );
150 $wpdb->query( $query );
151 }
152 }
153
154 // Handle booktics_cart_items table
155 $cart_items_table = "{$table_prefix}booktics_cart_items";
156 $cart_items_columns = $wpdb->get_col( 'DESC `' . esc_sql( $cart_items_table ) . '`', 0 );
157
158 // Rename sub_total to subtotal if exists
159 if ( in_array( 'sub_total', $cart_items_columns, true ) ) {
160 $wpdb->query(
161 sprintf(
162 'ALTER TABLE `%s` CHANGE COLUMN `sub_total` `subtotal` VARCHAR(20) NOT NULL',
163 esc_sql( $cart_items_table )
164 )
165 );
166 } elseif ( ! in_array( 'subtotal', $cart_items_columns, true ) ) {
167 $wpdb->query(
168 sprintf(
169 'ALTER TABLE `%s` ADD COLUMN `subtotal` VARCHAR(20) NOT NULL',
170 esc_sql( $cart_items_table )
171 )
172 );
173 }
174
175 $cart_items_columns_to_add = array(
176 'extra_services' => 'TEXT DEFAULT NULL',
177 'total' => 'VARCHAR(20) NOT NULL',
178 'additional_duration_id' => 'VARCHAR(100) NOT NULL',
179 'group_booking' => 'TEXT DEFAULT NULL',
180 );
181
182 foreach ( $cart_items_columns_to_add as $column => $definition ) {
183 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
189 );
190 $wpdb->query( $query );
191 }
192 }
193 }
194 }
195