PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.2
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 2.10.2 All 137 releases
bit-form / includes / Core / Database / DB.php

DB.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.2, at includes/Core/Database/DB.php

226 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class For Database Migration
5 *
6 * @category Database
7 * @author BitCode Developer <developer@bitcode.pro>
8 */
9
10 namespace BitCode\BitForm\Core\Database;
11
12 /**
13 * Database Migration
14 */
15 final class DB
16 {
17 /**
18 * Undocumented function
19 *
20 * @return void
21 */
22 public static function migrate()
23 {
24 global $wpdb;
25 global $bitforms_db_version;
26 $collate = '';
27
28 if ($wpdb->has_cap('collation')) {
29 if (!empty($wpdb->charset)) {
30 $collate .= "DEFAULT CHARACTER SET $wpdb->charset";
31 }
32
33 if (!empty($wpdb->collate)) {
34 $collate .= " COLLATE $wpdb->collate";
35 }
36 }
37
38 $table_schema = array(
39 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_reports` (
40 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
41 `category` varchar(50) NOT NULL,
42 `type` varchar(20) NOT NULL,
43 `context` varchar(20) NOT NULL,
44 `details` longtext DEFAULT NULL,
45 `isDefault` tinyint(1) DEFAULT 0,/* 0 not default, 1 default */
46 `user_id` bigint(20) unsigned DEFAULT NULL,
47 `user_ip` int(11) unsigned DEFAULT NULL,
48 `user_device` varchar(50) DEFAULT NULL,
49 `created_at` datetime DEFAULT NULL,
50 `updated_at` datetime DEFAULT NULL,
51 PRIMARY KEY (`id`)
52 ) $collate;",
53
54 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form` (
55 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
56 `form_name` varchar(255) DEFAULT NULL,
57 `form_content` longtext DEFAULT NULL,
58 `user_id` bigint(20) unsigned DEFAULT NULL,
59 `user_ip` int(11) unsigned DEFAULT NULL,
60 `views` int(11) unsigned DEFAULT 0,
61 `entries` int(11) unsigned DEFAULT 0,
62 `user_device` varchar(50) DEFAULT NULL,
63 `status` tinyint(1) DEFAULT 1,/* 0 not published, 1 published, 2 trashed */
64 `created_at` datetime DEFAULT NULL,
65 `updated_at` datetime DEFAULT NULL,
66 PRIMARY KEY (`id`)
67 ) $collate;",
68
69 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_workflows` (
70 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
71 `workflow_name` varchar(255) NOT NULL,
72 `workflow_type` varchar(50) NOT NULL,
73 `workflow_run` varchar(50) NOT NULL,
74 `workflow_behaviour` varchar(25) NOT NULL,
75 `workflow_condition` longtext DEFAULT NULL,
76 `workflow_action` longtext DEFAULT NULL,
77 `form_id` bigint(20) unsigned DEFAULT NULL,
78 `user_id` bigint(20) unsigned DEFAULT NULL,
79 `user_ip` int(11) unsigned DEFAULT NULL,
80 `user_location` text DEFAULT NULL,
81 `user_device` varchar(50) DEFAULT NULL,
82 `created_at` datetime DEFAULT NULL,
83 `updated_at` datetime DEFAULT NULL,
84 PRIMARY KEY (`id`),
85 KEY `form_id` (`form_id`)
86 ) $collate;",
87
88 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_success_messages` (
89 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
90 `message_title` varchar(255) DEFAULT NULL,
91 `message_content` longtext DEFAULT NULL,
92 `form_id` bigint(20) unsigned DEFAULT NULL,
93 `user_id` bigint(20) unsigned DEFAULT NULL,
94 `user_ip` int(11) unsigned DEFAULT NULL,
95 `created_at` datetime DEFAULT NULL,
96 `updated_at` datetime DEFAULT NULL,
97 PRIMARY KEY (`id`)
98 ) $collate;",
99
100 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_email_template` (
101 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
102 `title` text DEFAULT NULL,
103 `sub` text DEFAULT NULL,
104 `body` longtext DEFAULT NULL,
105 `form_id` bigint(20) unsigned DEFAULT NULL,
106 `user_id` bigint(20) unsigned DEFAULT NULL,
107 `user_ip` int(11) unsigned DEFAULT NULL,
108 `created_at` datetime DEFAULT NULL,
109 `updated_at` datetime DEFAULT NULL,
110 PRIMARY KEY (`id`)
111 ) $collate;",
112
113 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_integration` (
114 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
115 `category` varchar(50) NOT NULL,
116 `integration_name` varchar(255) DEFAULT NULL,
117 `integration_type` varchar(50) NOT NULL,
118 `integration_details` longtext DEFAULT NULL,
119 `form_id` bigint(20) unsigned DEFAULT NULL, /* form_id = 0 means all/app */
120 `user_id` bigint(20) unsigned DEFAULT NULL,
121 `user_ip` int(11) unsigned DEFAULT NULL,
122 `status` tinyint(1) DEFAULT 1,/* 0 disabled, 1 published, 2 trashed */
123 `created_at` datetime DEFAULT NULL,
124 `updated_at` datetime DEFAULT NULL,
125 PRIMARY KEY (`id`)
126 ) $collate;",
127
128 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form_entries` (
129 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
130 `form_id` bigint(20) unsigned DEFAULT NULL,
131 `user_id` bigint(20) unsigned DEFAULT NULL,
132 `user_ip` int(11) unsigned DEFAULT NULL,
133 `user_location` text DEFAULT NULL,
134 `user_device` varchar(50) DEFAULT NULL,
135 `referer` varchar(255) DEFAULT NULL,
136 `status` tinyint(1) DEFAULT 0,/* 0 not viewed, 1 viewed, 2 trashed */
137 `created_at` datetime DEFAULT NULL,
138 `updated_at` datetime DEFAULT NULL,
139 PRIMARY KEY (`id`),
140 KEY `form_id` (`form_id`)
141 ) $collate;",
142
143 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form_entrymeta` (
144 `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
145 `bitforms_form_entry_id` bigint(20) unsigned DEFAULT NULL,
146 `meta_key` varchar(255) DEFAULT NULL,
147 `meta_value` longtext,
148 PRIMARY KEY (`meta_id`),
149 KEY `meta_key` (`meta_key`),
150 KEY `entry_id` (`bitforms_form_entry_id`)
151 ) $collate;",
152
153 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form_entry_log` (
154 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
155 `user_id` int(11) NOT NULL,
156 `log_type` varchar(50) DEFAULT NULL,
157 `ip` int(11) DEFAULT NULL,
158 `action_type` varchar(50) DEFAULT NULL,
159 `form_entry_id` bigint(20) DEFAULT NULL,
160 `form_id` bigint(20) DEFAULT NULL,
161 `content` longtext,
162 `created_at` DATETIME NOT NULL,
163 PRIMARY KEY (`id`),
164 KEY `form_id` (`form_id`),
165 KEY `form_entry_id` (`form_entry_id`)
166 ) $collate;",
167
168 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form_log_details` (
169 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
170 `log_id` bigint(20) NOT NULL,
171 `integration_id` bigint(20) DEFAULT NULL,
172 `api_type` varchar(255) DEFAULT NULL,
173 `response_type` varchar(50) DEFAULT NULL,
174 `response_obj` LONGTEXT DEFAULT NULL,
175 `created_at` DATETIME NOT NULL,
176 PRIMARY KEY (`id`),
177 KEY `log_id` (`log_id`),
178 KEY `integration_id` (`integration_id`)
179 ) $collate;",
180 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form_entry_relatedinfo` (
181 `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
182 `info_type` VARCHAR(50) NOT NULL,
183 `info_details` LONGTEXT NULL,
184 `form_id` BIGINT(20) UNSIGNED NOT NULL,
185 `entry_id` BIGINT(20) UNSIGNED NOT NULL,
186 `user_id` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
187 `user_ip` INT(11) UNSIGNED NULL DEFAULT NULL,
188 `status` INT(1) UNSIGNED NOT NULL DEFAULT '1',
189 `created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
190 `updated_at` DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
191 PRIMARY KEY (`id`),
192 KEY `form_id` (`form_id`),
193 KEY `entry_id` (`entry_id`)
194 ) $collate;"
195 );
196
197 $table_schema_update = array(
198 "ALTER TABLE `{$wpdb->prefix}bitforms_form_entry_log`
199 CHANGE COLUMN `log_type` `log_type` VARCHAR(50) NULL DEFAULT NULL,
200 ADD COLUMN `action_type` VARCHAR(50) NULL DEFAULT NULL,
201 CHANGE COLUMN `meta_key` `content` LONGTEXT NULL,
202 CHANGE COLUMN `created_at` `created_at` DATETIME NOT NULL",
203 "ALTER TABLE `{$wpdb->prefix}bitforms_form_log_details`
204 CHANGE COLUMN `api_type` `api_type` VARCHAR(255) NULL DEFAULT NULL,
205 CHANGE COLUMN `response_obj` `response_obj` LONGTEXT NULL,
206 CHANGE COLUMN `created_at` `created_at` DATETIME NOT NULL",
207 );
208
209 include_once ABSPATH . 'wp-admin/includes/upgrade.php';
210 foreach ($table_schema as $table) {
211 dbDelta($table);
212 }
213 $installed_db_version = get_site_option("bitforms_db_version");
214 if ($installed_db_version && version_compare('1.1', $installed_db_version, '<=')) {
215 // if new db version is equal or higher than 1.1
216 foreach ($table_schema_update as $table) {
217 $wpdb->query($table);
218 }
219 }
220 update_site_option(
221 'bitforms_db_version',
222 $bitforms_db_version
223 );
224 }
225 }
226