3 fixes character set and engine=InnoDB.. in Mysql
7 class Pman_Core_UpdateDatabase_MysqlEngineCharset {
10 var $schema = array();
14 function __construct()
16 // this might get run before we have imported the database
17 // and hence not have any db.
18 $this->loadIniFiles(); //?? shared???
21 $dbo = DB_DataObject::factory('core_enum');
25 if (is_a($dbo, 'PDO_DataObject')) {
27 $this->views = $dbo->generator()->introspection()->getListOf('views');
29 $db = DB_DataObject::factory('core_enum')->getDatabaseConnection();
30 $this->views = $db->getListOf( 'views'); // needs updated pear...
33 // update the engine first - get's around 1000 character limit on indexes..cd
34 // however - Innodb does not support fulltext indexes, so this may fail...
35 $this->updateEngine();
37 $this->updateCharacterSet();
41 function loadIniFiles()
43 // will create the combined ini cache file for the running user.
45 $ff = HTML_FlexyFramework::get();
46 $ff->generateDataobjectsCache(true);
47 $this->dburl = parse_url($ff->database);
50 $dbini = 'ini_'. basename($this->dburl['path']);
53 $iniCache = isset( $ff->PDO_DataObject) ? $ff->PDO_DataObject['schema_location'] : $ff->DB_DataObject[$dbini];
54 if (!file_exists($iniCache)) {
58 $this->schema = parse_ini_file($iniCache, true);
59 $this->links = parse_ini_file(preg_replace('/\.ini$/', '.links.ini', $iniCache), true);
65 function updateCharacterSet()
67 $views = $this->views;
70 foreach (array_keys($this->schema) as $tbl){
72 if(strpos($tbl, '__keys') !== false ){
76 if(in_array($tbl , $views)) {
80 $ce = DB_DataObject::factory('core_enum');
84 CCSA.character_set_name csname,
85 CCSA.collation_name collatename
87 information_schema.`TABLES` T,
88 information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
90 CCSA.collation_name = T.table_collation
92 T.table_schema = DATABASE() -- COLLATE utf8_general_ci
94 T.table_name = '{$tbl}' -- COLLATE utf8_general_ci
101 if($ce->csname == 'utf8' && $ce->collatename == 'utf8_general_ci'){
102 echo "utf8: SKIP $tbl\n";
105 // this used to be utf8_unicode_ci
106 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
108 $ce = DB_DataObject::factory('core_enum');
109 // not sure why, but convert to does not actually change the 'charset=' bit..
110 $ce->query("ALTER TABLE `$tbl` CHARSET=utf8");
111 $ce->query("ALTER TABLE `{$tbl}` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
112 echo "utf8: FIXED {$tbl}\n";
116 function updateEngine()
118 $db = DB_DataObject::factory('core_enum');
119 $db->query("show variables like 'innodb_file_per_table'");
123 $pg = HTML_FlexyFramework::get()->page;
125 if (empty($pg->opts['skip-mysql-checks'])) {
126 if ($db->Value == 'OFF') {
127 die("Error: set innodb_file_per_table = 1 in my.cnf\n\n");
133 // get a list of table views...
134 // innodb in single files is far more efficient that MYD or one big innodb file.
135 // first check if database is using this format.
139 $views = $this->views;
142 foreach (array_keys($this->schema) as $tbl){
144 if(strpos($tbl, '__keys') !== false ){
148 if(in_array($tbl , $views)) {
152 $ce = DB_DataObject::factory('core_enum');
158 information_schema.tables
160 table_schema= DATABASE()
162 table_name = '{$tbl}'
168 //AWS is returning captials?
169 $engine = isset($ce->engine) ? $ce->engine : $ce->ENGINE;
171 if($engine == 'InnoDB' ){
172 echo "InnoDB: SKIP $tbl\n";
175 if($engine == 'ndbcluster' ){
176 echo "ndbcluster: SKIP $tbl\n";
180 // should really determine if we are running in cluster ready ...
182 // this used to be utf8_unicode_ci
183 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
185 $ce = DB_DataObject::factory('core_enum');
186 $ce->query("ALTER TABLE `$tbl` ENGINE=InnoDB");
187 echo "InnoDB: FIXED {$tbl}\n";