| @@ -42,9 +42,9 @@ | ||
| 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(); |
| @@ -157,10 +157,61 @@ | ||
| 157 | 157 | $wpdb->query( $q . $charset_collate ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 158 | 158 | } |
| 159 | 159 | unset( $q ); |
| 160 | 160 | } |
| 161 | + | |
| 162 | + $this->add_composite_indexes_for_entries(); | |
| 161 | 163 | } |
| 162 | 164 | |
| 165 | + /** | |
| 166 | + * These indexes help optimize database queries for entries. | |
| 167 | + * | |
| 168 | + * @since 6.6 | |
| 169 | + * | |
| 170 | + * @return void | |
| 171 | + */ | |
| 172 | + private function add_composite_indexes_for_entries() { | |
| 173 | + global $wpdb; | |
| 174 | + | |
| 175 | + $table_name = "{$wpdb->prefix}frm_items"; | |
| 176 | + $index_name = 'idx_is_draft_created_at'; | |
| 177 | + | |
| 178 | + if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 179 | + $wpdb->query( "CREATE INDEX idx_is_draft_created_at ON `{$wpdb->prefix}frm_items` (is_draft, created_at)" ); | |
| 180 | + } | |
| 181 | + | |
| 182 | + $table_name = "{$wpdb->prefix}frm_item_metas"; | |
| 183 | + $index_name = 'idx_field_id_item_id'; | |
| 184 | + | |
| 185 | + if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 186 | + $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" ); | |
| 187 | + } | |
| 188 | + } | |
| 189 | + | |
| 190 | + /** | |
| 191 | + * Check that an index exists in a database table before trying to add it (which results in an error). | |
| 192 | + * | |
| 193 | + * @since 6.6 | |
| 194 | + * | |
| 195 | + * @param string $table_name | |
| 196 | + * @param string $index_name | |
| 197 | + * @return bool | |
| 198 | + */ | |
| 199 | + private static function index_exists( $table_name, $index_name ) { | |
| 200 | + global $wpdb; | |
| 201 | + $row = $wpdb->get_row( | |
| 202 | + $wpdb->prepare( | |
| 203 | + 'SELECT 1 FROM information_schema.statistics | |
| 204 | + WHERE table_schema = database() | |
| 205 | + AND table_name = %s | |
| 206 | + AND index_name = %s | |
| 207 | + LIMIT 1', | |
| 208 | + array( $table_name, $index_name ) | |
| 209 | + ) | |
| 210 | + ); | |
| 211 | + return (bool) $row; | |
| 212 | + } | |
| 213 | + | |
| 163 | 214 | private function maybe_create_contact_form() { |
| 164 | 215 | $form_exists = FrmForm::get_id_by_key( 'contact-form' ); |
| 165 | 216 | if ( ! $form_exists ) { |
| 166 | 217 | $this->add_default_template(); |
| @@ -204,9 +255,9 @@ | ||
| 204 | 255 | // bail if we don't know the previous version |
| 205 | 256 | return; |
| 206 | 257 | } |
| 207 | 258 | |
| 208 | - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98 ); | |
| 259 | + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101 ); | |
| 209 | 260 | foreach ( $migrations as $migration ) { |
| 210 | 261 | if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) { |
| 211 | 262 | $function_name = 'migrate_to_' . $migration; |
| 212 | 263 | $this->$function_name(); |
| @@ -234,8 +285,9 @@ | ||
| 234 | 285 | delete_option( 'frm-usage-uuid' ); |
| 235 | 286 | delete_option( 'frm_inbox' ); |
| 236 | 287 | delete_option( 'frmpro_css' ); |
| 237 | 288 | delete_option( 'frm_welcome_redirect' ); |
| 289 | + delete_option( FrmEmailSummaryHelper::$option_name ); | |
| 238 | 290 | |
| 239 | 291 | // Delete roles. |
| 240 | 292 | $frm_roles = FrmAppHelper::frm_capabilities(); |
| 241 | 293 | $roles = get_editable_roles(); |
| @@ -271,8 +323,28 @@ | ||
| 271 | 323 | |
| 272 | 324 | do_action( 'frm_after_uninstall' ); |
| 273 | 325 | |
| 274 | 326 | return true; |
| 327 | + } | |
| 328 | + | |
| 329 | + /** | |
| 330 | + * Disables summary email for multisite (not the main site) if recipient setting isn't changed. | |
| 331 | + * | |
| 332 | + * @since 6.8 | |
| 333 | + */ | |
| 334 | + private function migrate_to_101() { | |
| 335 | + if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) { | |
| 336 | + return; | |
| 337 | + } | |
| 338 | + | |
| 339 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 340 | + if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) { | |
| 341 | + // User changed it. | |
| 342 | + return; | |
| 343 | + } | |
| 344 | + | |
| 345 | + $frm_settings->summary_emails = 0; | |
| 346 | + $frm_settings->store(); | |
| 275 | 347 | } |
| 276 | 348 | |
| 277 | 349 | /** |
| 278 | 350 | * Clear frmpro_css transient. |