3 fixes character set and engine=InnoDB.. in Mysql
7 class Pman_Core_UpdateDatabase_MysqlEngineCharset {
10 var $schema = array();
14 function __construct()
17 $this->loadIniFiles(); //?? shared???
19 $dbo = DB_DataObject::factory('core_enum');
20 if (is_a($dbo, 'PDO_DataObject')) {
22 $this->views = $dbo->generator()->introspection()->getListOf('views');
24 $db = DB_DataObject::factory('core_enum')->getDatabaseConnection();
25 $this->views = $db->getListOf( 'views'); // needs updated pear...
28 // update the engine first - get's around 1000 character limit on indexes..cd
29 // however - Innodb does not support fulltext indexes, so this may fail...
30 $this->updateEngine();
32 $this->updateCharacterSet();
37 function loadIniFiles()
39 // will create the combined ini cache file for the running user.
41 $ff = HTML_FlexyFramework::get();
42 $ff->generateDataobjectsCache(true);
43 $this->dburl = parse_url($ff->database);
46 $dbini = 'ini_'. basename($this->dburl['path']);
49 $iniCache = isset( $ff->PDO_DataObject) ? $ff->PDO_DataObject['schema_location'] : $ff->DB_DataObject[$dbini];
50 if (!file_exists($iniCache)) {
54 $this->schema = parse_ini_file($iniCache, true);
55 $this->links = parse_ini_file(preg_replace('/\.ini$/', '.links.ini', $iniCache), true);
61 function updateCharacterSet()
63 $views = $this->views;
66 foreach (array_keys($this->schema) as $tbl){
68 if(strpos($tbl, '__keys') !== false ){
72 if(in_array($tbl , $views)) {
76 $ce = DB_DataObject::factory('core_enum');
80 CCSA.character_set_name csname,
81 CCSA.collation_name collatename
83 information_schema.`TABLES` T,
84 information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
86 CCSA.collation_name = T.table_collation
88 T.table_schema = DATABASE() -- COLLATE utf8_general_ci
90 T.table_name = '{$tbl}' -- COLLATE utf8_general_ci
97 if($ce->csname == 'utf8' && $ce->collatename == 'utf8_general_ci'){
98 echo "utf8: SKIP $tbl\n";
101 // this used to be utf8_unicode_ci
102 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
104 $ce = DB_DataObject::factory('core_enum');
105 // not sure why, but convert to does not actually change the 'charset=' bit..
106 $ce->query("ALTER TABLE $tbl CHARSET=utf8");
107 $ce->query("ALTER TABLE {$tbl} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
108 echo "utf8: FIXED {$tbl}\n";
112 function updateEngine()
114 $db = DB_DataObject::factory('core_enum');
115 $db->query("show variables like 'innodb_file_per_table'");
118 $pg = HTML_FlexyFramework::get()->page;
120 if (empty($pg->opts['skip-mysql-checks'])) {
121 if ($db->Value == 'OFF') {
122 die("Error: set innodb_file_per_table = 1 in my.cnf\n\n");
128 // get a list of table views...
129 // innodb in single files is far more efficient that MYD or one big innodb file.
130 // first check if database is using this format.
134 $views = $this->views;
137 foreach (array_keys($this->schema) as $tbl){
139 if(strpos($tbl, '__keys') !== false ){
143 if(in_array($tbl , $views)) {
147 $ce = DB_DataObject::factory('core_enum');
153 information_schema.tables
155 table_schema= DATABASE()
157 table_name = '{$tbl}'
163 //AWS is returning captials?
164 $engine = isset($ce->engine) ? $ce->engine : $ce->ENGINE;
166 if($engine == 'InnoDB' ){
167 echo "InnoDB: SKIP $tbl\n";
170 if($engine == 'ndbcluster' ){
171 echo "ndbcluster: SKIP $tbl\n";
175 // should really determine if we are running in cluster ready ...
177 // this used to be utf8_unicode_ci
178 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
180 $ce = DB_DataObject::factory('core_enum');
181 $ce->query("ALTER TABLE $tbl ENGINE=InnoDB");
182 echo "InnoDB: FIXED {$tbl}\n";