* -- {tablename}_trigger_{optional_string}_before_update_{column_name}(OLD.column, NEW.column}
* -- {tablename}_trigger_{optional_string}_before_insert_{column_name}(OLD.column}
*
- *
*
+ * ------- Importing with triggers disabled.
+ *
+ * SET @DISABLE_TRIGGER=1; (or anything you like except NULL)
+ * do imports
+ * SET @DISABLE_TRIGGER=NULL;
+ *
+ * ------ Call a method disabling a particular set of triggers
+ * SET @DISABLE_TRIGGER_the_table_name=1; (or anything you like except NULL)
+ * do action
+ * SET @DISABLE_TRIGGER_the_table_name=NULL;*
*/
class Pman_Core_UpdateDatabase_MysqlLinks {
$this->loadIniFiles();
$this->updateTableComments();
+
+ $this->updateCharacterSet();
+ $this->updateEngine();
+
$ff = HTML_FlexyFramework::get();
if (!empty($ff->Pman['enable_trigger_tests'])) {
foreach($map as $k=>$v) {
$fks[] = "$k=$v";
}
-
$fkstr = $tc . ' FK(' . implode("\n", $fks) .')';
-
- echo "$fkstr \n $tbl";
-
- exit;
if ($q->TABLE_COMMENT == $fkstr) {
return;
}
-
-
$q = DB_DAtaObject::factory('core_enum');
$q->query("ALTER TABLE $tbl COMMENT = '{$q->escape($fkstr)}'");
BEFORE DELETE ON `{$target_table}`
FOR EACH ROW
BEGIN
- DECLARE mid INT(11);
-
+ DECLARE mid INT(11);
+ IF (@DISABLE_TRIGGER IS NULL AND @DISABLE_TRIGGER_{$target_table} IS NULL ) THEN
";
foreach($sources as $source=>$target) {
}
$trigger .= "
+ END IF;
END
";
FOR EACH ROW
BEGIN
DECLARE mid INT(11);
-
+ IF (@DISABLE_TRIGGER IS NULL AND @DISABLE_TRIGGER_{$tbl} IS NULL ) THEN
";
foreach($map as $source_col=>$target) {
}
$trigger .= "
+ END IF;
END
";
FOR EACH ROW
BEGIN
DECLARE mid INT(11);
-
+ IF (@DISABLE_TRIGGER IS NULL AND @DISABLE_TRIGGER_{$tbl} IS NULL ) THEN
";
foreach($map as $source_col=>$target) {
}
$trigger .= "
+ END IF;
END
";
return $ret;
}
+ function updateCharacterSet()
+ {
+ foreach (array_keys($this->schema) as $tbl){
+
+ if(strpos($tbl, '__keys') !== false ){
+ continue;
+ }
+
+ $ce = DB_DataObject::factory('core_enum');
+
+ $ce->query("
+ SELECT
+ CCSA.character_set_name csname,
+ CCSA.collation_name collatename
+ FROM
+ information_schema.`TABLES` T,
+ information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
+ WHERE
+ CCSA.collation_name = T.table_collation
+ AND
+ T.table_schema = '{$ce->database()}' -- COLLATE utf8_general_ci
+ AND
+ T.table_name = '{$tbl}' -- COLLATE utf8_general_ci
+ ");
+
+ $ce->fetch();
+
+ if($ce->csname == 'utf8' && $ce->collatename == 'utf8_general_ci'){
+ echo "$tbl is Already utf8 \n";
+ continue;
+ }
+ // 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.
+
+ $ce = DB_DataObject::factory('core_enum');
+ $ce->query("ALTER TABLE {$tbl} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
+ echo "FIXED utf8 on {$tbl}\n";
+
+ }
+ }
+ function updateEngine()
+ {
+ foreach (array_keys($this->schema) as $tbl){
+
+ if(strpos($tbl, '__keys') !== false ){
+ continue;
+ }
+
+ $ce = DB_DataObject::factory('core_enum');
+
+ $ce->query("select engine from information_schema.tables where table_schema='hydra' and table_name = 'core_enum'");
+
+ $ce->fetch();
+
+ if($ce->engine == 'InnoDB' ){
+ echo "SKIP engine on $tbl - already InnoDB\n";
+ continue;
+ }
+ // 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.
+
+ $ce = DB_DataObject::factory('core_enum');
+ $ce->query("ALTER TABLE $tbl ENGINE=InnoDB");
+ echo "FIXED engine on {$tbl}\n";
+
+ }
+ }
}