| @@ -35,9 +35,9 @@ | ||
| 35 | 35 | if ( $needs_upgrade ) { |
| 36 | 36 | // update rewrite rules for views and other custom post types |
| 37 | 37 | flush_rewrite_rules(); |
| 38 | 38 | |
| 39 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); | |
| 39 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | |
| 40 | 40 | |
| 41 | 41 | $old_db_version = get_option( 'frm_db_version' ); |
| 42 | 42 | |
| 43 | 43 | $this->create_tables(); |
| @@ -42,15 +42,19 @@ | ||
| 42 | 42 | |
| 43 | 43 | $this->create_tables(); |
| 44 | 44 | $this->migrate_data( $old_db_version ); |
| 45 | 45 | |
| 46 | - /***** SAVE DB VERSION *****/ | |
| 46 | + // SAVE DB VERSION. | |
| 47 | 47 | update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version ); |
| 48 | 48 | |
| 49 | 49 | if ( ! $old_db_version ) { |
| 50 | 50 | $this->maybe_create_contact_form(); |
| 51 | + | |
| 52 | + if ( false === get_option( 'frm_first_activation' ) ) { | |
| 53 | + update_option( 'frm_first_activation', time(), false ); | |
| 54 | + } | |
| 51 | 55 | } |
| 52 | - } | |
| 56 | + }//end if | |
| 53 | 57 | |
| 54 | 58 | do_action( 'frm_after_install' ); |
| 55 | 59 | |
| 56 | 60 | $frm_vars['doing_upgrade'] = false; |
| @@ -157,10 +161,77 @@ | ||
| 157 | 161 | $wpdb->query( $q . $charset_collate ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 158 | 162 | } |
| 159 | 163 | unset( $q ); |
| 160 | 164 | } |
| 165 | + | |
| 166 | + $this->add_composite_indexes_for_entries(); | |
| 161 | 167 | } |
| 162 | 168 | |
| 169 | + /** | |
| 170 | + * These indexes help optimize database queries for entries. | |
| 171 | + * | |
| 172 | + * @since 6.6 | |
| 173 | + * @since 6.16.3 idx_form_id_is_draft was also added to frm_items. | |
| 174 | + * @since 6.17 idx_form_id_type was also added to frm_fields. | |
| 175 | + * | |
| 176 | + * @return void | |
| 177 | + */ | |
| 178 | + private function add_composite_indexes_for_entries() { | |
| 179 | + global $wpdb; | |
| 180 | + | |
| 181 | + $table_name = "{$wpdb->prefix}frm_items"; | |
| 182 | + $index_name = 'idx_is_draft_created_at'; | |
| 183 | + | |
| 184 | + if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 185 | + $wpdb->query( "CREATE INDEX idx_is_draft_created_at ON `{$wpdb->prefix}frm_items` (is_draft, created_at)" ); | |
| 186 | + } | |
| 187 | + | |
| 188 | + $table_name = "{$wpdb->prefix}frm_item_metas"; | |
| 189 | + $index_name = 'idx_field_id_item_id'; | |
| 190 | + | |
| 191 | + if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 192 | + $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" ); | |
| 193 | + } | |
| 194 | + | |
| 195 | + $table_name = "{$wpdb->prefix}frm_items"; | |
| 196 | + $index_name = 'idx_form_id_is_draft'; | |
| 197 | + | |
| 198 | + if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 199 | + $wpdb->query( "CREATE INDEX idx_form_id_is_draft ON `{$wpdb->prefix}frm_items` (form_id, is_draft)" ); | |
| 200 | + } | |
| 201 | + | |
| 202 | + $table_name = "{$wpdb->prefix}frm_fields"; | |
| 203 | + $index_name = 'idx_form_id_type'; | |
| 204 | + | |
| 205 | + if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 206 | + $wpdb->query( "CREATE INDEX idx_form_id_type ON `{$wpdb->prefix}frm_fields` (form_id, type(30))" ); | |
| 207 | + } | |
| 208 | + } | |
| 209 | + | |
| 210 | + /** | |
| 211 | + * Check that an index exists in a database table before trying to add it (which results in an error). | |
| 212 | + * | |
| 213 | + * @since 6.6 | |
| 214 | + * | |
| 215 | + * @param string $table_name | |
| 216 | + * @param string $index_name | |
| 217 | + * @return bool | |
| 218 | + */ | |
| 219 | + private static function index_exists( $table_name, $index_name ) { | |
| 220 | + global $wpdb; | |
| 221 | + $row = $wpdb->get_row( | |
| 222 | + $wpdb->prepare( | |
| 223 | + 'SELECT 1 FROM information_schema.statistics | |
| 224 | + WHERE table_schema = database() | |
| 225 | + AND table_name = %s | |
| 226 | + AND index_name = %s | |
| 227 | + LIMIT 1', | |
| 228 | + array( $table_name, $index_name ) | |
| 229 | + ) | |
| 230 | + ); | |
| 231 | + return (bool) $row; | |
| 232 | + } | |
| 233 | + | |
| 163 | 234 | private function maybe_create_contact_form() { |
| 164 | 235 | $form_exists = FrmForm::get_id_by_key( 'contact-form' ); |
| 165 | 236 | if ( ! $form_exists ) { |
| 166 | 237 | $this->add_default_template(); |
| @@ -204,9 +275,9 @@ | ||
| 204 | 275 | // bail if we don't know the previous version |
| 205 | 276 | return; |
| 206 | 277 | } |
| 207 | 278 | |
| 208 | - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98 ); | |
| 279 | + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101 ); | |
| 209 | 280 | foreach ( $migrations as $migration ) { |
| 210 | 281 | if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) { |
| 211 | 282 | $function_name = 'migrate_to_' . $migration; |
| 212 | 283 | $this->$function_name(); |
| @@ -233,9 +304,10 @@ | ||
| 233 | 304 | delete_option( 'frm_lite_settings_upgrade' ); |
| 234 | 305 | delete_option( 'frm-usage-uuid' ); |
| 235 | 306 | delete_option( 'frm_inbox' ); |
| 236 | 307 | delete_option( 'frmpro_css' ); |
| 237 | - delete_option( 'frm_welcome_redirect' ); | |
| 308 | + delete_option( FrmOnboardingWizardController::REDIRECT_STATUS_OPTION ); | |
| 309 | + delete_option( FrmEmailSummaryHelper::$option_name ); | |
| 238 | 310 | |
| 239 | 311 | // Delete roles. |
| 240 | 312 | $frm_roles = FrmAppHelper::frm_capabilities(); |
| 241 | 313 | $roles = get_editable_roles(); |
| @@ -264,9 +336,9 @@ | ||
| 264 | 336 | // delete transients |
| 265 | 337 | delete_transient( 'frmpro_css' ); |
| 266 | 338 | delete_transient( 'frm_options' ); |
| 267 | 339 | delete_transient( 'frmpro_options' ); |
| 268 | - delete_transient( 'frm_activation_redirect' ); | |
| 340 | + delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME ); | |
| 269 | 341 | |
| 270 | 342 | $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_%' ) ); |
| 271 | 343 | |
| 272 | 344 | do_action( 'frm_after_uninstall' ); |
| @@ -274,8 +346,28 @@ | ||
| 274 | 346 | return true; |
| 275 | 347 | } |
| 276 | 348 | |
| 277 | 349 | /** |
| 350 | + * Disables summary email for multisite (not the main site) if recipient setting isn't changed. | |
| 351 | + * | |
| 352 | + * @since 6.8 | |
| 353 | + */ | |
| 354 | + private function migrate_to_101() { | |
| 355 | + if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) { | |
| 356 | + return; | |
| 357 | + } | |
| 358 | + | |
| 359 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 360 | + if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) { | |
| 361 | + // User changed it. | |
| 362 | + return; | |
| 363 | + } | |
| 364 | + | |
| 365 | + $frm_settings->summary_emails = 0; | |
| 366 | + $frm_settings->store(); | |
| 367 | + } | |
| 368 | + | |
| 369 | + /** | |
| 278 | 370 | * Clear frmpro_css transient. |
| 279 | 371 | * |
| 280 | 372 | * @since 4.10.02 |
| 281 | 373 | */ |
| @@ -318,9 +410,9 @@ | ||
| 318 | 410 | } |
| 319 | 411 | } |
| 320 | 412 | |
| 321 | 413 | /** |
| 322 | - * Delete uneeded default templates | |
| 414 | + * Delete unneeded default templates | |
| 323 | 415 | * |
| 324 | 416 | * @since 3.06 |
| 325 | 417 | */ |
| 326 | 418 | private function migrate_to_90() { |
| @@ -340,9 +432,9 @@ | ||
| 340 | 432 | $fields = $this->get_fields_with_size(); |
| 341 | 433 | |
| 342 | 434 | foreach ( (array) $fields as $f ) { |
| 343 | 435 | FrmAppHelper::unserialize_or_decode( $f->field_options ); |
| 344 | - $size = $f->field_options['size']; | |
| 436 | + $size = $f->field_options['size']; | |
| 345 | 437 | $this->maybe_convert_migrated_size( $size ); |
| 346 | 438 | |
| 347 | 439 | if ( $size === $f->field_options['size'] ) { |
| 348 | 440 | continue; |
| @@ -444,9 +536,9 @@ | ||
| 444 | 536 | return; |
| 445 | 537 | } |
| 446 | 538 | |
| 447 | 539 | foreach ( $styles as $style ) { |
| 448 | - if ( $style->post_content['field_width'] == '400px' ) { | |
| 540 | + if ( $style->post_content['field_width'] === '400px' ) { | |
| 449 | 541 | $style->post_content['field_width'] = '100%'; |
| 450 | 542 | $frm_style->save( (array) $style ); |
| 451 | 543 | |
| 452 | 544 | return; |
| @@ -510,9 +602,9 @@ | ||
| 510 | 602 | |
| 511 | 603 | private function convert_character_to_px( &$size ) { |
| 512 | 604 | $pixel_conversion = 9; |
| 513 | 605 | |
| 514 | - $size = round( $pixel_conversion * (int) $size ); | |
| 606 | + $size = round( $pixel_conversion * (int) $size ); | |
| 515 | 607 | $size .= 'px'; |
| 516 | 608 | } |
| 517 | 609 | |
| 518 | 610 | /** |
| @@ -584,9 +676,9 @@ | ||
| 584 | 676 | $new_default_html = FrmFormsHelper::get_default_html( 'submit' ); |
| 585 | 677 | $draft_link = FrmFormsHelper::get_draft_link(); |
| 586 | 678 | foreach ( $forms as $form ) { |
| 587 | 679 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 588 | - if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) { | |
| 680 | + if ( empty( $form->options['submit_html'] ) ) { | |
| 589 | 681 | continue; |
| 590 | 682 | } |
| 591 | 683 | |
| 592 | 684 | if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |