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.
19 $this->loadIniFiles(); //?? shared???
20 } catch(PDO_DataObject_Exception_InvalidConfig $e) {
21 echo "SKipping MysqlEngineCharse - no database yet\n";
25 $dbo = DB_DataObject::factory('core_enum');
26 if (is_a($dbo, 'PDO_DataObject')) {
28 $this->views = $dbo->generator()->introspection()->getListOf('views');
30 $db = DB_DataObject::factory('core_enum')->getDatabaseConnection();
31 $this->views = $db->getListOf( 'views'); // needs updated pear...
34 // update the engine first - get's around 1000 character limit on indexes..cd
35 // however - Innodb does not support fulltext indexes, so this may fail...
36 $this->updateEngine();
38 $this->updateCharacterSet();
43 function loadIniFiles()
45 // will create the combined ini cache file for the running user.
47 $ff = HTML_FlexyFramework::get();
48 $ff->generateDataobjectsCache(true);
49 $this->dburl = parse_url($ff->database);
52 $dbini = 'ini_'. basename($this->dburl['path']);
55 $iniCache = isset( $ff->PDO_DataObject) ? $ff->PDO_DataObject['schema_location'] : $ff->DB_DataObject[$dbini];
56 if (!file_exists($iniCache)) {
60 $this->schema = parse_ini_file($iniCache, true);
61 $this->links = parse_ini_file(preg_replace('/\.ini$/', '.links.ini', $iniCache), true);
67 function updateCharacterSet()
69 $views = $this->views;
72 foreach (array_keys($this->schema) as $tbl){
74 if(strpos($tbl, '__keys') !== false ){
78 if(in_array($tbl , $views)) {
82 $ce = DB_DataObject::factory('core_enum');
86 CCSA.character_set_name csname,
87 CCSA.collation_name collatename
89 information_schema.`TABLES` T,
90 information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
92 CCSA.collation_name = T.table_collation
94 T.table_schema = DATABASE() -- COLLATE utf8_general_ci
96 T.table_name = '{$tbl}' -- COLLATE utf8_general_ci
103 if($ce->csname == 'utf8' && $ce->collatename == 'utf8_general_ci'){
104 echo "utf8: SKIP $tbl\n";
107 // this used to be utf8_unicode_ci
108 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
110 $ce = DB_DataObject::factory('core_enum');
111 // not sure why, but convert to does not actually change the 'charset=' bit..
112 $ce->query("ALTER TABLE $tbl CHARSET=utf8");
113 $ce->query("ALTER TABLE {$tbl} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
114 echo "utf8: FIXED {$tbl}\n";
118 function updateEngine()
120 $db = DB_DataObject::factory('core_enum');
121 $db->query("show variables like 'innodb_file_per_table'");
124 $pg = HTML_FlexyFramework::get()->page;
126 if (empty($pg->opts['skip-mysql-checks'])) {
127 if ($db->Value == 'OFF') {
128 die("Error: set innodb_file_per_table = 1 in my.cnf\n\n");
134 // get a list of table views...
135 // innodb in single files is far more efficient that MYD or one big innodb file.
136 // first check if database is using this format.
140 $views = $this->views;
143 foreach (array_keys($this->schema) as $tbl){
145 if(strpos($tbl, '__keys') !== false ){
149 if(in_array($tbl , $views)) {
153 $ce = DB_DataObject::factory('core_enum');
159 information_schema.tables
161 table_schema= DATABASE()
163 table_name = '{$tbl}'
169 //AWS is returning captials?
170 $engine = isset($ce->engine) ? $ce->engine : $ce->ENGINE;
172 if($engine == 'InnoDB' ){
173 echo "InnoDB: SKIP $tbl\n";
176 if($engine == 'ndbcluster' ){
177 echo "ndbcluster: SKIP $tbl\n";
181 // should really determine if we are running in cluster ready ...
183 // this used to be utf8_unicode_ci
184 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
186 $ce = DB_DataObject::factory('core_enum');
187 $ce->query("ALTER TABLE $tbl ENGINE=InnoDB");
188 echo "InnoDB: FIXED {$tbl}\n";