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');
22 } catch(PDO_DataObject_Exception_InvalidConfig $e) {
23 echo "SKipping MysqlEngineCharse - no database yet\n";
28 if (is_a($dbo, 'PDO_DataObject')) {
30 $this->views = $dbo->generator()->introspection()->getListOf('views');
32 $db = DB_DataObject::factory('core_enum')->getDatabaseConnection();
33 $this->views = $db->getListOf( 'views'); // needs updated pear...
36 // update the engine first - get's around 1000 character limit on indexes..cd
37 // however - Innodb does not support fulltext indexes, so this may fail...
38 $this->updateEngine();
40 $this->updateCharacterSet();
45 function loadIniFiles()
47 // will create the combined ini cache file for the running user.
49 $ff = HTML_FlexyFramework::get();
50 $ff->generateDataobjectsCache(true);
51 $this->dburl = parse_url($ff->database);
54 $dbini = 'ini_'. basename($this->dburl['path']);
57 $iniCache = isset( $ff->PDO_DataObject) ? $ff->PDO_DataObject['schema_location'] : $ff->DB_DataObject[$dbini];
58 if (!file_exists($iniCache)) {
62 $this->schema = parse_ini_file($iniCache, true);
63 $this->links = parse_ini_file(preg_replace('/\.ini$/', '.links.ini', $iniCache), true);
69 function updateCharacterSet()
71 $views = $this->views;
74 foreach (array_keys($this->schema) as $tbl){
76 if(strpos($tbl, '__keys') !== false ){
80 if(in_array($tbl , $views)) {
84 $ce = DB_DataObject::factory('core_enum');
88 CCSA.character_set_name csname,
89 CCSA.collation_name collatename
91 information_schema.`TABLES` T,
92 information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
94 CCSA.collation_name = T.table_collation
96 T.table_schema = DATABASE() -- COLLATE utf8_general_ci
98 T.table_name = '{$tbl}' -- COLLATE utf8_general_ci
105 if($ce->csname == 'utf8' && $ce->collatename == 'utf8_general_ci'){
106 echo "utf8: SKIP $tbl\n";
109 // this used to be utf8_unicode_ci
110 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
112 $ce = DB_DataObject::factory('core_enum');
113 // not sure why, but convert to does not actually change the 'charset=' bit..
114 $ce->query("ALTER TABLE $tbl CHARSET=utf8");
115 $ce->query("ALTER TABLE {$tbl} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
116 echo "utf8: FIXED {$tbl}\n";
120 function updateEngine()
122 $db = DB_DataObject::factory('core_enum');
123 $db->query("show variables like 'innodb_file_per_table'");
126 $pg = HTML_FlexyFramework::get()->page;
128 if (empty($pg->opts['skip-mysql-checks'])) {
129 if ($db->Value == 'OFF') {
130 die("Error: set innodb_file_per_table = 1 in my.cnf\n\n");
136 // get a list of table views...
137 // innodb in single files is far more efficient that MYD or one big innodb file.
138 // first check if database is using this format.
142 $views = $this->views;
145 foreach (array_keys($this->schema) as $tbl){
147 if(strpos($tbl, '__keys') !== false ){
151 if(in_array($tbl , $views)) {
155 $ce = DB_DataObject::factory('core_enum');
161 information_schema.tables
163 table_schema= DATABASE()
165 table_name = '{$tbl}'
171 //AWS is returning captials?
172 $engine = isset($ce->engine) ? $ce->engine : $ce->ENGINE;
174 if($engine == 'InnoDB' ){
175 echo "InnoDB: SKIP $tbl\n";
178 if($engine == 'ndbcluster' ){
179 echo "ndbcluster: SKIP $tbl\n";
183 // should really determine if we are running in cluster ready ...
185 // this used to be utf8_unicode_ci
186 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
188 $ce = DB_DataObject::factory('core_enum');
189 $ce->query("ALTER TABLE $tbl ENGINE=InnoDB");
190 echo "InnoDB: FIXED {$tbl}\n";