3 fixes character set and engine=InnoDB.. in Mysql
7 class Pman_Core_UpdateDatabase_MysqlEngineCharset {
13 function __construct()
16 $this->loadIniFiles(); //?? shared???
18 // update the engine first - get's around 1000 character limit on indexes..cd
19 // however - Innodb does not support fulltext indexes, so this may fail...
20 $this->updateEngine();
22 $this->updateCharacterSet();
27 function loadIniFiles()
29 // will create the combined ini cache file for the running user.
31 $ff = HTML_FlexyFramework::get();
32 $ff->generateDataobjectsCache(true);
33 $this->dburl = parse_url($ff->database);
35 $dbini = 'ini_'. basename($this->dburl['path']);
38 $iniCache = $ff->DB_DataObject[$dbini];
40 $this->schema = parse_ini_file($iniCache, true);
41 $this->links = parse_ini_file(preg_replace('/\.ini$/', '.links.ini', $iniCache), true);
47 function updateCharacterSet()
49 $db = DB_DataObject::factory('core_enum')->getDatabaseConnection();
50 $views = $db->getListOf( 'views');
53 foreach (array_keys($this->schema) as $tbl){
55 if(strpos($tbl, '__keys') !== false ){
59 if(in_array($tbl , $views)) {
63 $ce = DB_DataObject::factory('core_enum');
67 CCSA.character_set_name csname,
68 CCSA.collation_name collatename
70 information_schema.`TABLES` T,
71 information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
73 CCSA.collation_name = T.table_collation
75 T.table_schema = '{$ce->database()}' -- COLLATE utf8_general_ci
77 T.table_name = '{$tbl}' -- COLLATE utf8_general_ci
82 if($ce->csname == 'utf8' && $ce->collatename == 'utf8_general_ci'){
83 echo "utf8: SKIP $tbl\n";
86 // this used to be utf8_unicode_ci
87 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
89 $ce = DB_DataObject::factory('core_enum');
90 // not sure why, but convert to does not actually change the 'charset=' bit..
91 $ce->query("ALTER TABLE $tbl CHARSET=utf8");
92 $ce->query("ALTER TABLE {$tbl} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
93 echo "utf8: FIXED {$tbl}\n";
97 function updateEngine()
99 $db = DB_DataObject::factory('core_enum');
100 $db->query("show variables like 'innodb_file_per_table'");
102 if ($db->Value == 'OFF') {
103 die("Error: set innodb_file_per_table = 1 in my.cnf\n\n");
106 // get a list of table views...
107 // innodb in single files is far more efficient that MYD or one big innodb file.
108 // first check if database is using this format.
112 $db = DB_DataObject::factory('core_enum')->getDatabaseConnection();
113 $views = $db->getListOf( 'views');
118 foreach (array_keys($this->schema) as $tbl){
120 if(strpos($tbl, '__keys') !== false ){
123 if(in_array($tbl , $views)) {
127 $ce = DB_DataObject::factory('core_enum');
129 $ce->query("select engine from information_schema.tables where table_schema='{$ce->database()}' and table_name = '{$tbl}'");
133 if($ce->engine == 'InnoDB' ){
134 echo "InnoDB: SKIP $tbl\n";
137 // this used to be utf8_unicode_ci
138 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
140 $ce = DB_DataObject::factory('core_enum');
141 $ce->query("ALTER TABLE $tbl ENGINE=InnoDB");
142 echo "InnoDB: FIXED {$tbl}\n";