MDL-45134 adminlib: No more validation error when a config file is not set

When the destination draft area existed and the user draft area has not
been used, and thus does not exist, an error was displayed to the user
saying that they could not save the setting.

This was intended to handle the cases where the draft area disappears
and would overwrite the content of the destination area, deleting
all its content. But now we do not prompt with an error when
overwriting empty with empty.
This commit is contained in:
Frederic Massart
2014-04-23 12:40:50 +08:00
parent b6ac19d4d9
commit ffc6df1ba2
+4 -8
View File
@@ -8224,13 +8224,7 @@ class admin_setting_configstoredfile extends admin_setting {
// Let's not deal with validation here, this is for admins only.
$current = $this->get_setting();
if (empty($data)) {
// Most probably applying default settings.
if ($current === null) {
return ($this->config_write($this->name, '') ? '' : get_string('errorsetting', 'admin'));
}
return '';
} else if (!is_number($data)) {
if (!is_number($data)) {
// Draft item id is expected here!
return get_string('errorsetting', 'admin');
}
@@ -8250,8 +8244,10 @@ class admin_setting_configstoredfile extends admin_setting {
if ($fs->file_exists($options['context']->id, $component, $this->filearea, $this->itemid, '/', '.')) {
// Make sure the settings form was not open for more than 4 days and draft areas deleted in the meantime.
// But we can safely ignore that if the destination area is empty, so that the user is not prompt
// with an error because the draft area does not exist, as he did not use it.
$usercontext = context_user::instance($USER->id);
if (!$fs->file_exists($usercontext->id, 'user', 'draft', $data, '/', '.')) {
if (!$fs->file_exists($usercontext->id, 'user', 'draft', $data, '/', '.') && $current !== '') {
return get_string('errorsetting', 'admin');
}
}