From 88f4b6c75d827daae8159fcff4d998f39ef1c1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Thu, 16 Nov 2017 21:56:45 +0100 Subject: [PATCH] MDL-60824 profile: Fix handling of to-be-created user id The script user/editadvanced.php uses special value of userid = -1 for the case when a new user is being created. Such a value passes the non-empty check and would lead to "invaliduser" error. --- user/profile/lib.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/user/profile/lib.php b/user/profile/lib.php index 517bbb64c59..d54580301ed 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -88,7 +88,7 @@ class profile_field_base { $this->set_userid($userid); if ($fielddata) { $this->set_field($fielddata); - if ($userid && !empty($fielddata->hasuserdata)) { + if ($userid > 0 && !empty($fielddata->hasuserdata)) { $this->set_user_data($fielddata->data, $fielddata->dataformat); } } else { @@ -395,7 +395,7 @@ class profile_field_base { $this->set_field($field); } - if (!empty($this->field) && $this->userid) { + if (!empty($this->field) && $this->userid > 0) { $params = array('userid' => $this->userid, 'fieldid' => $this->fieldid); if ($data = $DB->get_record('user_info_data', $params, 'data, dataformat')) { $this->set_user_data($data->data, $data->dataformat); @@ -413,7 +413,7 @@ class profile_field_base { public function is_visible() { global $USER; - $context = $this->userid ? context_user::instance($this->userid) : context_system::instance(); + $context = ($this->userid > 0) ? context_user::instance($this->userid) : context_system::instance(); switch ($this->field->visible) { case PROFILE_VISIBLE_ALL: @@ -507,12 +507,12 @@ function profile_get_user_fields_with_data($userid) { // Join any user info data present with each user info field for the user object. $sql = 'SELECT uif.*, uic.name AS categoryname '; - if ($userid) { + if ($userid > 0) { $sql .= ', uind.id AS hasuserdata, uind.data, uind.dataformat '; } $sql .= 'FROM {user_info_field} uif '; $sql .= 'LEFT JOIN {user_info_category} uic ON uif.categoryid = uic.id '; - if ($userid) { + if ($userid > 0) { $sql .= 'LEFT JOIN {user_info_data} uind ON uif.id = uind.fieldid AND uind.userid = :userid '; } $sql .= 'ORDER BY uic.sortorder ASC, uif.sortorder ASC ';