mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
Prevent add_field() to work if we are adding one not null field
to one non-empty table without specifying its default value. Merged from MOODLE_17_STABLE
This commit is contained in:
parent
e0251aea34
commit
8914508a4b
@ -678,6 +678,12 @@ function add_field($table, $field, $continue=true, $feedback=true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/// If NOT NULL and no default given, check the table is empty
|
||||
if ($field->getNotNull() && $field->getDefault() === NULL && count_records($table->getName())) {
|
||||
debugging('Field ' . $field->getName() . ' cannot be added. Not null fields added to non empty tables require default value. Create skipped', DEBUG_DEVELOPER);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!$sqlarr = $table->getAddFieldSQL($CFG->dbtype, $CFG->prefix, $field, false)) {
|
||||
return true; //Empty array = nothing to do = no error
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user