diff --git a/admin/settings/badges.php b/admin/settings/badges.php index 0ea51937c78..2451390dcbd 100644 --- a/admin/settings/badges.php +++ b/admin/settings/badges.php @@ -100,10 +100,11 @@ if (($hassiteconfig || has_any_capability(array( new lang_string('allowexternalbackpack', 'badges'), new lang_string('allowexternalbackpack_desc', 'badges'), 1)); + $bp = $DB->get_record('badge_external_backpack', ['backpackweburl' => BADGRIO_BACKPACKWEBURL]); $backpacksettings->add(new admin_setting_configselect('badges_site_backpack', new lang_string('sitebackpack', 'badges'), new lang_string('sitebackpack_help', 'badges'), - 1, $choices)); + $bp->id, $choices)); $warning = badges_verify_site_backpack(); if (!empty($warning)) { diff --git a/badges/tests/badgeslib_test.php b/badges/tests/badgeslib_test.php index 1e379e81b82..d3d35417f96 100644 --- a/badges/tests/badgeslib_test.php +++ b/badges/tests/badgeslib_test.php @@ -75,6 +75,10 @@ class core_badges_badgeslib_testcase extends advanced_testcase { $this->badgeid = $DB->insert_record('badge', $fordb, true); + // Set the default Issuer (because OBv2 needs them). + set_config('badges_defaultissuername', $fordb->issuername); + set_config('badges_defaultissuercontact', $fordb->issuercontact); + // Create a course with activity and auto completion tracking. $this->course = $this->getDataGenerator()->create_course(array('enablecompletion' => true)); $this->user = $this->getDataGenerator()->create_user(); @@ -670,7 +674,7 @@ class core_badges_badgeslib_testcase extends advanced_testcase { // Get assertion. $award = reset($awards); - $assertion = new core_badges_assertion($award->uniquehash); + $assertion = new core_badges_assertion($award->uniquehash, OPEN_BADGES_V1); $testassertion = $this->assertion; // Make sure JSON strings have the same structure. diff --git a/badges/tests/behat/add_badge.feature b/badges/tests/behat/add_badge.feature index c2a4c00b487..81ecdb70591 100644 --- a/badges/tests/behat/add_badge.feature +++ b/badges/tests/behat/add_badge.feature @@ -16,8 +16,9 @@ Feature: Add badges to the system And I press "Save changes" And I follow "Badges" When I follow "Add a new badge" - Then the field "issuercontact" matches value "testuser@example.com" - And the field "issuername" matches value "Test Badge Site" + And I press "Issuer details" + Then I should see "testuser@example.com" + And I should see "Test Badge Site" @javascript Scenario: Accessing the badges @@ -38,8 +39,6 @@ Feature: Add badges to the system | Description | Test badge description | | Image author | http://author.example.com | | Image caption | Test caption image | - | issuername | Test Badge Site | - | issuercontact | testuser@example.com | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager When I press "Create badge" Then I should see "Edit details" @@ -62,8 +61,6 @@ Feature: Add badges to the system | Description | Test badge related description | | Image author | http://author.example.com | | Image caption | Test caption image | - | issuername | Test Badge Site | - | issuercontact | testuser@example.com | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I wait until the page is ready @@ -77,8 +74,6 @@ Feature: Add badges to the system | Description | Test badge description | | Image author | http://author.example.com | | Image caption | Test caption image | - | issuername | Test Badge Site | - | issuercontact | testuser@example.com | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I follow "Related badges (0)" @@ -101,8 +96,6 @@ Feature: Add badges to the system | Description | Test badge description | | Image author | http://author.example.com | | Image caption | Test caption image | - | issuername | Test Badge Site | - | issuercontact | testuser@example.com | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager When I press "Create badge" Then I should see "Edit details" @@ -127,8 +120,6 @@ Feature: Add badges to the system | Description | Test badge description | | Image author | http://author.example.com | | Image caption | Test caption image | - | issuername | Test Badge Site | - | issuercontact | testuser@example.com | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager When I press "Create badge" Then I should see "Test Badge" @@ -161,8 +152,6 @@ Feature: Add badges to the system | Description | Test badge description | | Image author | http://author.example.com | | Image caption | Test caption image | - | issuername | Test Badge Site | - | issuercontact | testuser@example.com | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" Then I should see "Edit details" diff --git a/badges/tests/behat/award_badge.feature b/badges/tests/behat/award_badge.feature index 079b2c6fc8d..313a9a55da4 100644 --- a/badges/tests/behat/award_badge.feature +++ b/badges/tests/behat/award_badge.feature @@ -25,7 +25,6 @@ Feature: Award badges And I set the following fields to these values: | Name | Course Badge 1 | | Description | Course badge 1 description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Manual issue by role" @@ -43,7 +42,6 @@ Feature: Award badges And I set the following fields to these values: | Name | Course Badge 2 | | Description | Course badge 2 description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" # Set "course badge 1" as criteria @@ -102,8 +100,6 @@ Feature: Award badges And I set the following fields to these values: | Name | Profile Badge | | Description | Test badge description | - | issuername | Test Badge Site | - | issuercontact | testuser@example.com | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Profile completion" @@ -140,7 +136,6 @@ Feature: Award badges And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Manual issue by role" @@ -183,7 +178,6 @@ Feature: Award badges And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Manual issue by role" @@ -235,7 +229,6 @@ Feature: Award badges And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Activity completion" @@ -290,7 +283,6 @@ Feature: Award badges And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Course completion" @@ -340,7 +332,6 @@ Feature: Award badges And I set the following fields to these values: | Name | Course Badge 1 | | Description | Course badge description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Manual issue by role" @@ -366,7 +357,6 @@ Feature: Award badges And I set the following fields to these values: | Name | Course Badge 2 | | Description | Course badge description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Manual issue by role" @@ -423,7 +413,6 @@ Feature: Award badges And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Manual issue by role" diff --git a/badges/tests/behat/award_badge_groups.feature b/badges/tests/behat/award_badge_groups.feature index 90683b37b6e..67c5b6e7b28 100644 --- a/badges/tests/behat/award_badge_groups.feature +++ b/badges/tests/behat/award_badge_groups.feature @@ -41,7 +41,6 @@ Feature: Award badges with separate groups And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Manual issue by role" diff --git a/badges/tests/behat/criteria_activity.feature b/badges/tests/behat/criteria_activity.feature index b71fcea4de8..55f92548f46 100644 --- a/badges/tests/behat/criteria_activity.feature +++ b/badges/tests/behat/criteria_activity.feature @@ -40,7 +40,6 @@ Feature: Award badges based on activity completion And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Activity completion" diff --git a/badges/tests/behat/criteria_cohort.feature b/badges/tests/behat/criteria_cohort.feature index e4971440ea8..e0578debdf7 100644 --- a/badges/tests/behat/criteria_cohort.feature +++ b/badges/tests/behat/criteria_cohort.feature @@ -23,7 +23,6 @@ Feature: Award badges based on cohort And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Cohort membership" @@ -59,7 +58,6 @@ Feature: Award badges based on cohort And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Cohort membership" @@ -100,7 +98,6 @@ Feature: Award badges based on cohort And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Cohort membership" @@ -137,7 +134,6 @@ Feature: Award badges based on cohort And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Cohort membership" @@ -188,7 +184,6 @@ Feature: Award badges based on cohort And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Cohort membership" @@ -245,7 +240,6 @@ Feature: Award badges based on cohort And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Cohort membership" @@ -302,7 +296,6 @@ Feature: Award badges based on cohort And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Cohort membership" @@ -360,7 +353,6 @@ Feature: Award badges based on cohort And I set the following fields to these values: | Name | Site Badge 1 | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Cohort membership" @@ -373,7 +365,6 @@ Feature: Award badges based on cohort And I set the following fields to these values: | Name | Site Badge 2 | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Cohort membership" @@ -415,7 +406,6 @@ Feature: Award badges based on cohort And I set the following fields to these values: | Name | Site Badge 1 | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Cohort membership" @@ -430,7 +420,6 @@ Feature: Award badges based on cohort And I set the following fields to these values: | Name | Site Badge 2 | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Cohort membership" diff --git a/badges/tests/behat/criteria_competency.feature b/badges/tests/behat/criteria_competency.feature index 88bc30a5e14..f84cf828683 100644 --- a/badges/tests/behat/criteria_competency.feature +++ b/badges/tests/behat/criteria_competency.feature @@ -44,7 +44,6 @@ Feature: Award badges based on competency completion And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" # Set the competency as a criteria for the badge @@ -89,7 +88,6 @@ Feature: Award badges based on competency completion And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" # Set the competency as a criteria for the badge @@ -142,7 +140,6 @@ Feature: Award badges based on competency completion And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" # Set the competency as a criteria for the badge diff --git a/badges/tests/behat/criteria_profile.feature b/badges/tests/behat/criteria_profile.feature index 14cc5b517e6..93be0eddaab 100644 --- a/badges/tests/behat/criteria_profile.feature +++ b/badges/tests/behat/criteria_profile.feature @@ -14,7 +14,6 @@ Feature: Award badges based on user profile field And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | - | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Profile completion" diff --git a/badges/tests/behat/role_visibility.feature b/badges/tests/behat/role_visibility.feature index e89489b5530..036ff5d060b 100644 --- a/badges/tests/behat/role_visibility.feature +++ b/badges/tests/behat/role_visibility.feature @@ -26,7 +26,6 @@ Feature: Test role visibility for the badge administration page And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Manual issue by role" @@ -42,7 +41,6 @@ Feature: Test role visibility for the badge administration page And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | - | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the following fields to these values: diff --git a/badges/upgrade.txt b/badges/upgrade.txt index ef6f89241fa..5a9feb60aa6 100644 --- a/badges/upgrade.txt +++ b/badges/upgrade.txt @@ -1,5 +1,9 @@ This files describes API changes in /badges/*, information provided here is intended especially for developers. + +=== 3.9 === +* BADGE_BACKPACKAPIURL and BADGE_BACKPACKWEBURL are deprecated and should not be used. + === 3.7 === * BADGE_BACKPACKURL is deprecated and should not be used. * Incorrect term "badge competencies" has been refactored to "alignments" everywhere. diff --git a/badges/upgradelib.php b/badges/upgradelib.php index d1acd8ba05b..7ce5b001566 100644 --- a/badges/upgradelib.php +++ b/badges/upgradelib.php @@ -33,23 +33,6 @@ defined('MOODLE_INTERNAL') || die(); function badges_install_default_backpacks() { global $DB; - $record = new stdClass(); - $record->backpackweburl = 'https://backpack.openbadges.org'; - $record->backpackapiurl = 'https://backpack.openbadges.org'; - $record->apiversion = 1; - $record->sortorder = 0; - $record->password = ''; - - if (!($bp = $DB->get_record('badge_external_backpack', array('backpackapiurl' => $record->backpackapiurl)))) { - $bpid = $DB->insert_record('badge_external_backpack', $record); - } else { - $bpid = $bp->id; - } - set_config('badges_site_backpack', $bpid); - - // All existing backpacks default to V1. - $DB->set_field('badge_backpack', 'externalbackpackid', $bpid); - $record = new stdClass(); $record->backpackapiurl = 'https://api.badgr.io/v2'; $record->backpackweburl = 'https://badgr.io'; @@ -57,9 +40,16 @@ function badges_install_default_backpacks() { $record->sortorder = 1; $record->password = ''; - if (!$DB->record_exists('badge_external_backpack', array('backpackapiurl' => $record->backpackapiurl))) { - $DB->insert_record('badge_external_backpack', $record); + $bp = $DB->get_record('badge_external_backpack', ['backpackapiurl' => $record->backpackapiurl]); + if ($bp) { + $bpid = $bp->id; + } else { + $bpid = $DB->insert_record('badge_external_backpack', $record); } + set_config('badges_site_backpack', $bpid); + + // Set external backpack to v2. + $DB->set_field('badge_backpack', 'externalbackpackid', $bpid); } diff --git a/blocks/badges/tests/behat/block_badges_course.feature b/blocks/badges/tests/behat/block_badges_course.feature index cc739afb96e..32d1626dba9 100644 --- a/blocks/badges/tests/behat/block_badges_course.feature +++ b/blocks/badges/tests/behat/block_badges_course.feature @@ -21,7 +21,6 @@ Feature: Enable Block Badges in a course And I set the following fields to these values: | id_name | Badge 1 | | id_description | Badge 1 | - | id_issuername | Teacher 1 | And I upload "blocks/badges/tests/fixtures/badge.png" file to "Image" filemanager And I press "Create badge" And I select "Manual issue by role" from the "Add badge criteria" singleselect @@ -39,7 +38,6 @@ Feature: Enable Block Badges in a course And I set the following fields to these values: | id_name | Badge 2 | | id_description | Badge 2 | - | id_issuername | Teacher 1 | And I upload "blocks/badges/tests/fixtures/badge.png" file to "Image" filemanager And I press "Create badge" And I select "Manual issue by role" from the "Add badge criteria" singleselect diff --git a/blocks/badges/tests/behat/block_badges_dashboard.feature b/blocks/badges/tests/behat/block_badges_dashboard.feature index 45d10c71070..fe21e468f6e 100644 --- a/blocks/badges/tests/behat/block_badges_dashboard.feature +++ b/blocks/badges/tests/behat/block_badges_dashboard.feature @@ -21,7 +21,6 @@ Feature: Enable Block Badges on the dashboard and view awarded badges And I set the following fields to these values: | id_name | Badge 1 | | id_description | Badge 1 | - | id_issuername | Teacher 1 | And I upload "blocks/badges/tests/fixtures/badge.png" file to "Image" filemanager And I press "Create badge" And I select "Manual issue by role" from the "Add badge criteria" singleselect diff --git a/blocks/badges/tests/behat/block_badges_frontpage.feature b/blocks/badges/tests/behat/block_badges_frontpage.feature index 89a99deb78d..388f4a30eb9 100644 --- a/blocks/badges/tests/behat/block_badges_frontpage.feature +++ b/blocks/badges/tests/behat/block_badges_frontpage.feature @@ -26,7 +26,6 @@ Feature: Enable Block Badges on the frontpage and view awarded badges And I set the following fields to these values: | id_name | Badge 1 | | id_description | Badge 1 | - | id_issuername | Teacher 1 | And I upload "blocks/badges/tests/fixtures/badge.png" file to "Image" filemanager And I press "Create badge" And I select "Manual issue by role" from the "Add badge criteria" singleselect diff --git a/lib/badgeslib.php b/lib/badgeslib.php index 6d58efafd10..4fc5e65a73b 100644 --- a/lib/badgeslib.php +++ b/lib/badgeslib.php @@ -96,8 +96,6 @@ define('BADGE_MESSAGE_MONTHLY', 4); /* * URL of backpack. Custom ones can be added. */ -define('BADGE_BACKPACKAPIURL', 'https://backpack.openbadges.org'); -define('BADGE_BACKPACKWEBURL', 'https://backpack.openbadges.org'); define('BADGRIO_BACKPACKAPIURL', 'https://api.badgr.io/v2'); define('BADGRIO_BACKPACKWEBURL', 'https://badgr.io'); @@ -106,6 +104,12 @@ define('BADGRIO_BACKPACKWEBURL', 'https://badgr.io'); */ define('BADGE_BACKPACKURL', 'https://backpack.openbadges.org'); +/* + * @deprecated since 3.9 (MDL-66357). + */ +define('BADGE_BACKPACKAPIURL', 'https://backpack.openbadges.org'); +define('BADGE_BACKPACKWEBURL', 'https://backpack.openbadges.org'); + /* * Open Badges specifications. */ diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 6ce95684d97..8fb38d4d312 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2212,5 +2212,40 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2020013000.01); } + if ($oldversion < 2020040200.01) { + // Remove deprecated Mozilla OpenBadges backpack. + $url = 'https://backpack.openbadges.org'; + $bp = $DB->get_record('badge_external_backpack', ['backpackapiurl' => $url]); + if ($bp) { + // Remove connections for users to this backpack. + $sql = "SELECT DISTINCT bb.id + FROM {badge_backpack} bb + LEFT JOIN {badge_external} be ON be. backpackid = bb.externalbackpackid + WHERE bb.externalbackpackid = :backpackid"; + $params = ['backpackid' => $bp->id]; + $externalbackpacks = $DB->get_fieldset_sql($sql, $params); + if ($externalbackpacks) { + list($sql, $params) = $DB->get_in_or_equal($externalbackpacks); + + // Delete user external collections references to this backpack. + $DB->execute("DELETE FROM {badge_external} WHERE backpackid " . $sql, $params); + } + $DB->delete_records('badge_backpack', ['externalbackpackid' => $bp->id]); + + // Delete deprecated backpack entry. + $DB->delete_records('badge_external_backpack', ['backpackapiurl' => $url]); + } + + // Set active external backpack to Badgr.io. + $url = 'https://api.badgr.io/v2'; + if ($bp = $DB->get_record('badge_external_backpack', ['backpackapiurl' => $url])) { + set_config('badges_site_backpack', $bp->id); + } else { + unset_config('badges_site_backpack'); + } + + upgrade_main_savepoint(true, 2020040200.01); + } + return true; } diff --git a/version.php b/version.php index bbed55d9341..d2a1eb8c66e 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2020040200.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2020040200.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '3.9dev (Build: 20200402)'; // Human-friendly version name