X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=UpdateDatabase%2FMysqlEngineCharset.php;h=ba81c6361b8648ad4fdeac6ce989e19a0cb77c96;hb=3dfa28ee12e72e27f69a7734bef807c2628e5d53;hp=20a1dc733b93411226f50ee2552277a00d1cf8c0;hpb=4fe8b23a82e5d21f1f7ff9d8cfb1e4206e67d0bb;p=Pman.Core diff --git a/UpdateDatabase/MysqlEngineCharset.php b/UpdateDatabase/MysqlEngineCharset.php index 20a1dc73..ba81c636 100644 --- a/UpdateDatabase/MysqlEngineCharset.php +++ b/UpdateDatabase/MysqlEngineCharset.php @@ -7,21 +7,35 @@ class Pman_Core_UpdateDatabase_MysqlEngineCharset { var $dburl; - var $schema; - var $links; + var $schema = array(); + var $links = array(); + var $views = array(); function __construct() { - + // this might get run before we have imported the database + // and hence not have any db. $this->loadIniFiles(); //?? shared??? + + $dbo = DB_DataObject::factory('core_enum'); + + + + if (is_a($dbo, 'PDO_DataObject')) { + + $this->views = $dbo->generator()->introspection()->getListOf('views'); + } else { + $db = DB_DataObject::factory('core_enum')->getDatabaseConnection(); + $this->views = $db->getListOf( 'views'); // needs updated pear... + } + // update the engine first - get's around 1000 character limit on indexes..cd // however - Innodb does not support fulltext indexes, so this may fail... $this->updateEngine(); - + $this->updateCharacterSet(); - - + } function loadIniFiles() @@ -32,10 +46,14 @@ class Pman_Core_UpdateDatabase_MysqlEngineCharset { $ff->generateDataobjectsCache(true); $this->dburl = parse_url($ff->database); + $dbini = 'ini_'. basename($this->dburl['path']); - $iniCache = $ff->DB_DataObject[$dbini]; + $iniCache = isset( $ff->PDO_DataObject) ? $ff->PDO_DataObject['schema_location'] : $ff->DB_DataObject[$dbini]; + if (!file_exists($iniCache)) { + return; + } $this->schema = parse_ini_file($iniCache, true); $this->links = parse_ini_file(preg_replace('/\.ini$/', '.links.ini', $iniCache), true); @@ -46,8 +64,7 @@ class Pman_Core_UpdateDatabase_MysqlEngineCharset { function updateCharacterSet() { - $db = DB_DataObject::factory('core_enum')->getDatabaseConnection(); - $views = $db->getListOf( 'views'); + $views = $this->views; foreach (array_keys($this->schema) as $tbl){ @@ -72,12 +89,14 @@ class Pman_Core_UpdateDatabase_MysqlEngineCharset { WHERE CCSA.collation_name = T.table_collation AND - T.table_schema = '{$ce->database()}' -- COLLATE utf8_general_ci + T.table_schema = DATABASE() -- COLLATE utf8_general_ci AND T.table_name = '{$tbl}' -- COLLATE utf8_general_ci "); - $ce->fetch(); + if (!$ce->fetch()) { + continue; + } if($ce->csname == 'utf8' && $ce->collatename == 'utf8_general_ci'){ echo "utf8: SKIP $tbl\n"; @@ -98,42 +117,68 @@ class Pman_Core_UpdateDatabase_MysqlEngineCharset { { $db = DB_DataObject::factory('core_enum'); $db->query("show variables like 'innodb_file_per_table'"); + $db->fetch(); - if ($db->Value == 'OFF') { - die("Error: set innodb_file_per_table = 1 in my.cnf\n\n"); + + $pg = HTML_FlexyFramework::get()->page; + + if (empty($pg->opts['skip-mysql-checks'])) { + if ($db->Value == 'OFF') { + die("Error: set innodb_file_per_table = 1 in my.cnf\n\n"); + } + } + // get a list of table views... // innodb in single files is far more efficient that MYD or one big innodb file. // first check if database is using this format. - $db = DB_DataObject::factory('core_enum')->getDatabaseConnection(); - $views = $db->getListOf( 'views'); - - - + $views = $this->views; + echo "a3\n"; foreach (array_keys($this->schema) as $tbl){ if(strpos($tbl, '__keys') !== false ){ continue; } + if(in_array($tbl , $views)) { continue; } $ce = DB_DataObject::factory('core_enum'); - $ce->query("select engine from information_schema.tables where table_schema='{$ce->database()}' and table_name = '{$tbl}'"); + $ce->query(" + select + engine + from + information_schema.tables + where + table_schema= DATABASE() + and + table_name = '{$tbl}' + "); - $ce->fetch(); + if (!$ce->fetch()) { + continue; + } + //AWS is returning captials? + $engine = isset($ce->engine) ? $ce->engine : $ce->ENGINE; - if($ce->engine == 'InnoDB' ){ + if($engine == 'InnoDB' ){ echo "InnoDB: SKIP $tbl\n"; continue; } + if($engine == 'ndbcluster' ){ + echo "ndbcluster: SKIP $tbl\n"; + continue; + } + + // should really determine if we are running in cluster ready ... + // this used to be utf8_unicode_ci //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.