PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16.1.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16.1.2
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 +2 -175 6.266.16.1.2 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
@@ -71,10 +51,8 @@
71 51
72 52 if ( false === get_option( 'frm_first_activation' ) ) {
73 53 update_option( 'frm_first_activation', time(), false );
74 54 }
75 -
76 - $this->update_settings_for_new_install();
77 55 }
78 56 }//end if
79 57
80 58 do_action( 'frm_after_install' );
@@ -89,60 +67,10 @@
89 67 $frm_style->update( 'default' );
90 68 }
91 69 }
92 70
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 71 public function collation() {
143 72 global $wpdb;
144 -
145 73 if ( ! $wpdb->has_cap( 'collation' ) ) {
146 74 return '';
147 75 }
148 76
@@ -148,11 +76,8 @@
148 76
149 77 return $wpdb->get_charset_collate();
150 78 }
151 79
152 - /**
153 - * @return void
154 - */
155 80 private function create_tables() {
156 81 $charset_collate = $this->collation();
157 82 $sql = array();
158 83
@@ -244,10 +169,8 @@
244 169 /**
245 170 * These indexes help optimize database queries for entries.
246 171 *
247 172 * @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 173 *
251 174 * @return void
252 175 */
253 176 private function add_composite_indexes_for_entries() {
@@ -265,22 +188,8 @@
265 188
266 189 if ( ! self::index_exists( $table_name, $index_name ) ) {
267 190 $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" );
268 191 }
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 192 }
284 193
285 194 /**
286 195 * Check that an index exists in a database table before trying to add it (which results in an error).
@@ -288,9 +197,8 @@
288 197 * @since 6.6
289 198 *
290 199 * @param string $table_name
291 200 * @param string $index_name
292 - *
293 201 * @return bool
294 202 */
295 203 private static function index_exists( $table_name, $index_name ) {
296 204 global $wpdb;
@@ -306,14 +214,10 @@
306 214 );
307 215 return (bool) $row;
308 216 }
309 217
310 - /**
311 - * @return void
312 - */
313 218 private function maybe_create_contact_form() {
314 219 $form_exists = FrmForm::get_id_by_key( 'contact-form' );
315 -
316 220 if ( ! $form_exists ) {
317 221 $this->add_default_template();
318 222 }
319 223 }
@@ -321,10 +225,8 @@
321 225 /**
322 226 * Create the default contact form
323 227 *
324 228 * @since 3.06
325 - *
326 - * @return void
327 229 */
328 230 private function add_default_template() {
329 231 if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
330 232 // XML import is not enabled on your server.
@@ -342,16 +244,13 @@
342 244 }
343 245
344 246 /**
345 247 * @param int|string $old_db_version
346 - *
347 - * @return void
348 248 */
349 249 private function migrate_data( $old_db_version ) {
350 250 if ( ! $old_db_version ) {
351 251 $old_db_version = get_option( 'frm_db_version' );
352 252 }
353 -
354 253 if ( strpos( $old_db_version, '-' ) ) {
355 254 $last_upgrade = explode( '-', $old_db_version );
356 255 $old_db_version = (int) $last_upgrade[1];
357 256 }
@@ -360,10 +259,9 @@
360 259 // bail if we don't know the previous version
361 260 return;
362 261 }
363 262
364 - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 );
365 -
263 + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101 );
366 264 foreach ( $migrations as $migration ) {
367 265 if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
368 266 $function_name = 'migrate_to_' . $migration;
369 267 $this->$function_name();
@@ -396,9 +294,8 @@
396 294
397 295 // Delete roles.
398 296 $frm_roles = FrmAppHelper::frm_capabilities();
399 297 $roles = get_editable_roles();
400 -
401 298 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
402 299 foreach ( $roles as $role => $details ) {
403 300 $wp_roles->remove_cap( $role, $frm_role );
404 301 unset( $role, $details );
@@ -413,9 +310,8 @@
413 310 remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' );
414 311 remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' );
415 312
416 313 $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 314 foreach ( $post_ids as $post_id ) {
419 315 // Delete's each post.
420 316 wp_delete_post( $post_id, true );
421 317 }
@@ -434,31 +330,11 @@
434 330 return true;
435 331 }
436 332
437 333 /**
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 334 * Disables summary email for multisite (not the main site) if recipient setting isn't changed.
457 335 *
458 336 * @since 6.8
459 - *
460 - * @return void
461 337 */
462 338 private function migrate_to_101() {
463 339 if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) {
464 340 return;
@@ -464,9 +340,8 @@
464 340 return;
465 341 }
466 342
467 343 $frm_settings = FrmAppHelper::get_settings();
468 -
469 344 if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) {
470 345 // User changed it.
471 346 return;
472 347 }
@@ -478,10 +353,8 @@
478 353 /**
479 354 * Clear frmpro_css transient.
480 355 *
481 356 * @since 4.10.02
482 - *
483 - * @return void
484 357 */
485 358 private function migrate_to_98() {
486 359 delete_transient( 'frmpro_css' );
487 360 }
@@ -489,10 +362,8 @@
489 362 /**
490 363 * Move default_blank and clear_on_focus to placeholder.
491 364 *
492 365 * @since 4.0
493 - *
494 - * @return void
495 366 */
496 367 private function migrate_to_97() {
497 368 $this->migrate_to_placeholder( 'clear_on_focus' );
498 369 $this->migrate_to_placeholder( 'default_blank' );
@@ -501,12 +372,8 @@
501 372 /**
502 373 * Move clear_on_focus or default_blank to placeholder.
503 374 *
504 375 * @since 4.0
505 - *
506 - * @param string $type Field option key to migrate.
507 - *
508 - * @return void
509 376 */
510 377 private function migrate_to_placeholder( $type = 'clear_on_focus' ) {
511 378 $query = array(
512 379 'field_options like' => '"' . $type . '";s:1:"1";',
@@ -517,9 +384,8 @@
517 384 foreach ( $fields as $field ) {
518 385 FrmAppHelper::unserialize_or_decode( $field->field_options );
519 386 FrmAppHelper::unserialize_or_decode( $field->options );
520 387 $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type );
521 -
522 388 if ( empty( $update_values ) ) {
523 389 continue;
524 390 }
525 391
@@ -531,14 +397,11 @@
531 397 /**
532 398 * Delete unneeded default templates
533 399 *
534 400 * @since 3.06
535 - *
536 - * @return void
537 401 */
538 402 private function migrate_to_90() {
539 403 $form = FrmForm::getOne( 'contact' );
540 -
541 404 if ( $form && $form->default_template == 1 ) {
542 405 FrmForm::destroy( 'contact' );
543 406 }
544 407 }
@@ -546,16 +409,14 @@
546 409 /**
547 410 * Reverse migration 17 -- Divide by 9
548 411 *
549 412 * @since 3.0.05
550 - *
551 - * @return void
552 413 */
553 414 private function migrate_to_86() {
554 415
555 416 $fields = $this->get_fields_with_size();
556 417
557 - foreach ( $fields as $f ) {
418 + foreach ( (array) $fields as $f ) {
558 419 FrmAppHelper::unserialize_or_decode( $f->field_options );
559 420 $size = $f->field_options['size'];
560 421 $this->maybe_convert_migrated_size( $size );
561 422
@@ -569,9 +430,8 @@
569 430 }
570 431
571 432 // reverse the extra size changes in widgets
572 433 $widgets = get_option( 'widget_frm_show_form' );
573 -
574 434 if ( empty( $widgets ) ) {
575 435 return;
576 436 }
577 437
@@ -577,11 +437,8 @@
577 437
578 438 $this->revert_widget_field_size();
579 439 }
580 440
581 - /**
582 - * @return array
583 - */
584 441 private function get_fields_with_size() {
585 442 $field_types = array(
586 443 'textarea',
587 444 'text',
@@ -609,20 +466,16 @@
609 466 /**
610 467 * Reverse the extra size changes in widgets
611 468 *
612 469 * @since 3.0.05
613 - *
614 - * @return void
615 470 */
616 471 private function revert_widget_field_size() {
617 472 $widgets = get_option( 'widget_frm_show_form' );
618 -
619 473 if ( empty( $widgets ) ) {
620 474 return;
621 475 }
622 476
623 477 FrmAppHelper::unserialize_or_decode( $widgets );
624 -
625 478 foreach ( $widgets as $k => $widget ) {
626 479 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
627 480 continue;
628 481 }
@@ -635,22 +488,16 @@
635 488 /**
636 489 * Divide by 9 to reverse the multiplication
637 490 *
638 491 * @since 3.0.05
639 - *
640 - * @param string $size Size string to maybe convert, passed by reference.
641 - *
642 - * @return void
643 492 */
644 493 private function maybe_convert_migrated_size( &$size ) {
645 494 $has_px_size = ! empty( $size ) && strpos( $size, 'px' );
646 -
647 495 if ( ! $has_px_size ) {
648 496 return;
649 497 }
650 498
651 499 $int_size = str_replace( 'px', '', $size );
652 -
653 500 if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) {
654 501 return;
655 502 }
656 503
@@ -663,16 +510,13 @@
663 510 * Migrate old styling settings. If sites are using the old
664 511 * default 400px field width, switch it to 100%
665 512 *
666 513 * @since 2.0.4
667 - *
668 - * @return void
669 514 */
670 515 private function migrate_to_25() {
671 516 // get the style that was created with the style migration
672 517 $frm_style = new FrmStyle();
673 518 $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
674 -
675 519 if ( empty( $styles ) ) {
676 520 return;
677 521 }
678 522
@@ -690,15 +534,12 @@
690 534 * Check if the parent_form_id columns exists.
691 535 * If not, try and add it again
692 536 *
693 537 * @since 2.0.2
694 - *
695 - * @return void
696 538 */
697 539 private function migrate_to_23() {
698 540 global $wpdb;
699 541 $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
700 -
701 542 if ( empty( $exists ) ) {
702 543 $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
703 544 }
704 545 }
@@ -704,10 +545,8 @@
704 545 }
705 546
706 547 /**
707 548 * Change field size from character to pixel -- Multiply by 9
708 - *
709 - * @return void
710 549 */
711 550 private function migrate_to_17() {
712 551 $fields = $this->get_fields_with_size();
713 552
@@ -712,9 +551,8 @@
712 551 $fields = $this->get_fields_with_size();
713 552
714 553 foreach ( $fields as $f ) {
715 554 FrmAppHelper::unserialize_or_decode( $f->field_options );
716 -
717 555 if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
718 556 continue;
719 557 }
720 558
@@ -728,20 +566,16 @@
728 566 }
729 567
730 568 /**
731 569 * Change the characters in widgets to pixels
732 - *
733 - * @return void
734 570 */
735 571 private function adjust_widget_size() {
736 572 $widgets = get_option( 'widget_frm_show_form' );
737 -
738 573 if ( empty( $widgets ) ) {
739 574 return;
740 575 }
741 576
742 577 FrmAppHelper::unserialize_or_decode( $widgets );
743 -
744 578 foreach ( $widgets as $k => $widget ) {
745 579 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
746 580 continue;
747 581 }
@@ -749,13 +583,8 @@
749 583 }
750 584 update_option( 'widget_frm_show_form', $widgets );
751 585 }
752 586
753 - /**
754 - * @param string $size
755 - *
756 - * @return void
757 - */
758 587 private function convert_character_to_px( &$size ) {
759 588 $pixel_conversion = 9;
760 589
761 590 $size = round( $pixel_conversion * (int) $size );
@@ -829,12 +658,10 @@
829 658 unset( $sending, $img );
830 659
831 660 $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
832 661 $draft_link = FrmFormsHelper::get_draft_link();
833 -
834 662 foreach ( $forms as $form ) {
835 663 FrmAppHelper::unserialize_or_decode( $form->options );
836 -
837 664 if ( empty( $form->options['submit_html'] ) ) {
838 665 continue;
839 666 }
840 667