Merge branch 'MDL-70913-master' of git://github.com/sarjona/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2021-03-01 14:21:59 +01:00
commit 76e5b1b59d
4 changed files with 23 additions and 7 deletions

View File

@ -1145,6 +1145,7 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
$data['password'] = 'test';
if ($isadmin || $updatetest) {
$this->setAdminUser();
$lastmax = $DB->get_field_sql('SELECT MAX(sortorder) FROM {badge_external_backpack}');
$backpack = badges_create_site_backpack((object) $data);
}
@ -1156,8 +1157,9 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
badges_update_site_backpack($backpack, (object)$data);
}
$record = $DB->get_record('badge_external_backpack', ['id' => $backpack]);
$this->assertEquals($record->backpackweburl, $data['backpackweburl']);
$this->assertEquals($record->backpackapiurl, $data['backpackapiurl']);
$this->assertEquals($data['backpackweburl'], $record->backpackweburl);
$this->assertEquals($data['backpackapiurl'], $record->backpackapiurl);
$this->assertEquals($lastmax + 1, $record->sortorder);
$record = $DB->get_record('badge_backpack', ['userid' => 0]);
$this->assertNotEmpty($record);
} else {

View File

@ -772,8 +772,9 @@ function badges_create_site_backpack($data) {
$context = context_system::instance();
require_capability('moodle/badges:manageglobalsettings', $context);
$count = $DB->count_records('badge_external_backpack');
$data->sortorder = $count;
$max = $DB->get_field_sql('SELECT MAX(sortorder) FROM {badge_external_backpack}');
$data->sortorder = $max + 1;
return badges_save_external_backpack($data);
}
@ -983,7 +984,7 @@ function badges_get_site_primary_backpack() {
function badges_get_site_backpacks() {
global $DB, $CFG;
$all = $DB->get_records('badge_external_backpack');
$all = $DB->get_records('badge_external_backpack', null, 'sortorder ASC');
foreach ($all as $key => $bp) {
if ($bp->id == $CFG->badges_site_backpack) {
@ -1379,4 +1380,4 @@ function badges_generate_badgr_open_url($backpack, $type, $externalid) {
return "{$url->get_scheme()}://{$url->get_host()}/public/{$entity}s/$externalid";
}
}
}

View File

@ -2458,5 +2458,18 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021052500.60);
}
if ($oldversion < 2021052500.64) {
// Get all the external backpacks and update the sortorder column, to avoid repeated/wrong values. As sortorder was not
// used since now, the id column will be the criteria to follow for re-ordering them with a valid value.
$i = 1;
$records = $DB->get_records('badge_external_backpack', null, 'id ASC');
foreach ($records as $record) {
$record->sortorder = $i++;
$DB->update_record('badge_external_backpack', $record);
}
upgrade_main_savepoint(true, 2021052500.64);
}
return true;
}

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2021052500.63; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021052500.64; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev (Build: 20210226)'; // Human-friendly version name