Skip to content

Commit

Permalink
Merge branch 'MDL-40881_M28' of https://github.com/nadavkav/moodle in…
Browse files Browse the repository at this point in the history
…to MOODLE_28_STABLE
  • Loading branch information
andrewnicols committed Apr 21, 2015
2 parents c41e9a3 + e5e43e7 commit b6f2ac8
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions admin/tool/uploaduser/locallib.php
Expand Up @@ -402,21 +402,37 @@ function uu_pre_process_custom_profile_data($data) {
function uu_check_custom_profile_data(&$data) {
global $CFG, $DB;
$noerror = true;

// find custom profile fields and check if data needs to converted.
$testuserid = null;
if (!empty($data['username'])) {
if (preg_match('/id=(.*)"/i', $data['username'], $result)) {
$testuserid = $result[1];
}
}
// Find custom profile fields and check if data needs to converted.
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');
$newfield = 'profile_field_'.$field->datatype;
$formfield = new $newfield($field->id, 0);
if (method_exists($formfield, 'convert_external_data') &&
is_null($formfield->convert_external_data($value))) {
is_null($formfield->convert_external_data($value))) {
$data['status'][] = get_string('invaliduserfield', 'error', $shortname);
$noerror = false;
}
// Check for duplicate value.
if (method_exists($formfield, 'edit_validate_field') ) {
$err = $formfield->edit_validate_field($testuser);
if (!empty($err[$key])) {
$data['status'][] = $err[$key].' ('.$key.')';
$noerror = false;
}
}
}
}
}
Expand Down

0 comments on commit b6f2ac8

Please sign in to comment.