Commit f2b5bc24 authored by Heena Agheda's avatar Heena Agheda Committed by Cecilia Vela Gurovic
Browse files

Bug 1895259: Set collation to store emoji

also update entrycontent in import_entry_requests to be able to import
the views with emojis

Change-Id: I0012dd215b488ce93313051f2bfe9f5f524433e2
parent 9f8e835c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -59,7 +59,8 @@ else {
    define('TITLE', get_string('upgrades', 'admin'));
    if (!db_is_utf8()) {
        global $SESSION;
        $SESSION->add_error_msg(get_string('dbnotutf8warning', 'admin'));
        $dbnotutf = (is_mysql() ? 'dbnotutf8mb4warning' : 'dbnotutf8warning');
        $SESSION->add_error_msg(get_string($dbnotutf, 'admin'));
    }
    ensure_upgrade_sanity();
    $smarty->assign('upgradeheading', get_string('performingupgrades', 'admin'));
+1 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ $string['upgradeinprogress'] = 'An upgrade began at %s and did not complete. <a
$string['Plugin'] = 'Plugin';
$string['jsrequiredforupgrade'] = 'You must enable JavaScript to perform an install or upgrade.';
$string['dbnotutf8warning'] = 'You are not using a UTF-8 database. Mahara stores all data as UTF-8 internally. You may still attempt this upgrade, but it is recommended that you convert your database to UTF-8.';
$string['dbnotutf8mb4warning'] = 'You are not using a utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding) database. Mahara stores all data as utf8mb4 internally. You may still attempt this upgrade, but it is recommended that you convert your database to utf8mb4.';
$string['dbcollationmismatch'] = 'A column of your database is using a collation that is not the same as the database default. Please ensure all columns use the same collation as the database.';
$string['maharainstalled'] = 'Mahara is already installed.';
$string['cliadminpassword1'] = 'The password for the administration account';
+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ $string['dbconnfailed'] = 'Mahara could not connect to the application database.
The error received was:
';
$string['dbnotutf8'] = 'You are not using a UTF-8 database. Mahara stores all data as UTF-8 internally. Please drop and re-create your database using UTF-8 encoding.';
$string['dbnotutf8mb4'] = 'You are not using a utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding) database. Mahara stores all data as utf8mb4 internally. Please drop and re-create your database using utf8mb4 encoding.';
$string['dbversioncheckfailed'] = 'Your database server version is not new enough to successfully run Mahara. Your server is %s %s, but Mahara requires at least version %s.';
$string['plpgsqlnotavailable'] = 'The PL/pgSQL language is not enabled in your Postgres installation, and Mahara cannot enable it. Please install PL/pgSQL in your database manually. For instructions on how to do this, see https://wiki.mahara.org/wiki/System_Administrator\'s_Guide/Enabling_Plpgsql';
$string['mysqlnotriggerprivilege'] = 'Mahara requires permission to create database triggers, but is unable to do so. Please ensure that the trigger privilege has been granted to the appropriate user in your MySQL installation. For instructions on how to do this, see https://wiki.mahara.org/wiki/System_Administrator\'s_Guide/Granting_Trigger_Privilege';
+24 −0
Original line number Diff line number Diff line
@@ -1933,5 +1933,29 @@ function xmldb_core_upgrade($oldversion=0) {
        change_field_notnull($table, $field);
    }

    // Set collation for view table - description field and block_instance table - configdata field for Bug 1895259
    if ($oldversion < 2020092103) {
        if (is_mysql()) {
            $columns = array(0 => array('table' => 'view',
                                        'value' => 'description'),
                             1 => array('table' => 'view',
                                        'value' => 'instructions'),
                             2 => array('table' => 'block_instance',
                                        'value' => 'configdata'),
                             3 => array('table' => 'import_entry_requests',
                                        'value' => 'entrycontent')
                            );
            foreach ($columns as $column) {
                $charset = get_field_sql("SELECT character_set_name FROM information_schema.columns
                                          WHERE table_schema = '" . get_config('dbname') . "'
                                          AND table_name = '" . get_config('dbprefix') . $column['table'] . "'
                                          AND column_name = ?", array($column['value']));
                if ($charset && !preg_match('/utf8mb4/', $charset)) {
                    execute_sql('ALTER TABLE {' . $column['table'] . '} MODIFY ' . $column['value'] . ' text CHARSET utf8mb4');
                }
            }
        }
    }

    return $status;
}
+3 −2
Original line number Diff line number Diff line
@@ -76,8 +76,9 @@ function db_is_utf8() {
        throw new SQLException('Database connection is not available ');
    }
    if (is_mysql()) {
        // For mysql check for utf8mb4, Bug: #1895259
        $result = $db->_Execute("SHOW VARIABLES LIKE 'character_set_database'");
        return preg_match('/^utf8/', $result->fields['Value']);
        return preg_match('/^utf8mb4/', $result->fields['Value']);
    }
    if (is_postgres()) {
        $result = $db->_Execute("SHOW SERVER_ENCODING");
@@ -1748,7 +1749,7 @@ function configure_dbconnection() {

    if (is_mysql()) {
        $db->_Execute("SET SQL_MODE='PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE'");
        $db->_Execute("SET CHARACTER SET utf8mb4");
        $db->_Execute("SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci");
        $db->_Execute("SET SQL_BIG_SELECTS=1");
    }

Loading