PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.15.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.15.3
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
← All changes | includes/Core/Database/DB.php +51 -153 3.2.22.15.3 View file →
@@ -8,10 +8,8 @@
8 8 */
9 9
10 10 namespace BitCode\BitForm\Core\Database;
11 11
12 -use BitCode\BitForm\Core\Util\Log;
13 -
14 12 /**
15 13 * Database Migration
16 14 */
17 15 final class DB
@@ -20,66 +18,8 @@
20 18 * Undocumented function
21 19 *
22 20 * @return void
23 21 */
24 -
25 - /**
26 - * Idempotently add the email-template status/config columns.
27 - *
28 - * @return void
29 - */
30 - public static function ensureEmailTemplateStatusColumn()
31 - {
32 - global $wpdb;
33 - $emailTable = $wpdb->prefix . 'bitforms_email_template';
34 - if (null === $wpdb->get_var("SHOW COLUMNS FROM `{$emailTable}` LIKE 'status'")) {
35 - // Schema migration: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize DDL.
36 - $wpdb->query(
37 - "ALTER TABLE `{$emailTable}`
38 - ADD COLUMN `status` TINYINT(1) DEFAULT 1 AFTER `body`,
39 - ADD COLUMN `config` LONGTEXT NULL AFTER `status`"
40 - );
41 - }
42 - }
43 -
44 - /**
45 - * Idempotently add the workflows `workflow_info` column.
46 - *
47 - * @return void
48 - */
49 - public static function ensureWorkflowInfoColumn()
50 - {
51 - global $wpdb;
52 - $table = $wpdb->prefix . 'bitforms_workflows';
53 - if (null === $wpdb->get_var("SHOW COLUMNS FROM `{$table}` LIKE 'workflow_info'")) {
54 - // Schema migration: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize DDL.
55 - $wpdb->query(
56 - "ALTER TABLE `{$table}`
57 - ADD COLUMN `workflow_info` LONGTEXT NULL AFTER `workflow_condition`"
58 - );
59 - }
60 - }
61 -
62 - /**
63 - * Idempotently add the workflows `workflow_category` column (conditional-logic classic/basic split).
64 - *
65 - * @return void
66 - */
67 - public static function ensureWorkflowCategoryColumn()
68 - {
69 - self::ensureWorkflowInfoColumn();
70 - global $wpdb;
71 - $table = $wpdb->prefix . 'bitforms_workflows';
72 - if (null === $wpdb->get_var("SHOW COLUMNS FROM `{$table}` LIKE 'workflow_category'")) {
73 - // Schema migration: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize DDL.
74 - $wpdb->query(
75 - "ALTER TABLE `{$table}`
76 - ADD COLUMN `workflow_category` VARCHAR(20) DEFAULT 'classic' AFTER `workflow_info`,
77 - ADD KEY `workflow_category` (`workflow_category`)"
78 - );
79 - }
80 - }
81 -
82 22 public static function migrate()
83 23 {
84 24 global $wpdb;
85 25 global $bitforms_db_version;
@@ -137,12 +77,9 @@
137 77 `workflow_type` varchar(50) NOT NULL,
138 78 `workflow_run` varchar(50) NOT NULL,
139 79 `workflow_behaviour` varchar(25) NOT NULL,
140 80 `workflow_condition` longtext DEFAULT NULL,
141 - `workflow_info` longtext DEFAULT NULL,
142 - `workflow_category` varchar(20) DEFAULT 'classic',/* classic = legacy, basic = field show/hide, advanced = multi-condition routing */
143 81 `workflow_order` int(11) unsigned DEFAULT NULL,
144 - `workflow_status` tinyint(1) DEFAULT 1,/* 0 disable, 1 enable, 2 enable in field settings */
145 82 `form_id` bigint(20) unsigned DEFAULT NULL,
146 83 `user_id` bigint(20) unsigned DEFAULT NULL,
147 84 `user_ip` int(11) unsigned DEFAULT NULL,
148 85 `user_location` text DEFAULT NULL,
@@ -149,10 +86,9 @@
149 86 `user_device` varchar(50) DEFAULT NULL,
150 87 `created_at` datetime DEFAULT NULL,
151 88 `updated_at` datetime DEFAULT NULL,
152 89 PRIMARY KEY (`id`),
153 - KEY `form_id` (`form_id`),
154 - KEY `workflow_category` (`workflow_category`)
90 + KEY `form_id` (`form_id`)
155 91 ) $collate;",
156 92
157 93 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_success_messages` (
158 94 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
@@ -171,10 +107,8 @@
171 107 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
172 108 `title` text DEFAULT NULL,
173 109 `sub` text DEFAULT NULL,
174 110 `body` longtext DEFAULT NULL,
175 - `status` tinyint(1) DEFAULT 1,/* 0 disabled, 1 enabled */
176 - `config` longtext DEFAULT NULL,/* SendTo / From / From Name / CC / BCC / Reply-To / attachments JSON */
177 111 `form_id` bigint(20) unsigned DEFAULT NULL,
178 112 `user_id` bigint(20) unsigned DEFAULT NULL,
179 113 `user_ip` int(11) unsigned DEFAULT NULL,
180 114 `created_at` datetime DEFAULT NULL,
@@ -265,98 +199,62 @@
265 199 KEY `entry_id` (`entry_id`)
266 200 ) $collate;"
267 201 ];
268 202
269 - try {
270 - include_once ABSPATH . 'wp-admin/includes/upgrade.php';
271 - foreach ($table_schema as $table) {
272 - dbDelta($table);
273 - }
274 - $installed_db_version = get_option('bitforms_db_version');
275 - if ($installed_db_version && version_compare('1.1', $installed_db_version, '>=')) {
276 - // if new db version is equal or higher than 1.1
277 - // Schema migration: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize DDL statements.
278 - try {
279 - $wpdb->query("ALTER TABLE `{$wpdb->prefix}bitforms_form_entry_log`
280 - MODIFY `log_type` VARCHAR(50) NULL DEFAULT NULL,
281 - MODIFY `created_at` DATETIME NOT NULL,
203 + $table_schema_update = [
204 + "ALTER TABLE `{$wpdb->prefix}bitforms_form_entry_log`
205 + CHANGE COLUMN `log_type` `log_type` VARCHAR(50) NULL DEFAULT NULL,
206 + ADD COLUMN `action_type` VARCHAR(50) NULL DEFAULT NULL,
282 207 CHANGE COLUMN `meta_key` `content` LONGTEXT NULL,
283 - ADD COLUMN `action_type` VARCHAR(50) NULL DEFAULT NULL,
284 - ADD COLUMN `content` LONGTEXT NULL AFTER `action_type`");
285 - } catch (\Exception $e) {
286 - Log::debug_log("Update failed: {$e->getMessage()} in query: ALTER TABLE `{$wpdb->prefix}bitforms_form_entry_log`...");
287 - }
288 - try {
289 - $wpdb->query("ALTER TABLE `{$wpdb->prefix}bitforms_form_log_details`
290 - MODIFY `api_type` VARCHAR(255) NULL DEFAULT NULL,
291 - MODIFY `response_obj` LONGTEXT NULL,
292 - MODIFY `created_at` DATETIME NOT NULL");
293 - } catch (\Exception $e) {
294 - Log::debug_log("Update failed: {$e->getMessage()} in query: ALTER TABLE `{$wpdb->prefix}bitforms_form_log_details`...");
295 - }
296 - }
297 - if ($installed_db_version && version_compare('1.3', $installed_db_version, '>=')) {
298 - // if new db version is equal or higher than 1.3
299 - $wpdb->query("ALTER TABLE `{$wpdb->prefix}bitforms_form_entries` MODIFY `user_ip` VARCHAR(255) NULL DEFAULT NULL");
300 - }
208 + CHANGE COLUMN `created_at` `created_at` DATETIME NOT NULL",
209 + "ALTER TABLE `{$wpdb->prefix}bitforms_form_log_details`
210 + CHANGE COLUMN `api_type` `api_type` VARCHAR(255) NULL DEFAULT NULL,
211 + CHANGE COLUMN `response_obj` `response_obj` LONGTEXT NULL,
212 + CHANGE COLUMN `created_at` `created_at` DATETIME NOT NULL",
213 + ];
301 214
302 - if ($installed_db_version && version_compare('2.0', $installed_db_version, '>=')) {
303 - if (null === $wpdb->get_var("SHOW COLUMNS FROM `{$wpdb->prefix}bitforms_success_messages` LIKE 'message_config'")) {
304 - $wpdb->query(
305 - "ALTER TABLE `{$wpdb->prefix}bitforms_success_messages`
306 - ADD COLUMN `message_config` LONGTEXT NULL AFTER `message_content`"
307 - );
308 - }
309 - if (null === $wpdb->get_var("SHOW COLUMNS FROM `{$wpdb->prefix}bitforms_form` LIKE 'builder_helper_state'")) {
310 - $wpdb->query(
311 - "ALTER TABLE `{$wpdb->prefix}bitforms_form`
312 - ADD COLUMN `builder_helper_state` LONGTEXT NULL AFTER `form_content`,
313 - ADD COLUMN `atomic_class_map` LONGTEXT NULL AFTER `builder_helper_state`,
314 - ADD COLUMN `generated_script_page_ids` LONGTEXT NULL AFTER `atomic_class_map`"
315 - );
316 - }
317 - if (null === $wpdb->get_var("SHOW COLUMNS FROM `{$wpdb->prefix}bitforms_workflows` LIKE 'workflow_order'")) {
318 - $wpdb->query(
319 - "ALTER TABLE `{$wpdb->prefix}bitforms_workflows`
320 - ADD COLUMN `workflow_order` INT(11) DEFAULT NULL AFTER `workflow_condition`"
321 - );
322 - }
215 + include_once ABSPATH . 'wp-admin/includes/upgrade.php';
216 + foreach ($table_schema as $table) {
217 + dbDelta($table);
218 + }
219 + $installed_db_version = get_site_option('bitforms_db_version');
220 + if ($installed_db_version && version_compare('1.1', $installed_db_version, '>=')) {
221 + // if new db version is equal or higher than 1.1
222 + foreach ($table_schema_update as $table) {
223 + $wpdb->query($table);
323 224 }
225 + }
226 + if ($installed_db_version && version_compare('1.3', $installed_db_version, '>=')) {
227 + // if new db version is equal or higher than 1.3
228 + $wpdb->query("ALTER TABLE `{$wpdb->prefix}bitforms_form_entries` CHANGE `user_ip` `user_ip` VARCHAR(255) NULL DEFAULT NULL");
229 + }
324 230
325 - if ($installed_db_version && version_compare('2.2', $installed_db_version, '>=')) {
326 - if (null === $wpdb->get_var("SHOW COLUMNS FROM `{$wpdb->prefix}bitforms_form_entries` LIKE 'referer'")) {
327 - $wpdb->query(
328 - "ALTER TABLE `{$wpdb->prefix}bitforms_form_entries`
329 - ADD COLUMN `referer` TEXT NULL DEFAULT NULL"
330 - );
331 - }
332 - }
231 + if ($installed_db_version && version_compare('2.0', $installed_db_version, '>=')) {
232 + $wpdb->query(
233 + "ALTER TABLE `{$wpdb->prefix}bitforms_success_messages`
234 + ADD `message_config` LONGTEXT NULL AFTER `message_content`"
235 + );
236 + $wpdb->query(
237 + "ALTER TABLE `{$wpdb->prefix}bitforms_form`
238 + ADD `builder_helper_state` LONGTEXT NULL AFTER `form_content`,
239 + ADD `atomic_class_map` LONGTEXT NULL AFTER `builder_helper_state`,
240 + ADD `generated_script_page_ids` LONGTEXT NULL AFTER `atomic_class_map`"
241 + );
242 + $wpdb->query(
243 + "ALTER TABLE `{$wpdb->prefix}bitforms_workflows`
244 + ADD `workflow_order` INT(11) DEFAULT NULL AFTER `workflow_condition`"
245 + );
246 + }
333 247
334 - if ($installed_db_version && version_compare('2.4', $installed_db_version, '>=')) {
335 - if (null === $wpdb->get_var("SHOW COLUMNS FROM `{$wpdb->prefix}bitforms_workflows` LIKE 'workflow_status'")) {
336 - $wpdb->query(
337 - "ALTER TABLE `{$wpdb->prefix}bitforms_workflows`
338 - ADD COLUMN `workflow_status` TINYINT(1) DEFAULT 1 NOT NULL AFTER `workflow_order`"
339 - );
340 - }
341 - }
248 + if ($installed_db_version && version_compare('2.2', $installed_db_version, '>=')) {
249 + $wpdb->query(
250 + "ALTER TABLE `{$wpdb->prefix}bitforms_form_entries`
251 + MODIFY `referer` TEXT DEFAULT NULL"
252 + );
253 + }
342 254
343 - // add workflow_info column if not exists
344 - if ($installed_db_version && version_compare('3.0', $installed_db_version, '>=')) {
345 - self::ensureWorkflowInfoColumn();
346 - }
347 -
348 - // add workflow_category column if not exists (conditional logic separation)
349 - // existing rows default to 'classic' so Free keeps executing them unchanged; data normalization in Fallback WorkFlow@normalizeCategory
350 - if ($installed_db_version && version_compare('3.2', $installed_db_version, '>=')) {
351 - self::ensureWorkflowCategoryColumn();
352 - // email template enable/disable + per-template config (SendTo/From/CC/BCC/Reply-To/attachments)
353 - self::ensureEmailTemplateStatusColumn();
354 - }
355 -
356 - update_option('bitforms_db_version', $bitforms_db_version, true);
357 - } catch (\Exception $e) {
358 - // Log the error to a file or the database
359 - Log::debug_log('Error during DB migration: ' . $e->getMessage());
360 - }
255 + update_site_option(
256 + 'bitforms_db_version',
257 + $bitforms_db_version
258 + );
361 259 }
362 260 }