Merge branch 'w36_MDL-35080_m24_weirdtables' of git://github.com/skodak/moodle

This commit is contained in:
Aparup Banerjee 2012-09-03 17:09:23 +08:00
commit bb048c6afa

View File

@ -30,6 +30,51 @@
defined('MOODLE_INTERNAL') || die();
/**
* Returns all non-view and non-temp tables with sane names.
* Prints list of non-supported tables using $OUTPUT->notification()
*
* @return array
*/
function upgrade_mysql_get_supported_tables() {
global $OUTPUT, $DB;
$tables = array();
$patprefix = str_replace('_', '\\_', $DB->get_prefix());
$pregprefix = preg_quote($DB->get_prefix(), '/');
$sql = "SHOW FULL TABLES LIKE '$patprefix%'";
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $record) {
$record = array_change_key_case((array)$record, CASE_LOWER);
$type = $record['table_type'];
unset($record['table_type']);
$fullname = array_shift($record);
if ($pregprefix === '') {
$name = $fullname;
} else {
$count = null;
$name = preg_replace("/^$pregprefix/", '', $fullname, -1, $count);
if ($count !== 1) {
continue;
}
}
if (!preg_match("/^[a-z][a-z0-9_]*$/", $name)) {
echo $OUTPUT->notification("Database table with invalid name '$fullname' detected, skipping.", 'notifyproblem');
continue;
}
if ($type === 'VIEW') {
echo $OUTPUT->notification("Unsupported database table view '$fullname' detected, skipping.", 'notifyproblem');
continue;
}
$tables[$name] = $name;
}
$rs->close();
return $tables;
}
/**
* Remove all signed numbers from current database - mysql only.
@ -50,7 +95,7 @@ function upgrade_mysql_fix_unsigned_columns() {
$pbar = new progress_bar('mysqlconvertunsigned', 500, true);
$prefix = $DB->get_prefix();
$tables = $DB->get_tables();
$tables = upgrade_mysql_get_supported_tables();
$tablecount = count($tables);
$i = 0;
@ -115,7 +160,7 @@ function upgrade_mysql_fix_lob_columns() {
$pbar = new progress_bar('mysqlconvertlobs', 500, true);
$prefix = $DB->get_prefix();
$tables = $DB->get_tables();
$tables = upgrade_mysql_get_supported_tables();
asort($tables);
$tablecount = count($tables);