diff --git a/php/admin/functions.php b/php/admin/functions.php index 4e640b5fb..d2f47e68d 100644 --- a/php/admin/functions.php +++ b/php/admin/functions.php @@ -215,6 +215,38 @@ function qsm_add_author_column_in_db() { } } } + + /** + * Add new column in the results table + * + * @since 9.0.1 + */ + if ( get_option( 'qsm_update_db_column_charset_utf8mb4_unicode_ci', '' ) != 1 ) { + global $wpdb; + + $tables_to_convert = array( + "{$wpdb->prefix}mlw_qm_audit_trail", + "{$wpdb->prefix}mlw_questions", + "{$wpdb->prefix}mlw_quizzes", + "{$wpdb->prefix}mlw_results", + ); + + $success = true; + + foreach ( $tables_to_convert as $table ) { + $query = "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"; + $result = $wpdb->query($query); + + if ( $result === false ) { + $success = false; + $mlwQuizMasterNext->log_manager->add( 'Error updating column charset utf8mb4_unicode_ci', "Tried $query but got {$wpdb->last_error}.", 0, 'error' ); + } + } + + if ( $success ) { + update_option( 'qsm_update_db_column_charset_utf8mb4_unicode_ci', 1 ); + } + } } add_action( 'admin_init', 'qsm_change_the_post_type' ); diff --git a/php/classes/class-qsm-install.php b/php/classes/class-qsm-install.php index 94866fa6c..447871480 100644 --- a/php/classes/class-qsm-install.php +++ b/php/classes/class-qsm-install.php @@ -1951,10 +1951,10 @@ public function update() { } // Update 2.6.1 - $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_qm_audit_trail CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' ); - $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_questions CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci' ); - $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_quizzes CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci' ); - $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_results CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci' ); + $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_qm_audit_trail CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;' ); + $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_questions CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); + $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_quizzes CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); + $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_results CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); global $wpdb; $table_name = $wpdb->prefix . 'mlw_results';