Merge branch 'wip-MDL-59561-master' of git://github.com/abgreeve/moodle

This commit is contained in:
Andrew Nicols
2017-07-24 13:21:39 +08:00
2 changed files with 28 additions and 1 deletions
+14 -1
View File
@@ -823,7 +823,20 @@ class database_manager {
throw new ddl_exception('ddlunknownerror', null, 'add_index sql not generated');
}
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
try {
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
} catch (ddl_change_structure_exception $e) {
// There could be a problem with the index length related to the row format of the table.
// If we are using utf8mb4 and the row format is 'compact' or 'redundant' then we need to change it over to
// 'compressed' or 'dynamic'.
if (method_exists($this->mdb, 'convert_table_row_format')) {
$this->mdb->convert_table_row_format($xmldb_table->getName());
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
} else {
// It's some other problem that we are currently not handling.
throw $e;
}
}
}
/**
+14
View File
@@ -1917,4 +1917,18 @@ class mysqli_native_moodle_database extends moodle_database {
return true;
}
/**
* Converts a table to either 'Compressed' or 'Dynamic' row format.
*
* @param string $tablename Name of the table to convert to the new row format.
*/
public function convert_table_row_format($tablename) {
$currentrowformat = $this->get_row_format($tablename);
if ($currentrowformat == 'Compact' || $currentrowformat == 'Redundant') {
$rowformat = ($this->is_compressed_row_format_supported(false)) ? "ROW_FORMAT=Compressed" : "ROW_FORMAT=Dynamic";
$prefix = $this->get_prefix();
$this->change_database_structure("ALTER TABLE {$prefix}$tablename $rowformat");
}
}
}