View Issue Details

IDProjectCategoryView StatusLast Update
0000483Composrcommandrpublic2012-08-19 12:34
ReporterChris GrahamAssigned ToChris Graham 
SeverityFeature-request 
Status closedResolutionwon't fix 
Product Version 
Fixed in Version 
Summary0000483: New MySQL charset change command
DescriptionCommand to change everything about a character set. Takes charset param, defaults to utf-8.
Additional InformationOutline...

    $charset='utf8';

    header('Content-Type: text/plain');
    $GLOBALS['NO_DB_SCOPE_CHECK']=true;
    $GLOBALS['SITE_DB']->query('ALTER DATABASE '.get_db_site().' DEFAULT CHARACTER SET '.filter_naughty($charset));
    echo "Converted DB, sets default for new tables\n";
    $tables=$GLOBALS['SITE_DB']->query_select('db_meta',array('DISTINCT m_table'),NULL,'ORDER BY m_table');
    foreach ($tables as $table)
    {
        $GLOBALS['SITE_DB']->query('ALTER TABLE '.get_table_prefix().$table['m_table'].' CONVERT TO CHARACTER SET '.filter_naughty($charset));
        echo 'Converted '.$table['m_table']."\n";
    }
    $contents=file_get_contents(get_file_base().'/info.php');
    if (strpos($contents,'$SITE_INFO[\'database_charset\']=')!==false)
    {
        $contents=preg_replace('#\$SITE_INFO\[\'database_charset\']=\'[\w\-]+\';','$SITE_INFO[\'database_charset\']=\''.filter_naughty($charset).'\';',$contents);
        file_put_contents($contents,$contents);
        echo 'Told info.php new charset\n";
    }
    // TODO... Go through each lang pack, checking it is right charset, if not update


Also ideally needs a parameter to force cleanup of literally-stored utf8 data in non-utf8 tables (does binary charset change).


Document all this in the internationalisation tutorial.
TagsNo tags attached.
Time estimation (hours)2
Sponsorship open

Activities

Chris Graham

2012-06-20 14:30

administrator   ~0000677

"Also ideally needs a parameter to force cleanup of literally-stored utf8 data in non-utf8 tables (does binary charset change)." Since Composr now enforces the right communication character set, encoding problems are not buried but result in visible errors. Corruption cannot creep up, so this is not needed.

Chris Graham

2012-06-20 14:35

administrator   ~0000678

I'd consider this functionality quite critical, except that most users will create their databases as utf-8 in the first place if they are using a non-anglicised host. That is fine, the default Western European used in Composr's EN pack works great with a utf-8 DB now.
Plus people can do an export then re-import into a new DB, if they need to switch the DBs charset.

So it's not an awful situation. I'd still love this Commandr command to exist. Probably next time I need to do a conversion I'll write the command and use it.

Chris Graham

2012-08-19 12:34

administrator   ~0000880

As Composr is moving to utf-8, this will become irrelevant.

Issue History

Date Modified Username Field Change