Skip to content
Browse files

Merge branch 'w36_MDL-35080_m23_weirdtables' of git://github.com/skod…

…ak/moodle into MOODLE_23_STABLE
  • Loading branch information...
2 parents 8169e2f + 9817f08 commit 90c499dbca48eb9a5b645e7f4f7276892bdb7c7e @nebgor nebgor committed Sep 3, 2012
Showing with 47 additions and 2 deletions.
  1. +47 −2 lib/db/upgradelib.php
View
49 lib/db/upgradelib.php
@@ -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);

0 comments on commit 90c499d

Please sign in to comment.
Something went wrong with that request. Please try again.