Skip to content

Commit

Permalink
MDL-40881 uploaduser: Validate profile fields unique values
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavkav committed Apr 13, 2015
1 parent d755125 commit ada4071
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion admin/tool/uploaduser/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,20 @@ function uu_pre_process_custom_profile_data($data) {
function uu_check_custom_profile_data(&$data) {
global $CFG, $DB;
$noerror = true;
$testuserid = null;

// find custom profile fields and check if data needs to converted.
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');
Expand All @@ -436,6 +445,14 @@ function uu_check_custom_profile_data(&$data) {
$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 ada4071

Please sign in to comment.