PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.5.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.5.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.5.2, at includes/Core/Database/DB.php

229 lines 10.0 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 $max_index_length = 191;
39
40 $table_schema = array(
41 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_reports` (
42 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
43 `category` varchar(50) NOT NULL,
44 `type` varchar(20) NOT NULL,
45 `context` varchar(20) NOT NULL,
46 `details` longtext DEFAULT NULL,
47 `isDefault` tinyint(1) DEFAULT 0,/* 0 not default, 1 default */
48 `user_id` bigint(20) unsigned DEFAULT NULL,
49 `user_ip` int(11) unsigned DEFAULT NULL,
50 `user_device` varchar(50) DEFAULT NULL,
51 `created_at` datetime DEFAULT NULL,
52 `updated_at` datetime DEFAULT NULL,
53 PRIMARY KEY (`id`)
54 ) $collate;",
55
56 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form` (
57 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
58 `form_name` varchar(255) DEFAULT NULL,
59 `form_content` longtext DEFAULT NULL,
60 `user_id` bigint(20) unsigned DEFAULT NULL,
61 `user_ip` int(11) unsigned DEFAULT NULL,
62 `views` int(11) unsigned DEFAULT 0,
63 `entries` int(11) unsigned DEFAULT 0,
64 `user_device` varchar(50) DEFAULT NULL,
65 `status` tinyint(1) DEFAULT 1,/* 0 not published, 1 published, 2 trashed */
66 `created_at` datetime DEFAULT NULL,
67 `updated_at` datetime DEFAULT NULL,
68 PRIMARY KEY (`id`)
69 ) $collate;",
70
71 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_workflows` (
72 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
73 `workflow_name` varchar(255) NOT NULL,
74 `workflow_type` varchar(50) NOT NULL,
75 `workflow_run` varchar(50) NOT NULL,
76 `workflow_behaviour` varchar(25) NOT NULL,
77 `workflow_condition` longtext DEFAULT NULL,
78 `workflow_action` longtext DEFAULT NULL,
79 `form_id` bigint(20) unsigned DEFAULT NULL,
80 `user_id` bigint(20) unsigned DEFAULT NULL,
81 `user_ip` int(11) unsigned DEFAULT NULL,
82 `user_location` text DEFAULT NULL,
83 `user_device` varchar(50) DEFAULT NULL,
84 `created_at` datetime DEFAULT NULL,
85 `updated_at` datetime DEFAULT NULL,
86 PRIMARY KEY (`id`),
87 KEY `form_id` (`form_id`)
88 ) $collate;",
89
90 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_success_messages` (
91 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
92 `message_title` varchar(255) DEFAULT NULL,
93 `message_content` longtext DEFAULT NULL,
94 `form_id` bigint(20) unsigned DEFAULT NULL,
95 `user_id` bigint(20) unsigned DEFAULT NULL,
96 `user_ip` int(11) unsigned DEFAULT NULL,
97 `created_at` datetime DEFAULT NULL,
98 `updated_at` datetime DEFAULT NULL,
99 PRIMARY KEY (`id`)
100 ) $collate;",
101
102 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_email_template` (
103 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
104 `title` text DEFAULT NULL,
105 `sub` text DEFAULT NULL,
106 `body` longtext DEFAULT NULL,
107 `form_id` bigint(20) unsigned DEFAULT NULL,
108 `user_id` bigint(20) unsigned DEFAULT NULL,
109 `user_ip` int(11) unsigned DEFAULT NULL,
110 `created_at` datetime DEFAULT NULL,
111 `updated_at` datetime DEFAULT NULL,
112 PRIMARY KEY (`id`)
113 ) $collate;",
114
115 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_integration` (
116 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
117 `category` varchar(50) NOT NULL,
118 `integration_name` varchar(255) DEFAULT NULL,
119 `integration_type` varchar(50) NOT NULL,
120 `integration_details` longtext DEFAULT NULL,
121 `form_id` bigint(20) unsigned DEFAULT NULL, /* form_id = 0 means all/app */
122 `user_id` bigint(20) unsigned DEFAULT NULL,
123 `user_ip` int(11) unsigned DEFAULT NULL,
124 `status` tinyint(1) DEFAULT 1,/* 0 disabled, 1 published, 2 trashed */
125 `created_at` datetime DEFAULT NULL,
126 `updated_at` datetime DEFAULT NULL,
127 PRIMARY KEY (`id`)
128 ) $collate;",
129
130 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form_entries` (
131 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
132 `form_id` bigint(20) unsigned DEFAULT NULL,
133 `user_id` bigint(20) unsigned DEFAULT NULL,
134 `user_ip` int(11) unsigned DEFAULT NULL,
135 `user_location` text DEFAULT NULL,
136 `user_device` varchar(50) DEFAULT NULL,
137 `referer` varchar(255) DEFAULT NULL,
138 `status` tinyint(1) DEFAULT 0,/* 0 not viewed, 1 viewed, 2 trashed */
139 `created_at` datetime DEFAULT NULL,
140 `updated_at` datetime DEFAULT NULL,
141 PRIMARY KEY (`id`),
142 KEY `form_id` (`form_id`)
143 ) $collate;",
144
145 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form_entrymeta` (
146 `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
147 `bitforms_form_entry_id` bigint(20) unsigned DEFAULT NULL,
148 `meta_key` varchar(255) DEFAULT NULL,
149 `meta_value` longtext,
150 PRIMARY KEY (`meta_id`),
151 KEY `meta_key` (`meta_key`({$max_index_length})),
152 KEY `entry_id` (`bitforms_form_entry_id`)
153 ) $collate;",
154
155 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form_entry_log` (
156 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
157 `user_id` int(11) NOT NULL,
158 `log_type` varchar(50) DEFAULT NULL,
159 `ip` int(11) DEFAULT NULL,
160 `action_type` varchar(50) DEFAULT NULL,
161 `form_entry_id` bigint(20) DEFAULT NULL,
162 `form_id` bigint(20) DEFAULT NULL,
163 `content` longtext,
164 `created_at` DATETIME NOT NULL,
165 PRIMARY KEY (`id`),
166 KEY `form_id` (`form_id`),
167 KEY `form_entry_id` (`form_entry_id`)
168 ) $collate;",
169
170 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form_log_details` (
171 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
172 `log_id` bigint(20) NOT NULL,
173 `integration_id` bigint(20) DEFAULT NULL,
174 `api_type` varchar(255) DEFAULT NULL,
175 `response_type` varchar(50) DEFAULT NULL,
176 `response_obj` LONGTEXT DEFAULT NULL,
177 `created_at` DATETIME NOT NULL,
178 PRIMARY KEY (`id`),
179 KEY `log_id` (`log_id`),
180 KEY `integration_id` (`integration_id`)
181 ) $collate;",
182 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}bitforms_form_entry_relatedinfo` (
183 `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
184 `info_type` VARCHAR(50) NOT NULL,
185 `info_details` LONGTEXT NULL,
186 `form_id` BIGINT(20) UNSIGNED NOT NULL,
187 `entry_id` BIGINT(20) UNSIGNED NOT NULL,
188 `user_id` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
189 `user_ip` INT(11) UNSIGNED NULL DEFAULT NULL,
190 `status` INT(1) UNSIGNED NOT NULL DEFAULT '1',
191 `created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
192 `updated_at` DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
193 PRIMARY KEY (`id`),
194 KEY `form_id` (`form_id`),
195 KEY `entry_id` (`entry_id`)
196 ) $collate;"
197 );
198
199 $table_schema_update = array(
200 "ALTER TABLE `{$wpdb->prefix}bitforms_form_entry_log`
201 CHANGE COLUMN `log_type` `log_type` VARCHAR(50) NULL DEFAULT NULL,
202 ADD COLUMN `action_type` VARCHAR(50) NULL DEFAULT NULL,
203 CHANGE COLUMN `meta_key` `content` LONGTEXT NULL,
204 CHANGE COLUMN `created_at` `created_at` DATETIME NOT NULL",
205 "ALTER TABLE `{$wpdb->prefix}bitforms_form_log_details`
206 CHANGE COLUMN `api_type` `api_type` VARCHAR(255) NULL DEFAULT NULL,
207 CHANGE COLUMN `response_obj` `response_obj` LONGTEXT NULL,
208 CHANGE COLUMN `created_at` `created_at` DATETIME NOT NULL",
209 "ALTER TABLE `{$wpdb->prefix}bitforms_form_entries` CHANGE `user_ip` `user_ip` VARCHAR(255) NULL DEFAULT NULL",
210 );
211
212 include_once ABSPATH . 'wp-admin/includes/upgrade.php';
213 foreach ($table_schema as $table) {
214 dbDelta($table);
215 }
216 $installed_db_version = get_site_option("bitforms_db_version");
217 if ($installed_db_version && version_compare('1.1', $installed_db_version, '<=')) {
218 // if new db version is equal or higher than 1.1
219 foreach ($table_schema_update as $table) {
220 $wpdb->query($table);
221 }
222 }
223 update_site_option(
224 'bitforms_db_version',
225 $bitforms_db_version
226 );
227 }
228 }
229