WordPress.org

Make WordPress Core

Ticket #32310: patch.diff

File patch.diff, 1.0 KB (added by gabrielperezs, 5 years ago)

Patch to check the actual collation of a table before try to change it again

  • wp-admin/includes/upgrade.php

     
    17591759                }
    17601760        }
    17611761
    1762         return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" );
     1762        if (_get_table_collation($table) != 'utf8mb4_unicode_ci')
     1763                return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" );
     1764
     1765        return true;
    17631766}
    17641767
    17651768/**
     1769 * Get the collation of a table utf8mb4.
     1770 *
     1771 * @since 4.2.0
     1772 *
     1773 * @param string $table The table to check.
     1774 * @return string like utf8mb4_unicode_ci.
     1775 */
     1776function _get_table_collation($table) {
     1777    global $wpdb;
     1778
     1779    $table_detail = $wpdb->get_results("show table status like '".$table."'");
     1780    if (empty($table_detail)) return false;
     1781    $table_detail = array_shift($table_detail);
     1782
     1783    return $table_detail->Collation;
     1784}
     1785
     1786/**
    17661787 * Retrieve all options as it was for 1.2.
    17671788 *
    17681789 * @since 1.2.0