PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmMigrate.php +3 -180 6.266.13 View file →
@@ -3,27 +3,11 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmMigrate {
7 -
8 - /**
9 - * @var string
10 - */
11 7 public $fields;
12 -
13 - /**
14 - * @var string
15 - */
16 8 public $forms;
17 -
18 - /**
19 - * @var string
20 - */
21 9 public $entries;
22 -
23 - /**
24 - * @var string
25 - */
26 10 public $entry_metas;
27 11
28 12 public function __construct() {
29 13 global $wpdb;
@@ -32,11 +16,8 @@
32 16 $this->entries = $wpdb->prefix . 'frm_items';
33 17 $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
34 18 }
35 19
36 - /**
37 - * @return void
38 - */
39 20 public function upgrade() {
40 21 do_action( 'frm_before_install' );
41 22
42 23 global $wpdb, $frm_vars;
@@ -60,9 +41,8 @@
60 41 $old_db_version = get_option( 'frm_db_version' );
61 42
62 43 $this->create_tables();
63 44 $this->migrate_data( $old_db_version );
64 - $this->check_that_tables_exist();
65 45
66 46 // SAVE DB VERSION.
67 47 update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version );
68 48
@@ -67,16 +47,10 @@
67 47 update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version );
68 48
69 49 if ( ! $old_db_version ) {
70 50 $this->maybe_create_contact_form();
71 -
72 - if ( false === get_option( 'frm_first_activation' ) ) {
73 - update_option( 'frm_first_activation', time(), false );
74 - }
75 -
76 - $this->update_settings_for_new_install();
77 51 }
78 - }//end if
52 + }
79 53
80 54 do_action( 'frm_after_install' );
81 55
82 56 $frm_vars['doing_upgrade'] = false;
@@ -89,60 +63,10 @@
89 63 $frm_style->update( 'default' );
90 64 }
91 65 }
92 66
93 - /**
94 - * Updates some settings for new installs.
95 - *
96 - * @since 6.23
97 - *
98 - * @return void
99 - */
100 - private function update_settings_for_new_install() {
101 - $settings = FrmAppHelper::get_settings();
102 -
103 - $settings->denylist_check = 1;
104 - $settings->installed_after_welcome_tour_update = 1;
105 - $settings->store();
106 - }
107 -
108 - /**
109 - * If we fail to create the database tables, add an inbox notice.
110 - * This informs the user that they need to correct the issue and try again.
111 - *
112 - * @since 6.19
113 - *
114 - * @return void
115 - */
116 - private function check_that_tables_exist() {
117 - // Check the DB that the table $this->forms exists.
118 - global $wpdb;
119 - $exists = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', $this->forms ) );
120 -
121 - if ( $exists ) {
122 - $inbox = new FrmInbox();
123 - $inbox->dismiss( 'failed-to-create-tables' );
124 - return;
125 - }
126 -
127 - $message = array(
128 - 'key' => 'failed-to-create-tables',
129 - 'subject' => 'Something went wrong setting up the database',
130 - 'message' => 'For steps to continue, see our <a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">documentation</a>. If you need assistance, we recommend that you reach out to your hosting provider. Then <a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_add_tables=1' ) ) . '">click here</a> to try again.',
131 - 'cta' => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">Learn More</a>',
132 - 'type' => 'error',
133 - );
134 -
135 - $inbox = new FrmInbox();
136 - $inbox->add_message( $message );
137 - }
138 -
139 - /**
140 - * @return string
141 - */
142 67 public function collation() {
143 68 global $wpdb;
144 -
145 69 if ( ! $wpdb->has_cap( 'collation' ) ) {
146 70 return '';
147 71 }
148 72
@@ -148,11 +72,8 @@
148 72
149 73 return $wpdb->get_charset_collate();
150 74 }
151 75
152 - /**
153 - * @return void
154 - */
155 76 private function create_tables() {
156 77 $charset_collate = $this->collation();
157 78 $sql = array();
158 79
@@ -244,10 +165,8 @@
244 165 /**
245 166 * These indexes help optimize database queries for entries.
246 167 *
247 168 * @since 6.6
248 - * @since 6.16.3 idx_form_id_is_draft was also added to frm_items.
249 - * @since 6.17 idx_form_id_type was also added to frm_fields.
250 169 *
251 170 * @return void
252 171 */
253 172 private function add_composite_indexes_for_entries() {
@@ -265,22 +184,8 @@
265 184
266 185 if ( ! self::index_exists( $table_name, $index_name ) ) {
267 186 $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" );
268 187 }
269 -
270 - $table_name = "{$wpdb->prefix}frm_items";
271 - $index_name = 'idx_form_id_is_draft';
272 -
273 - if ( ! self::index_exists( $table_name, $index_name ) ) {
274 - $wpdb->query( "CREATE INDEX idx_form_id_is_draft ON `{$wpdb->prefix}frm_items` (form_id, is_draft)" );
275 - }
276 -
277 - $table_name = "{$wpdb->prefix}frm_fields";
278 - $index_name = 'idx_form_id_type';
279 -
280 - if ( ! self::index_exists( $table_name, $index_name ) ) {
281 - $wpdb->query( "CREATE INDEX idx_form_id_type ON `{$wpdb->prefix}frm_fields` (form_id, type(30))" );
282 - }
283 188 }
284 189
285 190 /**
286 191 * Check that an index exists in a database table before trying to add it (which results in an error).
@@ -288,9 +193,8 @@
288 193 * @since 6.6
289 194 *
290 195 * @param string $table_name
291 196 * @param string $index_name
292 - *
293 197 * @return bool
294 198 */
295 199 private static function index_exists( $table_name, $index_name ) {
296 200 global $wpdb;
@@ -306,14 +210,10 @@
306 210 );
307 211 return (bool) $row;
308 212 }
309 213
310 - /**
311 - * @return void
312 - */
313 214 private function maybe_create_contact_form() {
314 215 $form_exists = FrmForm::get_id_by_key( 'contact-form' );
315 -
316 216 if ( ! $form_exists ) {
317 217 $this->add_default_template();
318 218 }
319 219 }
@@ -321,10 +221,8 @@
321 221 /**
322 222 * Create the default contact form
323 223 *
324 224 * @since 3.06
325 - *
326 - * @return void
327 225 */
328 226 private function add_default_template() {
329 227 if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
330 228 // XML import is not enabled on your server.
@@ -342,16 +240,13 @@
342 240 }
343 241
344 242 /**
345 243 * @param int|string $old_db_version
346 - *
347 - * @return void
348 244 */
349 245 private function migrate_data( $old_db_version ) {
350 246 if ( ! $old_db_version ) {
351 247 $old_db_version = get_option( 'frm_db_version' );
352 248 }
353 -
354 249 if ( strpos( $old_db_version, '-' ) ) {
355 250 $last_upgrade = explode( '-', $old_db_version );
356 251 $old_db_version = (int) $last_upgrade[1];
357 252 }
@@ -360,10 +255,9 @@
360 255 // bail if we don't know the previous version
361 256 return;
362 257 }
363 258
364 - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 );
365 -
259 + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101 );
366 260 foreach ( $migrations as $migration ) {
367 261 if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
368 262 $function_name = 'migrate_to_' . $migration;
369 263 $this->$function_name();
@@ -396,9 +290,8 @@
396 290
397 291 // Delete roles.
398 292 $frm_roles = FrmAppHelper::frm_capabilities();
399 293 $roles = get_editable_roles();
400 -
401 294 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
402 295 foreach ( $roles as $role => $details ) {
403 296 $wp_roles->remove_cap( $role, $frm_role );
404 297 unset( $role, $details );
@@ -413,9 +306,8 @@
413 306 remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' );
414 307 remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' );
415 308
416 309 $post_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type in (%s, %s, %s)', FrmFormActionsController::$action_post_type, FrmStylesController::$post_type, 'frm_display' ) );
417 -
418 310 foreach ( $post_ids as $post_id ) {
419 311 // Delete's each post.
420 312 wp_delete_post( $post_id, true );
421 313 }
@@ -434,31 +326,11 @@
434 326 return true;
435 327 }
436 328
437 329 /**
438 - * In older versions of Lite, it's possible we've saved the wrong location ID.
439 - * So force it to get valid values again.
440 - *
441 - * @since 6.25
442 - *
443 - * @return void
444 - */
445 - private function migrate_to_104() {
446 - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'test' ) ) {
447 - FrmSquareLiteConnectHelper::get_location_id( true, 'test' );
448 - }
449 -
450 - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'live' ) ) {
451 - FrmSquareLiteConnectHelper::get_location_id( true, 'live' );
452 - }
453 - }
454 -
455 - /**
456 330 * Disables summary email for multisite (not the main site) if recipient setting isn't changed.
457 331 *
458 332 * @since 6.8
459 - *
460 - * @return void
461 333 */
462 334 private function migrate_to_101() {
463 335 if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) {
464 336 return;
@@ -464,9 +336,8 @@
464 336 return;
465 337 }
466 338
467 339 $frm_settings = FrmAppHelper::get_settings();
468 -
469 340 if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) {
470 341 // User changed it.
471 342 return;
472 343 }
@@ -478,10 +349,8 @@
478 349 /**
479 350 * Clear frmpro_css transient.
480 351 *
481 352 * @since 4.10.02
482 - *
483 - * @return void
484 353 */
485 354 private function migrate_to_98() {
486 355 delete_transient( 'frmpro_css' );
487 356 }
@@ -489,10 +358,8 @@
489 358 /**
490 359 * Move default_blank and clear_on_focus to placeholder.
491 360 *
492 361 * @since 4.0
493 - *
494 - * @return void
495 362 */
496 363 private function migrate_to_97() {
497 364 $this->migrate_to_placeholder( 'clear_on_focus' );
498 365 $this->migrate_to_placeholder( 'default_blank' );
@@ -501,12 +368,8 @@
501 368 /**
502 369 * Move clear_on_focus or default_blank to placeholder.
503 370 *
504 371 * @since 4.0
505 - *
506 - * @param string $type Field option key to migrate.
507 - *
508 - * @return void
509 372 */
510 373 private function migrate_to_placeholder( $type = 'clear_on_focus' ) {
511 374 $query = array(
512 375 'field_options like' => '"' . $type . '";s:1:"1";',
@@ -517,9 +380,8 @@
517 380 foreach ( $fields as $field ) {
518 381 FrmAppHelper::unserialize_or_decode( $field->field_options );
519 382 FrmAppHelper::unserialize_or_decode( $field->options );
520 383 $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type );
521 -
522 384 if ( empty( $update_values ) ) {
523 385 continue;
524 386 }
525 387
@@ -531,14 +393,11 @@
531 393 /**
532 394 * Delete unneeded default templates
533 395 *
534 396 * @since 3.06
535 - *
536 - * @return void
537 397 */
538 398 private function migrate_to_90() {
539 399 $form = FrmForm::getOne( 'contact' );
540 -
541 400 if ( $form && $form->default_template == 1 ) {
542 401 FrmForm::destroy( 'contact' );
543 402 }
544 403 }
@@ -546,16 +405,14 @@
546 405 /**
547 406 * Reverse migration 17 -- Divide by 9
548 407 *
549 408 * @since 3.0.05
550 - *
551 - * @return void
552 409 */
553 410 private function migrate_to_86() {
554 411
555 412 $fields = $this->get_fields_with_size();
556 413
557 - foreach ( $fields as $f ) {
414 + foreach ( (array) $fields as $f ) {
558 415 FrmAppHelper::unserialize_or_decode( $f->field_options );
559 416 $size = $f->field_options['size'];
560 417 $this->maybe_convert_migrated_size( $size );
561 418
@@ -569,9 +426,8 @@
569 426 }
570 427
571 428 // reverse the extra size changes in widgets
572 429 $widgets = get_option( 'widget_frm_show_form' );
573 -
574 430 if ( empty( $widgets ) ) {
575 431 return;
576 432 }
577 433
@@ -577,11 +433,8 @@
577 433
578 434 $this->revert_widget_field_size();
579 435 }
580 436
581 - /**
582 - * @return array
583 - */
584 437 private function get_fields_with_size() {
585 438 $field_types = array(
586 439 'textarea',
587 440 'text',
@@ -609,20 +462,16 @@
609 462 /**
610 463 * Reverse the extra size changes in widgets
611 464 *
612 465 * @since 3.0.05
613 - *
614 - * @return void
615 466 */
616 467 private function revert_widget_field_size() {
617 468 $widgets = get_option( 'widget_frm_show_form' );
618 -
619 469 if ( empty( $widgets ) ) {
620 470 return;
621 471 }
622 472
623 473 FrmAppHelper::unserialize_or_decode( $widgets );
624 -
625 474 foreach ( $widgets as $k => $widget ) {
626 475 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
627 476 continue;
628 477 }
@@ -635,22 +484,16 @@
635 484 /**
636 485 * Divide by 9 to reverse the multiplication
637 486 *
638 487 * @since 3.0.05
639 - *
640 - * @param string $size Size string to maybe convert, passed by reference.
641 - *
642 - * @return void
643 488 */
644 489 private function maybe_convert_migrated_size( &$size ) {
645 490 $has_px_size = ! empty( $size ) && strpos( $size, 'px' );
646 -
647 491 if ( ! $has_px_size ) {
648 492 return;
649 493 }
650 494
651 495 $int_size = str_replace( 'px', '', $size );
652 -
653 496 if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) {
654 497 return;
655 498 }
656 499
@@ -663,16 +506,13 @@
663 506 * Migrate old styling settings. If sites are using the old
664 507 * default 400px field width, switch it to 100%
665 508 *
666 509 * @since 2.0.4
667 - *
668 - * @return void
669 510 */
670 511 private function migrate_to_25() {
671 512 // get the style that was created with the style migration
672 513 $frm_style = new FrmStyle();
673 514 $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
674 -
675 515 if ( empty( $styles ) ) {
676 516 return;
677 517 }
678 518
@@ -690,15 +530,12 @@
690 530 * Check if the parent_form_id columns exists.
691 531 * If not, try and add it again
692 532 *
693 533 * @since 2.0.2
694 - *
695 - * @return void
696 534 */
697 535 private function migrate_to_23() {
698 536 global $wpdb;
699 537 $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
700 -
701 538 if ( empty( $exists ) ) {
702 539 $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
703 540 }
704 541 }
@@ -704,10 +541,8 @@
704 541 }
705 542
706 543 /**
707 544 * Change field size from character to pixel -- Multiply by 9
708 - *
709 - * @return void
710 545 */
711 546 private function migrate_to_17() {
712 547 $fields = $this->get_fields_with_size();
713 548
@@ -712,9 +547,8 @@
712 547 $fields = $this->get_fields_with_size();
713 548
714 549 foreach ( $fields as $f ) {
715 550 FrmAppHelper::unserialize_or_decode( $f->field_options );
716 -
717 551 if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
718 552 continue;
719 553 }
720 554
@@ -728,20 +562,16 @@
728 562 }
729 563
730 564 /**
731 565 * Change the characters in widgets to pixels
732 - *
733 - * @return void
734 566 */
735 567 private function adjust_widget_size() {
736 568 $widgets = get_option( 'widget_frm_show_form' );
737 -
738 569 if ( empty( $widgets ) ) {
739 570 return;
740 571 }
741 572
742 573 FrmAppHelper::unserialize_or_decode( $widgets );
743 -
744 574 foreach ( $widgets as $k => $widget ) {
745 575 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
746 576 continue;
747 577 }
@@ -749,13 +579,8 @@
749 579 }
750 580 update_option( 'widget_frm_show_form', $widgets );
751 581 }
752 582
753 - /**
754 - * @param string $size
755 - *
756 - * @return void
757 - */
758 583 private function convert_character_to_px( &$size ) {
759 584 $pixel_conversion = 9;
760 585
761 586 $size = round( $pixel_conversion * (int) $size );
@@ -829,12 +654,10 @@
829 654 unset( $sending, $img );
830 655
831 656 $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
832 657 $draft_link = FrmFormsHelper::get_draft_link();
833 -
834 658 foreach ( $forms as $form ) {
835 659 FrmAppHelper::unserialize_or_decode( $form->options );
836 -
837 660 if ( empty( $form->options['submit_html'] ) ) {
838 661 continue;
839 662 }
840 663