Commit ca2b5406 authored by Robert Lyon's avatar Robert Lyon

Bug 1827445: Need to revert to old way during upgrade

Otherwise there is brokenness in upgrade

behatnotneeded

Change-Id: I1523ec044a9caecd52f5baa2a86308460ba6c284
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent bf4e742f
...@@ -1971,31 +1971,59 @@ function get_db_version() { ...@@ -1971,31 +1971,59 @@ function get_db_version() {
return $version; return $version;
} }
/**
* Check to see if table column exists by querying it and catching error if not
* This is a faster way than using the field_exists() function in lib/ddl.php
* NOTE: When doing an upgrade we fallback to check the table column in the old way to avoid
* inconsistent state before db_commit() is called.
*/
function db_column_exists($table, $field) { function db_column_exists($table, $field) {
global $DB_IGNORE_SQL_EXCEPTIONS; global $DB_IGNORE_SQL_EXCEPTIONS;
// We will check to see if a column exists by seeing if it throws an error or not
try { if (defined('INSTALLER')) {
$DB_IGNORE_SQL_EXCEPTIONS = true; // We do the check in the old way
get_column_sql("SELECT " . db_quote_identifier($field) . " FROM " . db_table_name($table) . " LIMIT 1"); require_once('ddl.php');
$DB_IGNORE_SQL_EXCEPTIONS = false; $table = new XMLDBTable($table);
return true; $field = new XMLDBField($field);
return field_exists($table, $field);
} }
catch (SQLException $e) { else {
return false; // We will check to see if a column exists by seeing if it throws an error or not
try {
$DB_IGNORE_SQL_EXCEPTIONS = true;
get_column_sql("SELECT " . db_quote_identifier($field) . " FROM " . db_table_name($table) . " LIMIT 1");
$DB_IGNORE_SQL_EXCEPTIONS = false;
return true;
}
catch (SQLException $e) {
return false;
}
} }
} }
/**
* Check to see if table exists by querying it and catching error if not
* This is a faster way than using the table_exists() function in lib/ddl.php
* NOTE: When doing an upgrade we fallback to check the table in the old way to avoid
* inconsistent state before db_commit() is called.
*/
function db_table_exists($table) { function db_table_exists($table) {
global $DB_IGNORE_SQL_EXCEPTIONS; global $DB_IGNORE_SQL_EXCEPTIONS;
// We will check to see if a table exists by seeing if it throws an error or not
// This is meant to be a faster way than using the table_exists() function in lib/ddl.php if (defined('INSTALLER')) {
try { // We do the check in the old way
$DB_IGNORE_SQL_EXCEPTIONS = true; require_once('ddl.php');
get_column_sql("SELECT 1 FROM " . db_table_name($table) . " LIMIT 1"); return table_exists(new XMLDBTable($table));
$DB_IGNORE_SQL_EXCEPTIONS = false;
return true;
} }
catch (SQLException $e) { else {
return false; try {
$DB_IGNORE_SQL_EXCEPTIONS = true;
get_column_sql("SELECT 1 FROM " . db_table_name($table) . " LIMIT 1");
$DB_IGNORE_SQL_EXCEPTIONS = false;
return true;
}
catch (SQLException $e) {
return false;
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment