mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
Detect CHAR + NOT NULL FIELDS + '' (empty) defaults. They shouldn't be in
XMLDB definitions at all. Convert the default to the proper one and output it via xmldb debug.
This commit is contained in:
parent
b794dc20c0
commit
b4464372af
@ -93,7 +93,7 @@ class XMLDBField extends XMLDBObject {
|
||||
$this->enumvalues[] = $value;
|
||||
}
|
||||
}
|
||||
$this->default = $default;
|
||||
$this->setDefault($default);
|
||||
|
||||
$this->previous = $previous;
|
||||
}
|
||||
@ -230,6 +230,13 @@ class XMLDBField extends XMLDBObject {
|
||||
* Set the field default
|
||||
*/
|
||||
function setDefault($default) {
|
||||
/// Check, warn and auto-fix '' (empty) defaults for CHAR NOT NULL columns, changing them
|
||||
/// to NULL so XMLDB will apply the proper default
|
||||
if ($this->type == XMLDB_TYPE_CHAR && $this->notnull && $default === '') {
|
||||
$this->errormsg = 'XMLDB has detected one CHAR NOT NULL column (' . $this->name . ") with '' (empty string) as DEFAULT value. This type of columns must have one meaningful DEFAULT declared or none (NULL). XMLDB have fixed it automatically changing it to none (NULL). The process will continue ok and proper defaults will be created accordingly with each DB requirements. Please fix it in source (XML and/or upgrade script) to avoid this message to be displayed.";
|
||||
$this->debug($this->errormsg);
|
||||
$default = NULL;
|
||||
}
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
@ -346,7 +353,7 @@ class XMLDBField extends XMLDBObject {
|
||||
}
|
||||
|
||||
if (isset($xmlarr['@']['DEFAULT'])) {
|
||||
$this->default = trim($xmlarr['@']['DEFAULT']);
|
||||
$this->setDefault(trim($xmlarr['@']['DEFAULT']));
|
||||
}
|
||||
|
||||
if (isset($xmlarr['@']['ENUM'])) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user