MDL-71051 core_user: always use API when working with profile fields

This commit is contained in:
Marina Glancy
2021-04-28 11:39:04 +02:00
parent a5f0b354e7
commit 5682b9a585
14 changed files with 135 additions and 153 deletions
+6 -9
View File
@@ -60,7 +60,7 @@ class process {
protected $standardfields = [];
/** @var array */
protected $profilefields = [];
/** @var array */
/** @var \profile_field_base[] */
protected $allprofilefields = [];
/** @var string|\uu_progress_tracker|null */
protected $progresstrackerclass = null;
@@ -161,12 +161,13 @@ class process {
* Profile fields
*/
protected function find_profile_fields(): void {
global $DB;
$this->allprofilefields = $DB->get_records('user_info_field');
global $CFG;
require_once($CFG->dirroot . '/user/profile/lib.php');
$this->allprofilefields = profile_get_user_fields_with_data(0);
$this->profilefields = [];
if ($proffields = $this->allprofilefields) {
foreach ($proffields as $key => $proffield) {
$profilefieldname = 'profile_field_'.$proffield->shortname;
$profilefieldname = 'profile_field_'.$proffield->get_shortname();
$this->profilefields[] = $profilefieldname;
// Re-index $proffields with key as shortname. This will be
// used while checking if profile data is key and needs to be converted (eg. menu profile field).
@@ -528,8 +529,7 @@ class process {
}
}
}
$proffields = $this->allprofilefields;
foreach ($this->profilefields as $field) {
foreach ($this->allprofilefields as $field => $profilefield) {
if (isset($user->$field)) {
continue;
}
@@ -539,9 +539,6 @@ class process {
// Form contains key and later code expects value.
// Convert key to value for required profile fields.
require_once($CFG->dirroot.'/user/profile/field/'.$proffields[$field]->datatype.'/field.class.php');
$profilefieldclass = 'profile_field_'.$proffields[$field]->datatype;
$profilefield = new $profilefieldclass($proffields[$field]->id);
if (method_exists($profilefield, 'convert_external_data')) {
$user->$field = $profilefield->edit_save_data_preprocess($user->$field, null);
}