MDL-40811 uploaduser: Optimise testuser code

This commit is contained in:
Andrew Nicols
2015-04-21 11:38:58 +08:00
parent 3428cd4c9b
commit a94e5a405d
+4 -4
View File
@@ -413,9 +413,6 @@ function uu_check_custom_profile_data(&$data) {
foreach ($data as $key => $value) {
if (preg_match('/^profile_field_/', $key)) {
$shortname = str_replace('profile_field_', '', $key);
$testuser = new stdClass();
$testuser->{$key} = $value;
$testuser->id = $testuserid;
if ($fields = $DB->get_records('user_info_field', array('shortname' => $shortname))) {
foreach ($fields as $field) {
require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
@@ -428,6 +425,9 @@ function uu_check_custom_profile_data(&$data) {
}
// Check for duplicate value.
if (method_exists($formfield, 'edit_validate_field') ) {
$testuser = new stdClass();
$testuser->{$key} = $value;
$testuser->id = $testuserid;
$err = $formfield->edit_validate_field($testuser);
if (!empty($err[$key])) {
$data['status'][] = $err[$key].' ('.$key.')';
@@ -439,4 +439,4 @@ function uu_check_custom_profile_data(&$data) {
}
}
return $noerror;
}
}