1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-30 11:20:25 +02:00

Permissive field validation in db_verify

Even if it's a new installation of e107, `db_verify` will be too strict in
validating database field defaults that are equivalent to each other.

This can happen on some MySQL or MariaDB servers that correct the field
definitions, which were not strictly correct in the table structures built into
e107 in the first place.

This commit introduces db_verify::validateFieldPermissive(), a
backwards-compatible way to validate database field defaults.  It works
regardless of whether the MySQL server stores a corrected representation of the
schema and does not require fixing the schema in any existing table structure
files.

Fixes: #2998
This commit is contained in:
Nick Liu
2018-01-23 07:48:24 -06:00
parent 0995810249
commit 9a5ac5b21a

View File

@@ -131,6 +131,29 @@ class db_verify
}
/**
* Permissive field validation
*/
private function validateFieldPermissive($expected, $actual)
{
// Permit actual text types that default to null even when
// expected does not explicitly default to null
if(0 === strcasecmp($expected['type'], $actual['type']) &&
1 === preg_match('/[A-Z]*TEXT/i', $expected['type']) &&
0 === strcasecmp($actual['default'], "DEFAULT NULL"))
{
$expected['default'] = $actual['default'];
}
// Loosely typed default value for int-like types
if(1 === preg_match('/[A-Z]*INT/i', $expected['type']))
{
$expected['default'] = preg_replace("/DEFAULT '(\d+)'/i", 'DEFAULT $1', $expected['default']);
$actual['default'] = preg_replace("/DEFAULT '(\d+)'/i", 'DEFAULT $1', $actual['default'] );
}
return !count($off = array_diff_assoc($expected, $actual));
}
/**
@@ -347,7 +370,7 @@ class db_verify
$this->results[$tbl][$field]['_valid'] = $info;
$this->results[$tbl][$field]['_file'] = $selection;
}
elseif(count($off = array_diff_assoc($info,$sqlFieldData[$field])))
elseif(!$this->validateFieldPermissive($info, $sqlFieldData[$field]))
{
$this->errors[$tbl]['_status'] = 'mismatch';
$this->results[$tbl][$field]['_status'] = 'mismatch';
@@ -1671,4 +1694,4 @@ function table_list()
*/
?>
?>