PluginProbe
Quill Forms | Conversational Multi Step Forms, Surveys & quizzes / trunk
Quill Forms | Conversational Multi Step Forms, Surveys & quizzes vtrunk
5.7.3 5.7.2 5.7.1 1.8.1 1.8.10 1.8.11 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 2.0.0 2.1.0 2.10.0 2.11.0 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 All 146 releases
quillforms / includes / class-install.php

class-install.php in Quill Forms | Conversational Multi Step Forms, Surveys & quizzes trunk, at includes/class-install.php

332 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Install: class Install
5 *
6 * @since 1.0.0
7 * @package QuillForms
8 */
9
10 namespace QuillForms;
11 use QuillForms\Site\License;
12
13 use QuillForms\Managers\Addons_Manager;
14
15 /**
16 * Class Install is responsible for main set up.
17 * create needed database tables.
18 * assign capabilities to user roles.
19 *
20 * @since 1.0.0
21 */
22 class Install {
23
24
25 /**
26 * Init
27 *
28 * @since 1.0.0
29 */
30 public static function init() {
31 add_action( 'init', array( __CLASS__, 'check_version' ), 5 );
32 }
33
34 /**
35 * Check Quill forms version and run the updater is required.
36 *
37 * This check is done on all requests and runs if the versions do not match.
38 */
39 public static function check_version() {
40 self::deactivate_old_entries_addon();
41 self::deactivate_old_thankyou_screen_addon();
42 if ( version_compare( get_option( 'quillforms_version' ), QUILLFORMS_VERSION, '<' ) ) {
43 self::install();
44 do_action( 'quillforms_updated' );
45 }
46 }
47
48 /**
49 * Install QuillForms
50 *
51 * @since 1.0.0
52 * @static
53 */
54 public static function install() {
55 // Check if we are not already running this routine.
56 if ( 'yes' === get_transient( 'quillforms_installing' ) ) {
57 return;
58 }
59
60 // If we made it till here nothing is running yet, lets set the transient now.
61 set_transient( 'quillforms_installing', 'yes', MINUTE_IN_SECONDS * 10 );
62
63 Core::register_quillforms_post_type();
64 Capabilities::assign_capabilities_for_user_roles();
65 self::version_4_migration();
66 self::create_tables();
67 self::version_1_7_5_migration();
68 self::version_3_5_7_migration();
69 self::create_cron_jobs();
70 self::update_quillforms_version();
71
72 delete_transient( 'quillforms_installing' );
73 }
74
75 /**
76 * Create DB Tables
77 *
78 * @since 1.0.0
79 */
80 public static function create_tables() {
81 global $wpdb;
82
83 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
84
85 $charset_collate = $wpdb->get_charset_collate();
86
87 $sql = "CREATE TABLE {$wpdb->prefix}quillforms_themes (
88 ID mediumint(8) unsigned NOT NULL auto_increment,
89 theme_properties longtext NOT NULL,
90 theme_title varchar(50) NOT NULL,
91 theme_author bigint(20) unsigned NOT NULL default '0',
92 date_created datetime NOT NULL,
93 date_updated datetime,
94 PRIMARY KEY (ID)
95 ) $charset_collate;
96 CREATE TABLE {$wpdb->prefix}quillforms_task_meta (
97 ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
98 action_id BIGINT UNSIGNED,
99 hook varchar(255) NOT NULL,
100 group_slug varchar(255) NOT NULL,
101 value longtext NOT NULL,
102 date_created datetime NOT NULL,
103 PRIMARY KEY (ID),
104 KEY action_id (action_id)
105 ) $charset_collate;
106 CREATE TABLE {$wpdb->prefix}quillforms_entries (
107 ID bigint(20) unsigned NOT NULL auto_increment,
108 form_id bigint(20) unsigned NOT NULL,
109 is_starred tinyint(1) DEFAULT 0,
110 is_read tinyint(1) DEFAULT 0,
111 status varchar(50) DEFAULT 'completed',
112 hash_id varchar(255) DEFAULT NULL,
113 date_created datetime NOT NULL,
114 date_updated datetime NOT NULL,
115 PRIMARY KEY (ID),
116 KEY form_id (form_id)
117 ) $charset_collate;
118 CREATE TABLE {$wpdb->prefix}quillforms_entry_records (
119 ID bigint(20) unsigned NOT NULL auto_increment,
120 form_id bigint(20) unsigned NOT NULL,
121 entry_id bigint(20) unsigned NOT NULL,
122 record_type varchar(50) NOT NULL,
123 record_id varchar(50) NOT NULL,
124 record_value longtext NOT NULL,
125 PRIMARY KEY (ID),
126 KEY entry_id (entry_id)
127 ) $charset_collate;
128 CREATE TABLE {$wpdb->prefix}quillforms_entry_meta (
129 ID bigint(20) unsigned NOT NULL auto_increment,
130 form_id bigint(20) unsigned,
131 entry_id bigint(20) unsigned NOT NULL,
132 meta_key varchar(50) NOT NULL,
133 meta_value longtext NOT NULL,
134 PRIMARY KEY (ID),
135 KEY entry_id (entry_id),
136 KEY meta_key (meta_key)
137 ) $charset_collate;
138 CREATE TABLE {$wpdb->prefix}quillforms_pending_submissions (
139 ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
140 form_id BIGINT UNSIGNED,
141 step varchar(255) NOT NULL,
142 entry longtext NOT NULL,
143 form_data longtext NOT NULL,
144 date_created datetime NOT NULL,
145 hash_id varchar(50) DEFAULT NULL,
146 PRIMARY KEY (ID),
147 KEY form_id (form_id)
148 ) $charset_collate;
149 CREATE TABLE {$wpdb->prefix}quillforms_log (
150 log_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
151 timestamp datetime NOT NULL,
152 level smallint(4) NOT NULL,
153 source varchar(200) NOT NULL,
154 message longtext NOT NULL,
155 context longtext NULL,
156 PRIMARY KEY (log_id),
157 KEY level (level)
158 ) $charset_collate;";
159
160 dbDelta( $sql );
161 }
162
163 /**
164 * Version 1.7.5 migration
165 * - Fix charset collate for v1.7.4 and below
166 *
167 * @since 1.7.5
168 *
169 * @return void
170 */
171 private static function version_1_7_5_migration() {
172 global $wpdb;
173
174 $version = get_option( 'quillforms_version' );
175 // skip new installations.
176 if ( ! $version ) {
177 return;
178 }
179
180 // fix charset collate.
181 if ( version_compare( $version, '1.7.5', '<' ) ) {
182 $charset_collate = '';
183 if ( ! empty( $wpdb->charset ) ) {
184 $charset_collate = "character set $wpdb->charset";
185 }
186 if ( ! empty( $wpdb->collate ) ) {
187 $charset_collate .= " collate $wpdb->collate";
188 }
189
190 if ( $charset_collate ) {
191 $wpdb->query("alter table {$wpdb->prefix}quillforms_themes convert to $charset_collate;"); // phpcs:ignore
192 $wpdb->query("alter table {$wpdb->prefix}quillforms_task_meta convert to $charset_collate;"); // phpcs:ignore
193 }
194 }
195 }
196
197 /**
198 * Version 3.5.7 migration
199 * Add new columns 'hash_id' and 'token' to quillforms_pending_submissions table (both can be null)
200 *
201 * @since 3.5.7
202 */
203 public static function version_3_5_7_migration() {
204 global $wpdb;
205 $version = get_option( 'quillforms_version' );
206 if ( version_compare( $version, '3.5.7', '<' ) ) {
207 $sql = "ALTER TABLE {$wpdb->prefix}quillforms_pending_submissions
208 ADD hash_id varchar(50) DEFAULT NULL";
209 dbDelta( $sql );
210 }
211 }
212
213 /**
214 * Version next.version migration
215 * - Add status and hash_id columns to entries table.
216 *
217 * @since next.version
218 *
219 * @return void
220 */
221 private static function version_4_migration() {
222 global $wpdb;
223 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Intentional logging for migration tracking.
224 error_log( 'version_4_migration' );
225 $version = get_option( 'quillforms_version' );
226 if ( ! $version ) {
227 return;
228 }
229
230 // deactivate old entries add-on.
231 self::deactivate_old_entries_addon();
232
233 if ( version_compare( $version, '4.0.0', '<' ) ) {
234 $entries_table = $wpdb->prefix . 'quillforms_entries';
235 if ( $wpdb->get_var( "SHOW TABLES LIKE '$entries_table'" ) !== $entries_table ) {
236 return;
237 }
238
239 $wpdb->query( "ALTER TABLE {$wpdb->prefix}quillforms_entries ADD COLUMN `status` VARCHAR(50) DEFAULT 'completed' AFTER `is_read`;" );
240 $wpdb->query( "ALTER TABLE {$wpdb->prefix}quillforms_entries ADD COLUMN `hash_id` VARCHAR(255) DEFAULT NULL AFTER `status`;" );
241 }
242 }
243
244 /**
245 * Deactivate old entries add-on
246 *
247 * @since next.version
248 *
249 * @return void
250 */
251 private static function deactivate_old_entries_addon() {
252 if ( ! function_exists( 'is_plugin_active' ) || ! function_exists( 'deactivate_plugins' ) ) {
253 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
254 }
255
256 $plugin_path = 'quillforms-entries/quillforms-entries.php';
257 if ( is_plugin_active( $plugin_path ) ) {
258 deactivate_plugins( $plugin_path );
259 }
260 }
261
262 private static function deactivate_old_thankyou_screen_addon() {
263 if ( ! function_exists( 'is_plugin_active' ) || ! function_exists( 'deactivate_plugins' ) ) {
264 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
265 }
266 $plugin_path = 'quillforms-customthankyouscreenblock/quillforms-customthankyouscreenblock.php';
267 if ( is_plugin_active( $plugin_path ) ) {
268 deactivate_plugins( $plugin_path );
269 }
270 }
271
272 private static function deactivate_funnelkit_addon() {
273 if ( ! function_exists( 'is_plugin_active' ) || ! function_exists( 'deactivate_plugins' ) ) {
274 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
275 }
276 $plugin_path = 'quillforms-funnelkit/quillforms-funnelkit.php';
277 if ( is_plugin_active( $plugin_path ) ) {
278 deactivate_plugins( $plugin_path );
279 }
280 }
281
282 // /**
283 // * Version 2.13.4 migration
284 // *
285 // * @since version 2.13.4
286 // *
287 // * Add branded "powered by"
288 // */
289 // public static function version_2_13_4_migration() {
290 // if (version_compare($version, '3.0.2', '<')) {
291 // $license = License::instance()->get_license_info();
292 // if( !isset($license) || empty($license) || $license['status'] !== 'valid') return;
293 // $forms = get_posts( array(
294 // 'post_type' => 'quill_forms',
295 // 'posts_per_page' => -1,
296 // ) );
297 // for all forms add a setting in the form settings to enable the branded powered by if the form is free
298 // if( !empty($forms)) {
299 // foreach ( $forms as $form ) {
300 // $settings = get_post_meta( $form->ID, 'settings', true );
301 // if ( !isset($settings) || empty($settings) ) {
302 // $settings = array();
303 // }
304 // if ( ! isset( $settings['displayBranding'] ) ) {
305 // $settings['displayBranding'] = false;
306 // update_post_meta( $form->ID, 'settings', $settings );
307 // }
308 // }
309 // }
310 // }
311 // }
312
313 /**
314 * Create cron jobs (clear them first).
315 */
316 private static function create_cron_jobs() {
317 wp_clear_scheduled_hook( 'quillforms_cleanup_logs' );
318
319 wp_schedule_event( time() + ( 3 * HOUR_IN_SECONDS ), 'daily', 'quillforms_cleanup_logs' );
320 }
321
322 /**
323 * Update QuillForms version to current.
324 *
325 * @since 1.0.0
326 */
327 private static function update_quillforms_version() {
328 delete_option( 'quillforms_version' );
329 add_option( 'quillforms_version', QUILLFORMS_VERSION );
330 }
331 }
332