mirror of
https://github.com/moodle/moodle.git
synced 2025-03-19 23:20:09 +01:00
Instead of looking for current default value, fetch from
the generator the *real* default value that the table will have.
This commit is contained in:
parent
2c5e52e286
commit
b794dc20c0
@ -319,7 +319,7 @@ function field_exists($table, $field) {
|
||||
$exists = false;
|
||||
}
|
||||
|
||||
/// Re-set original debug
|
||||
/// Re-set original debug
|
||||
$db->debug = $olddbdebug;
|
||||
|
||||
return $exists;
|
||||
@ -348,7 +348,7 @@ function index_exists($table, $index) {
|
||||
$exists = false;
|
||||
}
|
||||
|
||||
/// Re-set original debug
|
||||
/// Re-set original debug
|
||||
$db->debug = $olddbdebug;
|
||||
|
||||
return $exists;
|
||||
@ -746,14 +746,20 @@ function add_field($table, $field, $continue=true, $feedback=true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Load the needed generator
|
||||
$classname = 'XMLDB' . $CFG->dbtype;
|
||||
$generator = new $classname();
|
||||
$generator->setPrefix($CFG->prefix);
|
||||
|
||||
/// Check the field doesn't exist
|
||||
if (field_exists($table, $field)) {
|
||||
debugging('Field ' . $field->getName() . ' exists. Create skipped', DEBUG_DEVELOPER);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// If NOT NULL and no default given, check the table is empty
|
||||
if ($field->getNotNull() && $field->getDefault() === NULL && count_records($table->getName())) {
|
||||
/// If NOT NULL and no default given (we ask the generator about the
|
||||
/// *real* default that will be used) check the table is empty
|
||||
if ($field->getNotNull() && $generator->getDefaultValue($field) === 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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user