Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Mon, Sep 22, 12:27 AM

in-portal

Index: branches/unlabeled/unlabeled-1.1.2/core/install/utf.php
===================================================================
--- branches/unlabeled/unlabeled-1.1.2/core/install/utf.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.1.2/core/install/utf.php (revision 8704)
@@ -0,0 +1,131 @@
+<?php
+
+// comment out this line to run the script
+die(' Should be enabled by the administrator! ');
+
+$start = getmicrotime();
+
+define('FULL_PATH', realpath(dirname(__FILE__)).'/../../');
+define('REL_PATH', '/core/install');
+include_once(FULL_PATH.'/core/kernel/startup.php');
+
+$application =& kApplication::Instance();
+$application->Init();
+
+header('Content-type: text/html; charset: utf-8');
+
+if (!defined('DEBUG_MODE') || !DEBUG_MODE) exit;
+
+$target_charset = 'utf8';
+$target_collation = 'utf8_general_ci';
+
+//$target_charset = 'latin1';
+//$target_collation = 'latin1_swedish_ci';
+
+ini_set('max_execution_time', 0);
+
+// Convert language translation
+$langs = $application->Conn->Query('SELECT * FROM '.TABLE_PREFIX.'Language', 'LanguageId');
+foreach ($langs as $lang_id => $a_lang) {
+ switch ( strtoupper($a_lang['Charset']) ) {
+ case 'WINDOWS-1251':
+ $langs[$lang_id]['mysql_charset'] = 'cp1251';
+ break;
+ default:
+ $langs[$lang_id]['mysql_charset'] = 'latin1';
+ }
+}
+
+print_pre($langs);
+
+//die();
+
+$query = 'ALTER DATABASE `'.SQL_DB.'` DEFAULT CHARACTER SET '.$target_charset.' COLLATE '.$target_collation;
+//$application->Conn->Query($query);
+
+$query = 'SHOW TABLE STATUS';
+$tables = $application->Conn->Query($query);
+
+foreach ($tables as $table_status)
+{
+ $table = $table_status['Name'];
+
+ if ($table_status['Collation'] != $target_collation) {
+ $sql = 'ALTER TABLE '.$table.' COLLATE '.$application->Conn->qstr($target_collation);
+ echo "$sql<br>\n";
+ $application->Conn->Query($sql);
+ }
+
+ echo "scanning $table<br>";
+
+ $columns = $application->Conn->Query('SHOW FULL COLUMNS FROM '.$table);
+ foreach ($columns as $a_column) {
+ if ($a_column['Collation'] != 'NULL') {
+ if ($a_column['Collation'] == $target_collation) {
+ echo "skipping ".$a_column['Field'].'<br>';
+ continue;
+ }
+
+ echo 'processing column '.$a_column['Field'].' ('.$a_column['Collation'].')<br>';
+
+// ALTER TABLE `inp_Addresses` ADD `utf_To` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `To` ;
+
+ // adding temporary UTF column
+ $new_def = $a_column['Type'].' CHARACTER SET '.$target_charset.' COLLATE '.$target_collation.' '.($a_column['Null'] == 'YES' ? 'NULL':'NOT NULL');
+ $q = 'ALTER TABLE `'.$table.'` ADD `utf_'.$a_column['Field'].'` '.$new_def.' AFTER `'.$a_column['Field'].'`;';
+ echo "$q<br>";
+ $application->Conn->Query($q);
+
+ // copying value to utf
+ if ($table == TABLE_PREFIX.'Phrase' && $a_column['Field'] == 'Translation') {
+ foreach ($langs as $lang_id => $a_lang) {
+ $cast = $a_lang['mysql_charset'];
+ if (!$cast) $cast = 'latin1';
+ $copy_def = 'CONVERT( CAST(BINARY('.$a_column['Field'].') AS CHAR CHARACTER SET '.$cast.') USING '.$target_charset.')';
+ $q = 'UPDATE `'.$table.'` SET `utf_'.$a_column['Field'].'` = '.$copy_def.' WHERE LanguageId = '.$lang_id;
+ echo "$q<br>";
+ $application->Conn->Query($q);
+ }
+ }
+ elseif (preg_match('/l([0-9]+)_.*/', $a_column['Field'], $matches)) {
+ $cast = $langs[$matches[1]]['mysql_charset'];
+ if (!$cast) $cast = 'latin1';
+ $copy_def = 'CONVERT( CAST(BINARY('.$a_column['Field'].') AS CHAR CHARACTER SET '.$cast.') USING '.$target_charset.')';
+ $q = 'UPDATE `'.$table.'` SET `utf_'.$a_column['Field'].'` = '.$copy_def;
+ echo "$q<br>";
+ $application->Conn->Query($q);
+ }
+ else {
+ $copy_def = 'BINARY(`'.$a_column['Field'].'`);';
+ $q = 'UPDATE `'.$table.'` SET `utf_'.$a_column['Field'].'` = '.$copy_def;
+ echo "$q<br>";
+ $application->Conn->Query($q);
+ }
+
+ // altering orignal field to utf
+ $q = 'ALTER TABLE `'.$table.'` CHANGE `'.$a_column['Field'].'` `'.$a_column['Field'].'` '.$new_def.';';
+ echo "$q<br>";
+ $application->Conn->Query($q);
+
+ // copying utf value back
+ $q = 'UPDATE `'.$table.'` SET `'.$a_column['Field'].'` = `utf_'.$a_column['Field'].'`;';
+ echo "$q<br>";
+ $application->Conn->Query($q);
+
+ // removing temporary UTF column
+ $q = 'ALTER TABLE `'.$table.'` DROP `utf_'.$a_column['Field'].'`;';
+ echo "$q<br>";
+ $application->Conn->Query($q);
+
+ }
+ }
+}
+
+$application->Conn->Query('UPDATE '.TABLE_PREFIX.'Language SET Charset = \''.$target_charset.'\'');
+
+function getmicrotime()
+{
+ list($usec, $sec) = explode(" ", microtime());
+ return ((float)$usec + (float)$sec);
+}
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.1.2/core/install/utf.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1.2.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline