Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update charset to utf8mb4_unicode_ci for emoji support #2527

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions php/admin/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
8 changes: 4 additions & 4 deletions php/classes/class-qsm-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading