Skip to content

Commit

Permalink
Merge branch 'MDL-73878-311' of https://github.com/aanabit/moodle int…
Browse files Browse the repository at this point in the history
…o MOODLE_311_STABLE
  • Loading branch information
junpataleta committed May 4, 2022
2 parents 43e181f + 692657f commit 5b02f3b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
18 changes: 18 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -2682,5 +2682,23 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021051700.05);
}

if ($oldversion < 2021051706.12) {
// Social custom fields could had been created linked to category id = 1. Let's check category 1 exists.
if (!$DB->get_record('user_info_category', ['id' => 1])) {
// Let's check if we have any custom field linked to category id = 1.
$fields = $DB->get_records('user_info_field', ['categoryid' => 1]);
if (!empty($fields)) {
$categoryid = $DB->get_field_sql('SELECT min(id) from {user_info_category}');
foreach ($fields as $field) {
$field->categoryid = $categoryid;
$DB->update_record('user_info_field', $field);
}
}
}

// Main savepoint reached.
upgrade_main_savepoint(true, 2021051706.12);
}

return true;
}
14 changes: 9 additions & 5 deletions user/profile/field/social/upgradelib.php
Expand Up @@ -28,8 +28,10 @@

/**
* Create the default category for custom profile fields if it does not exist yet.
*
* @return int Category ID for social user profile category.
*/
function user_profile_social_create_info_category() {
function user_profile_social_create_info_category(): int {
global $DB;

$categories = $DB->get_records('user_info_category', null, 'sortorder ASC');
Expand All @@ -39,7 +41,9 @@ function user_profile_social_create_info_category() {
'name' => get_string('profiledefaultcategory', 'admin'),
'sortorder' => 1
];
$DB->insert_record('user_info_category', $defaultcategory);
return $DB->insert_record('user_info_category', $defaultcategory);
} else {
return (int)$DB->get_field_sql('SELECT min(id) from {user_info_category}');
}
}

Expand Down Expand Up @@ -89,13 +93,15 @@ function user_profile_social_create_profilefield($social) {
];
$visible = (in_array($confignames[$social], $hiddenfields)) ? 3 : 2;

$categoryid = user_profile_social_create_info_category();

$newfield = (object)[
'shortname' => $social,
'name' => $social,
'datatype' => 'social',
'description' => '',
'descriptionformat' => 1,
'categoryid' => 1,
'categoryid' => $categoryid,
'required' => 0,
'locked' => 0,
'visible' => $visible,
Expand All @@ -106,8 +112,6 @@ function user_profile_social_create_profilefield($social) {
'param1' => $social
];

user_profile_social_create_info_category();

$profilefield = $DB->get_record_sql(
'SELECT * FROM {user_info_field} WHERE datatype = :datatype AND ' .
$DB->sql_compare_text('param1') . ' = ' . $DB->sql_compare_text(':social', 40),
Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2021051706.11; // 20210517 = branching date YYYYMMDD - do not modify!
$version = 2021051706.12; // 20210517 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '3.11.6+ (Build: 20220429)';// Human-friendly version name
Expand Down

0 comments on commit 5b02f3b

Please sign in to comment.