Upgrades to legacy version 1.0.10.
Description
See also
Source
File: src/components/legacy-upgrades.php
protected function upgrade_to_1_0_10() { global $wpdb; $containers = $this->get_full_table_name( 'containers' ); $elements = $this->get_full_table_name( 'elements' ); $element_answers = $this->get_full_table_name( 'element_answers' ); $element_choices = $this->get_full_table_name( 'element_choices' ); $element_settings = $this->get_full_table_name( 'element_settings' ); $results = $this->get_full_table_name( 'results' ); $submissions = $this->get_full_table_name( 'submissions' ); $result_values = $this->get_full_table_name( 'result_values' ); $submission_values = $this->get_full_table_name( 'submission_values' ); $participants = $this->get_full_table_name( 'participants' ); $email_notifications = $this->get_full_table_name( 'email_notifications' ); $wpdb->query( "ALTER TABLE $containers CHANGE sort sort int(11) unsigned NOT NULL default '0'" ); $wpdb->query( "ALTER TABLE $containers ADD KEY form_id (form_id)" ); $wpdb->query( "ALTER TABLE $elements CHANGE sort sort int(11) unsigned NOT NULL default '0'" ); $wpdb->query( "ALTER TABLE $elements ADD KEY container_id (container_id)" ); $wpdb->query( "ALTER TABLE $elements ADD KEY type (type)" ); $wpdb->query( "ALTER TABLE $elements ADD KEY type_container_id (type,container_id)" ); $wpdb->query( "ALTER TABLE $element_answers RENAME TO $element_choices" ); $wpdb->query( "ALTER TABLE $element_choices CHANGE answer value text NOT NULL" ); $wpdb->query( "ALTER TABLE $element_choices CHANGE sort sort int(11) unsigned NOT NULL default '0'" ); $wpdb->query( "ALTER TABLE $element_choices ADD field char(100) NOT NULL default '' AFTER element_id" ); $wpdb->query( "ALTER TABLE $element_choices ADD KEY element_id (element_id)" ); $wpdb->query( "ALTER TABLE $element_settings ADD KEY element_id (element_id)" ); $wpdb->query( "ALTER TABLE $results RENAME TO $submissions" ); $wpdb->query( "ALTER TABLE $submissions CHANGE remote_addr remote_addr char(50) NOT NULL" ); $wpdb->query( "ALTER TABLE $submissions CHANGE cookie_key user_key char(50) NOT NULL" ); $wpdb->query( "ALTER TABLE $submissions ADD status char(50) NOT NULL default 'completed' AFTER user_key" ); $wpdb->query( "ALTER TABLE $submissions ADD KEY form_id (form_id)" ); $wpdb->query( "ALTER TABLE $submissions ADD KEY user_id (user_id)" ); $wpdb->query( "ALTER TABLE $submissions ADD KEY status (status)" ); $wpdb->query( "ALTER TABLE $submissions ADD KEY status_form_id (status,form_id)" ); $wpdb->query( "ALTER TABLE $result_values RENAME TO $submission_values" ); $wpdb->query( "ALTER TABLE $submission_values CHANGE result_id submission_id int(11) unsigned NOT NULL" ); $wpdb->query( "ALTER TABLE $submission_values ADD field char(100) NOT NULL default '' AFTER element_id" ); $wpdb->query( "ALTER TABLE $submission_values ADD KEY submission_id (submission_id)" ); $wpdb->query( "ALTER TABLE $submission_values ADD KEY element_id (element_id)" ); $this->upgrade_legacy_settings(); $form_attachment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s AND post_status = %s LIMIT 1", 'attachment', 'torro-forms-upload' ) ); if ( ! empty( $form_attachment_ids ) ) { // Set a flag to indicate that some form attachments need to have their old status migrated to a taxonomy term. update_option( $this->get_prefix() . 'legacy_attachments_need_migration', 'true' ); } // Set a flag that the old participants table still exists. update_option( $this->get_prefix() . 'legacy_participants_table_installed', 'true' ); // Set a flag that the old email notifications table still exists. update_option( $this->get_prefix() . 'legacy_email_notifications_table_installed', 'true' ); // If forms exist, their data needs to be migrated on-the-fly later. $form_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s", $this->get_prefix() . 'form' ) ); if ( empty( $form_ids ) ) { return; } // Set flags to indicate that form meta still need to be migrated. $insert_flags = array(); foreach ( $form_ids as $form_id ) { $insert_flags[] = $wpdb->prepare( "( %d, %s, %s)", (int) $form_id, $this->get_prefix() . 'legacy_needs_migration', 'true' ); } $wpdb->query( "INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES " . implode( ', ', $insert_flags ) ); foreach ( $form_ids as $form_id ) { wp_cache_delete( (int) $form_id, 'post_meta' ); } }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |