Skip to content

Commit

Permalink
Merge pull request #2527 from QuizandSurveyMaster/dev-zubair
Browse files Browse the repository at this point in the history
update charset to utf8mb4_unicode_ci for emoji support
  • Loading branch information
zubairraeen authored Apr 24, 2024
2 parents dd99d52 + 39a6fa4 commit d40f3ad
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
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

0 comments on commit d40f3ad

Please sign in to comment.