| @@ -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,61 @@ | ||
| 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 | + * | |
| 174 | + * @return void | |
| 175 | + */ | |
| 176 | + private function add_composite_indexes_for_entries() { | |
| 177 | + global $wpdb; | |
| 178 | + | |
| 179 | + $table_name = "{$wpdb->prefix}frm_items"; | |
| 180 | + $index_name = 'idx_is_draft_created_at'; | |
| 181 | + | |
| 182 | + if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 183 | + $wpdb->query( "CREATE INDEX idx_is_draft_created_at ON `{$wpdb->prefix}frm_items` (is_draft, created_at)" ); | |
| 184 | + } | |
| 185 | + | |
| 186 | + $table_name = "{$wpdb->prefix}frm_item_metas"; | |
| 187 | + $index_name = 'idx_field_id_item_id'; | |
| 188 | + | |
| 189 | + if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 190 | + $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" ); | |
| 191 | + } | |
| 192 | + } | |
| 193 | + | |
| 194 | + /** | |
| 195 | + * Check that an index exists in a database table before trying to add it (which results in an error). | |
| 196 | + * | |
| 197 | + * @since 6.6 | |
| 198 | + * | |
| 199 | + * @param string $table_name | |
| 200 | + * @param string $index_name | |
| 201 | + * @return bool | |
| 202 | + */ | |
| 203 | + private static function index_exists( $table_name, $index_name ) { | |
| 204 | + global $wpdb; | |
| 205 | + $row = $wpdb->get_row( | |
| 206 | + $wpdb->prepare( | |
| 207 | + 'SELECT 1 FROM information_schema.statistics | |
| 208 | + WHERE table_schema = database() | |
| 209 | + AND table_name = %s | |
| 210 | + AND index_name = %s | |
| 211 | + LIMIT 1', | |
| 212 | + array( $table_name, $index_name ) | |
| 213 | + ) | |
| 214 | + ); | |
| 215 | + return (bool) $row; | |
| 216 | + } | |
| 217 | + | |
| 163 | 218 | private function maybe_create_contact_form() { |
| 164 | 219 | $form_exists = FrmForm::get_id_by_key( 'contact-form' ); |
| 165 | 220 | if ( ! $form_exists ) { |
| 166 | 221 | $this->add_default_template(); |
| @@ -204,9 +259,9 @@ | ||
| 204 | 259 | // bail if we don't know the previous version |
| 205 | 260 | return; |
| 206 | 261 | } |
| 207 | 262 | |
| 208 | - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98 ); | |
| 263 | + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101 ); | |
| 209 | 264 | foreach ( $migrations as $migration ) { |
| 210 | 265 | if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) { |
| 211 | 266 | $function_name = 'migrate_to_' . $migration; |
| 212 | 267 | $this->$function_name(); |
| @@ -233,9 +288,10 @@ | ||
| 233 | 288 | delete_option( 'frm_lite_settings_upgrade' ); |
| 234 | 289 | delete_option( 'frm-usage-uuid' ); |
| 235 | 290 | delete_option( 'frm_inbox' ); |
| 236 | 291 | delete_option( 'frmpro_css' ); |
| 237 | - delete_option( 'frm_welcome_redirect' ); | |
| 292 | + delete_option( FrmOnboardingWizardController::REDIRECT_STATUS_OPTION ); | |
| 293 | + delete_option( FrmEmailSummaryHelper::$option_name ); | |
| 238 | 294 | |
| 239 | 295 | // Delete roles. |
| 240 | 296 | $frm_roles = FrmAppHelper::frm_capabilities(); |
| 241 | 297 | $roles = get_editable_roles(); |
| @@ -264,9 +320,9 @@ | ||
| 264 | 320 | // delete transients |
| 265 | 321 | delete_transient( 'frmpro_css' ); |
| 266 | 322 | delete_transient( 'frm_options' ); |
| 267 | 323 | delete_transient( 'frmpro_options' ); |
| 268 | - delete_transient( 'frm_activation_redirect' ); | |
| 324 | + delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME ); | |
| 269 | 325 | |
| 270 | 326 | $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 | 327 | |
| 272 | 328 | do_action( 'frm_after_uninstall' ); |
| @@ -274,8 +330,28 @@ | ||
| 274 | 330 | return true; |
| 275 | 331 | } |
| 276 | 332 | |
| 277 | 333 | /** |
| 334 | + * Disables summary email for multisite (not the main site) if recipient setting isn't changed. | |
| 335 | + * | |
| 336 | + * @since 6.8 | |
| 337 | + */ | |
| 338 | + private function migrate_to_101() { | |
| 339 | + if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) { | |
| 340 | + return; | |
| 341 | + } | |
| 342 | + | |
| 343 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 344 | + if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) { | |
| 345 | + // User changed it. | |
| 346 | + return; | |
| 347 | + } | |
| 348 | + | |
| 349 | + $frm_settings->summary_emails = 0; | |
| 350 | + $frm_settings->store(); | |
| 351 | + } | |
| 352 | + | |
| 353 | + /** | |
| 278 | 354 | * Clear frmpro_css transient. |
| 279 | 355 | * |
| 280 | 356 | * @since 4.10.02 |
| 281 | 357 | */ |
| @@ -318,9 +394,9 @@ | ||
| 318 | 394 | } |
| 319 | 395 | } |
| 320 | 396 | |
| 321 | 397 | /** |
| 322 | - * Delete uneeded default templates | |
| 398 | + * Delete unneeded default templates | |
| 323 | 399 | * |
| 324 | 400 | * @since 3.06 |
| 325 | 401 | */ |
| 326 | 402 | private function migrate_to_90() { |
| @@ -340,9 +416,9 @@ | ||
| 340 | 416 | $fields = $this->get_fields_with_size(); |
| 341 | 417 | |
| 342 | 418 | foreach ( (array) $fields as $f ) { |
| 343 | 419 | FrmAppHelper::unserialize_or_decode( $f->field_options ); |
| 344 | - $size = $f->field_options['size']; | |
| 420 | + $size = $f->field_options['size']; | |
| 345 | 421 | $this->maybe_convert_migrated_size( $size ); |
| 346 | 422 | |
| 347 | 423 | if ( $size === $f->field_options['size'] ) { |
| 348 | 424 | continue; |
| @@ -444,9 +520,9 @@ | ||
| 444 | 520 | return; |
| 445 | 521 | } |
| 446 | 522 | |
| 447 | 523 | foreach ( $styles as $style ) { |
| 448 | - if ( $style->post_content['field_width'] == '400px' ) { | |
| 524 | + if ( $style->post_content['field_width'] === '400px' ) { | |
| 449 | 525 | $style->post_content['field_width'] = '100%'; |
| 450 | 526 | $frm_style->save( (array) $style ); |
| 451 | 527 | |
| 452 | 528 | return; |
| @@ -510,9 +586,9 @@ | ||
| 510 | 586 | |
| 511 | 587 | private function convert_character_to_px( &$size ) { |
| 512 | 588 | $pixel_conversion = 9; |
| 513 | 589 | |
| 514 | - $size = round( $pixel_conversion * (int) $size ); | |
| 590 | + $size = round( $pixel_conversion * (int) $size ); | |
| 515 | 591 | $size .= 'px'; |
| 516 | 592 | } |
| 517 | 593 | |
| 518 | 594 | /** |
| @@ -584,9 +660,9 @@ | ||
| 584 | 660 | $new_default_html = FrmFormsHelper::get_default_html( 'submit' ); |
| 585 | 661 | $draft_link = FrmFormsHelper::get_draft_link(); |
| 586 | 662 | foreach ( $forms as $form ) { |
| 587 | 663 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 588 | - if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) { | |
| 664 | + if ( empty( $form->options['submit_html'] ) ) { | |
| 589 | 665 | continue; |
| 590 | 666 | } |
| 591 | 667 | |
| 592 | 668 | if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |