PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.25.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.25.1
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
formidable / classes / models / FrmMigrate.php

FrmMigrate.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.25.1, at classes/models/FrmMigrate.php

763 lines 22.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmMigrate {
7 public $fields;
8 public $forms;
9 public $entries;
10 public $entry_metas;
11
12 public function __construct() {
13 global $wpdb;
14 $this->fields = $wpdb->prefix . 'frm_fields';
15 $this->forms = $wpdb->prefix . 'frm_forms';
16 $this->entries = $wpdb->prefix . 'frm_items';
17 $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
18 }
19
20 public function upgrade() {
21 do_action( 'frm_before_install' );
22
23 global $wpdb, $frm_vars;
24
25 $frm_vars['doing_upgrade'] = true;
26
27 $needs_upgrade = FrmAppController::compare_for_update(
28 array(
29 'option' => 'frm_db_version',
30 'new_db_version' => FrmAppHelper::$db_version,
31 'new_plugin_version' => FrmAppHelper::plugin_version(),
32 )
33 );
34
35 if ( $needs_upgrade ) {
36 // update rewrite rules for views and other custom post types
37 flush_rewrite_rules();
38
39 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
40
41 $old_db_version = get_option( 'frm_db_version' );
42
43 $this->create_tables();
44 $this->migrate_data( $old_db_version );
45 $this->check_that_tables_exist();
46
47 // SAVE DB VERSION.
48 update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version );
49
50 if ( ! $old_db_version ) {
51 $this->maybe_create_contact_form();
52
53 if ( false === get_option( 'frm_first_activation' ) ) {
54 update_option( 'frm_first_activation', time(), false );
55 }
56
57 $this->update_settings_for_new_install();
58 }
59 }//end if
60
61 do_action( 'frm_after_install' );
62
63 $frm_vars['doing_upgrade'] = false;
64
65 FrmAppHelper::save_combined_js();
66
67 // update the styling settings
68 if ( function_exists( 'get_filesystem_method' ) ) {
69 $frm_style = new FrmStyle();
70 $frm_style->update( 'default' );
71 }
72 }
73
74 /**
75 * Updates some settings for new installs.
76 *
77 * @since 6.23
78 */
79 private function update_settings_for_new_install() {
80 $settings = FrmAppHelper::get_settings();
81
82 $settings->denylist_check = 1;
83 $settings->installed_after_welcome_tour_update = 1;
84 $settings->store();
85 }
86
87 /**
88 * If we fail to create the database tables, add an inbox notice.
89 * This informs the user that they need to correct the issue and try again.
90 *
91 * @since 6.19
92 *
93 * @return void
94 */
95 private function check_that_tables_exist() {
96 // Check the DB that the table $this->forms exists.
97 global $wpdb;
98 $exists = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', $this->forms ) );
99
100 if ( $exists ) {
101 $inbox = new FrmInbox();
102 $inbox->dismiss( 'failed-to-create-tables' );
103 return;
104 }
105
106 $message = array(
107 'key' => 'failed-to-create-tables',
108 'subject' => 'Something went wrong setting up the database',
109 '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.',
110 'cta' => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">Learn More</a>',
111 'type' => 'error',
112 );
113
114 $inbox = new FrmInbox();
115 $inbox->add_message( $message );
116 }
117
118 /**
119 * @return string
120 */
121 public function collation() {
122 global $wpdb;
123 if ( ! $wpdb->has_cap( 'collation' ) ) {
124 return '';
125 }
126
127 return $wpdb->get_charset_collate();
128 }
129
130 private function create_tables() {
131 $charset_collate = $this->collation();
132 $sql = array();
133
134 /* Create/Upgrade Fields Table */
135 $sql[] = 'CREATE TABLE ' . $this->fields . ' (
136 id BIGINT(20) NOT NULL auto_increment,
137 field_key varchar(100) default NULL,
138 name text default NULL,
139 description longtext default NULL,
140 type text default NULL,
141 default_value longtext default NULL,
142 options longtext default NULL,
143 field_order int(11) default 0,
144 required int(1) default NULL,
145 field_options longtext default NULL,
146 form_id int(11) default NULL,
147 created_at datetime NOT NULL,
148 PRIMARY KEY (id),
149 KEY form_id (form_id),
150 UNIQUE KEY field_key (field_key)
151 )';
152
153 /* Create/Upgrade Forms Table */
154 $sql[] = 'CREATE TABLE ' . $this->forms . ' (
155 id int(11) NOT NULL auto_increment,
156 form_key varchar(100) default NULL,
157 name varchar(255) default NULL,
158 description text default NULL,
159 parent_form_id int(11) default 0,
160 logged_in tinyint(1) default NULL,
161 editable tinyint(1) default NULL,
162 is_template tinyint(1) default 0,
163 default_template tinyint(1) default 0,
164 status varchar(255) default NULL,
165 options longtext default NULL,
166 created_at datetime NOT NULL,
167 PRIMARY KEY (id),
168 UNIQUE KEY form_key (form_key)
169 )';
170
171 /* Create/Upgrade Items Table */
172 $sql[] = 'CREATE TABLE ' . $this->entries . ' (
173 id BIGINT(20) NOT NULL auto_increment,
174 item_key varchar(100) default NULL,
175 name varchar(255) default NULL,
176 description text default NULL,
177 ip text default NULL,
178 form_id BIGINT(20) default NULL,
179 post_id BIGINT(20) default NULL,
180 user_id BIGINT(20) default NULL,
181 parent_item_id BIGINT(20) default 0,
182 is_draft tinyint(1) default 0,
183 updated_by BIGINT(20) default NULL,
184 created_at datetime NOT NULL,
185 updated_at datetime NOT NULL,
186 PRIMARY KEY (id),
187 KEY form_id (form_id),
188 KEY post_id (post_id),
189 KEY user_id (user_id),
190 KEY parent_item_id (parent_item_id),
191 UNIQUE KEY item_key (item_key)
192 )';
193
194 /* Create/Upgrade Meta Table */
195 $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
196 id BIGINT(20) NOT NULL auto_increment,
197 meta_value longtext default NULL,
198 field_id BIGINT(20) NOT NULL,
199 item_id BIGINT(20) NOT NULL,
200 created_at datetime NOT NULL,
201 PRIMARY KEY (id),
202 KEY field_id (field_id),
203 KEY item_id (item_id)
204 )';
205
206 foreach ( $sql as $q ) {
207 if ( function_exists( 'dbDelta' ) ) {
208 dbDelta( $q . $charset_collate . ';' );
209 } else {
210 global $wpdb;
211 $wpdb->query( $q . $charset_collate ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
212 }
213 unset( $q );
214 }
215
216 $this->add_composite_indexes_for_entries();
217 }
218
219 /**
220 * These indexes help optimize database queries for entries.
221 *
222 * @since 6.6
223 * @since 6.16.3 idx_form_id_is_draft was also added to frm_items.
224 * @since 6.17 idx_form_id_type was also added to frm_fields.
225 *
226 * @return void
227 */
228 private function add_composite_indexes_for_entries() {
229 global $wpdb;
230
231 $table_name = "{$wpdb->prefix}frm_items";
232 $index_name = 'idx_is_draft_created_at';
233
234 if ( ! self::index_exists( $table_name, $index_name ) ) {
235 $wpdb->query( "CREATE INDEX idx_is_draft_created_at ON `{$wpdb->prefix}frm_items` (is_draft, created_at)" );
236 }
237
238 $table_name = "{$wpdb->prefix}frm_item_metas";
239 $index_name = 'idx_field_id_item_id';
240
241 if ( ! self::index_exists( $table_name, $index_name ) ) {
242 $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" );
243 }
244
245 $table_name = "{$wpdb->prefix}frm_items";
246 $index_name = 'idx_form_id_is_draft';
247
248 if ( ! self::index_exists( $table_name, $index_name ) ) {
249 $wpdb->query( "CREATE INDEX idx_form_id_is_draft ON `{$wpdb->prefix}frm_items` (form_id, is_draft)" );
250 }
251
252 $table_name = "{$wpdb->prefix}frm_fields";
253 $index_name = 'idx_form_id_type';
254
255 if ( ! self::index_exists( $table_name, $index_name ) ) {
256 $wpdb->query( "CREATE INDEX idx_form_id_type ON `{$wpdb->prefix}frm_fields` (form_id, type(30))" );
257 }
258 }
259
260 /**
261 * Check that an index exists in a database table before trying to add it (which results in an error).
262 *
263 * @since 6.6
264 *
265 * @param string $table_name
266 * @param string $index_name
267 * @return bool
268 */
269 private static function index_exists( $table_name, $index_name ) {
270 global $wpdb;
271 $row = $wpdb->get_row(
272 $wpdb->prepare(
273 'SELECT 1 FROM information_schema.statistics
274 WHERE table_schema = database()
275 AND table_name = %s
276 AND index_name = %s
277 LIMIT 1',
278 array( $table_name, $index_name )
279 )
280 );
281 return (bool) $row;
282 }
283
284 private function maybe_create_contact_form() {
285 $form_exists = FrmForm::get_id_by_key( 'contact-form' );
286 if ( ! $form_exists ) {
287 $this->add_default_template();
288 }
289 }
290
291 /**
292 * Create the default contact form
293 *
294 * @since 3.06
295 */
296 private function add_default_template() {
297 if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
298 // XML import is not enabled on your server.
299 return;
300 }
301
302 $set_err = libxml_use_internal_errors( true );
303 $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
304
305 $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml';
306 FrmXMLHelper::import_xml( $file );
307
308 libxml_use_internal_errors( $set_err );
309 FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader );
310 }
311
312 /**
313 * @param int|string $old_db_version
314 */
315 private function migrate_data( $old_db_version ) {
316 if ( ! $old_db_version ) {
317 $old_db_version = get_option( 'frm_db_version' );
318 }
319 if ( strpos( $old_db_version, '-' ) ) {
320 $last_upgrade = explode( '-', $old_db_version );
321 $old_db_version = (int) $last_upgrade[1];
322 }
323
324 if ( ! is_numeric( $old_db_version ) ) {
325 // bail if we don't know the previous version
326 return;
327 }
328
329 $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 );
330 foreach ( $migrations as $migration ) {
331 if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
332 $function_name = 'migrate_to_' . $migration;
333 $this->$function_name();
334 }
335 }
336 }
337
338 public function uninstall() {
339 if ( ! current_user_can( 'administrator' ) ) {
340 $frm_settings = FrmAppHelper::get_settings();
341 wp_die( esc_html( $frm_settings->admin_permission ) );
342 }
343
344 global $wpdb, $wp_roles;
345
346 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
347 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
348 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
349 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
350
351 delete_option( 'frm_options' );
352 delete_option( 'frm_db_version' );
353 delete_option( 'frm_install_running' );
354 delete_option( 'frm_lite_settings_upgrade' );
355 delete_option( 'frm-usage-uuid' );
356 delete_option( 'frm_inbox' );
357 delete_option( 'frmpro_css' );
358 delete_option( FrmOnboardingWizardController::REDIRECT_STATUS_OPTION );
359 delete_option( FrmEmailSummaryHelper::$option_name );
360
361 // Delete roles.
362 $frm_roles = FrmAppHelper::frm_capabilities();
363 $roles = get_editable_roles();
364 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
365 foreach ( $roles as $role => $details ) {
366 $wp_roles->remove_cap( $role, $frm_role );
367 unset( $role, $details );
368 }
369 unset( $frm_role, $frm_role_description );
370 }
371 unset( $roles, $frm_roles );
372
373 // delete actions, views, and styles
374
375 // prevent the post deletion from triggering entries to be deleted
376 remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' );
377 remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' );
378
379 $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' ) );
380 foreach ( $post_ids as $post_id ) {
381 // Delete's each post.
382 wp_delete_post( $post_id, true );
383 }
384 unset( $post_ids );
385
386 // delete transients
387 delete_transient( 'frmpro_css' );
388 delete_transient( 'frm_options' );
389 delete_transient( 'frmpro_options' );
390 delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME );
391
392 $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) );
393
394 do_action( 'frm_after_uninstall' );
395
396 return true;
397 }
398
399 /**
400 * In older versions of Lite, it's possible we've saved the wrong location ID.
401 * So force it to get valid values again.
402 *
403 * @since 6.25
404 *
405 * @return void
406 */
407 private function migrate_to_104() {
408 if ( FrmSquareLiteConnectHelper::get_merchant_id( 'test' ) ) {
409 FrmSquareLiteConnectHelper::get_location_id( true, 'test' );
410 }
411
412 if ( FrmSquareLiteConnectHelper::get_merchant_id( 'live' ) ) {
413 FrmSquareLiteConnectHelper::get_location_id( true, 'live' );
414 }
415 }
416
417 /**
418 * Disables summary email for multisite (not the main site) if recipient setting isn't changed.
419 *
420 * @since 6.8
421 */
422 private function migrate_to_101() {
423 if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) {
424 return;
425 }
426
427 $frm_settings = FrmAppHelper::get_settings();
428 if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) {
429 // User changed it.
430 return;
431 }
432
433 $frm_settings->summary_emails = 0;
434 $frm_settings->store();
435 }
436
437 /**
438 * Clear frmpro_css transient.
439 *
440 * @since 4.10.02
441 */
442 private function migrate_to_98() {
443 delete_transient( 'frmpro_css' );
444 }
445
446 /**
447 * Move default_blank and clear_on_focus to placeholder.
448 *
449 * @since 4.0
450 */
451 private function migrate_to_97() {
452 $this->migrate_to_placeholder( 'clear_on_focus' );
453 $this->migrate_to_placeholder( 'default_blank' );
454 }
455
456 /**
457 * Move clear_on_focus or default_blank to placeholder.
458 *
459 * @since 4.0
460 */
461 private function migrate_to_placeholder( $type = 'clear_on_focus' ) {
462 $query = array(
463 'field_options like' => '"' . $type . '";s:1:"1";',
464 );
465
466 $fields = FrmDb::get_results( $this->fields, $query, 'id, default_value, field_options, options' );
467
468 foreach ( $fields as $field ) {
469 FrmAppHelper::unserialize_or_decode( $field->field_options );
470 FrmAppHelper::unserialize_or_decode( $field->options );
471 $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type );
472 if ( empty( $update_values ) ) {
473 continue;
474 }
475
476 FrmField::update( $field->id, $update_values );
477 unset( $field );
478 }
479 }
480
481 /**
482 * Delete unneeded default templates
483 *
484 * @since 3.06
485 */
486 private function migrate_to_90() {
487 $form = FrmForm::getOne( 'contact' );
488 if ( $form && $form->default_template == 1 ) {
489 FrmForm::destroy( 'contact' );
490 }
491 }
492
493 /**
494 * Reverse migration 17 -- Divide by 9
495 *
496 * @since 3.0.05
497 */
498 private function migrate_to_86() {
499
500 $fields = $this->get_fields_with_size();
501
502 foreach ( (array) $fields as $f ) {
503 FrmAppHelper::unserialize_or_decode( $f->field_options );
504 $size = $f->field_options['size'];
505 $this->maybe_convert_migrated_size( $size );
506
507 if ( $size === $f->field_options['size'] ) {
508 continue;
509 }
510
511 $f->field_options['size'] = $size;
512 FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
513 unset( $f );
514 }
515
516 // reverse the extra size changes in widgets
517 $widgets = get_option( 'widget_frm_show_form' );
518 if ( empty( $widgets ) ) {
519 return;
520 }
521
522 $this->revert_widget_field_size();
523 }
524
525 private function get_fields_with_size() {
526 $field_types = array(
527 'textarea',
528 'text',
529 'number',
530 'email',
531 'url',
532 'rte',
533 'date',
534 'phone',
535 'password',
536 'image',
537 'tag',
538 'file',
539 );
540
541 $query = array(
542 'type' => $field_types,
543 'field_options like' => 's:4:"size";',
544 'field_options not like' => 's:4:"size";s:0:',
545 );
546
547 return FrmDb::get_results( $this->fields, $query, 'id, field_options' );
548 }
549
550 /**
551 * Reverse the extra size changes in widgets
552 *
553 * @since 3.0.05
554 */
555 private function revert_widget_field_size() {
556 $widgets = get_option( 'widget_frm_show_form' );
557 if ( empty( $widgets ) ) {
558 return;
559 }
560
561 FrmAppHelper::unserialize_or_decode( $widgets );
562 foreach ( $widgets as $k => $widget ) {
563 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
564 continue;
565 }
566
567 $this->maybe_convert_migrated_size( $widgets[ $k ]['size'] );
568 }
569 update_option( 'widget_frm_show_form', $widgets );
570 }
571
572 /**
573 * Divide by 9 to reverse the multiplication
574 *
575 * @since 3.0.05
576 */
577 private function maybe_convert_migrated_size( &$size ) {
578 $has_px_size = ! empty( $size ) && strpos( $size, 'px' );
579 if ( ! $has_px_size ) {
580 return;
581 }
582
583 $int_size = str_replace( 'px', '', $size );
584 if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) {
585 return;
586 }
587
588 $pixel_conversion = 9;
589
590 $size = round( (int) $int_size / $pixel_conversion );
591 }
592
593 /**
594 * Migrate old styling settings. If sites are using the old
595 * default 400px field width, switch it to 100%
596 *
597 * @since 2.0.4
598 */
599 private function migrate_to_25() {
600 // get the style that was created with the style migration
601 $frm_style = new FrmStyle();
602 $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
603 if ( empty( $styles ) ) {
604 return;
605 }
606
607 foreach ( $styles as $style ) {
608 if ( $style->post_content['field_width'] === '400px' ) {
609 $style->post_content['field_width'] = '100%';
610 $frm_style->save( (array) $style );
611
612 return;
613 }
614 }
615 }
616
617 /**
618 * Check if the parent_form_id columns exists.
619 * If not, try and add it again
620 *
621 * @since 2.0.2
622 */
623 private function migrate_to_23() {
624 global $wpdb;
625 $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
626 if ( empty( $exists ) ) {
627 $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
628 }
629 }
630
631 /**
632 * Change field size from character to pixel -- Multiply by 9
633 */
634 private function migrate_to_17() {
635 $fields = $this->get_fields_with_size();
636
637 foreach ( $fields as $f ) {
638 FrmAppHelper::unserialize_or_decode( $f->field_options );
639 if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
640 continue;
641 }
642
643 $this->convert_character_to_px( $f->field_options['size'] );
644
645 FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
646 unset( $f );
647 }
648
649 $this->adjust_widget_size();
650 }
651
652 /**
653 * Change the characters in widgets to pixels
654 */
655 private function adjust_widget_size() {
656 $widgets = get_option( 'widget_frm_show_form' );
657 if ( empty( $widgets ) ) {
658 return;
659 }
660
661 FrmAppHelper::unserialize_or_decode( $widgets );
662 foreach ( $widgets as $k => $widget ) {
663 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
664 continue;
665 }
666 $this->convert_character_to_px( $widgets[ $k ]['size'] );
667 }
668 update_option( 'widget_frm_show_form', $widgets );
669 }
670
671 private function convert_character_to_px( &$size ) {
672 $pixel_conversion = 9;
673
674 $size = round( $pixel_conversion * (int) $size );
675 $size .= 'px';
676 }
677
678 /**
679 * Migrate post and email notification settings into actions
680 */
681 private function migrate_to_16() {
682 $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
683
684 /**
685 * Old email settings format:
686 * email_to: Email or field id
687 * also_email_to: array of fields ids
688 * reply_to: Email, field id, 'custom'
689 * cust_reply_to: string
690 * reply_to_name: field id, 'custom'
691 * cust_reply_to_name: string
692 * plain_text: 0|1
693 * email_message: string or ''
694 * email_subject: string or ''
695 * inc_user_info: 0|1
696 * update_email: 0, 1, 2
697 *
698 * Old autoresponder settings format:
699 * auto_responder: 0|1
700 * ar_email_message: string or ''
701 * ar_email_to: field id
702 * ar_plain_text: 0|1
703 * ar_reply_to_name: string
704 * ar_reply_to: string
705 * ar_email_subject: string
706 * ar_update_email: 0, 1, 2
707 *
708 * New email settings:
709 * post_content: json settings
710 * post_title: form id
711 * post_excerpt: message
712 */
713 foreach ( $forms as $form ) {
714 if ( $form->is_template && $form->default_template ) {
715 // don't migrate the default templates since the email will be added anyway
716 continue;
717 }
718
719 // Format form options
720 $form_options = $form->options;
721 FrmAppHelper::unserialize_or_decode( $form_options );
722
723 // Migrate settings to actions
724 FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
725 }
726 }
727
728 private function migrate_to_11() {
729 global $wpdb;
730
731 $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
732
733 $sending = __( 'Sending', 'formidable' );
734 $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
735 $old_default_html = <<<DEFAULT_HTML
736 <div class="frm_submit">
737 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
738 <input type="submit" value="[button_label]" [button_action] />
739 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
740 </div>
741 DEFAULT_HTML;
742 unset( $sending, $img );
743
744 $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
745 $draft_link = FrmFormsHelper::get_draft_link();
746 foreach ( $forms as $form ) {
747 FrmAppHelper::unserialize_or_decode( $form->options );
748 if ( empty( $form->options['submit_html'] ) ) {
749 continue;
750 }
751
752 if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
753 $form->options['submit_html'] = $new_default_html;
754 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
755 } elseif ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
756 $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
757 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
758 }
759 unset( $form );
760 }
761 }
762 }
763