diff --git a/admin/tool/moodlenet/classes/task/post_install.php b/admin/tool/moodlenet/classes/task/post_install.php deleted file mode 100644 index 55f2ca13881..00000000000 --- a/admin/tool/moodlenet/classes/task/post_install.php +++ /dev/null @@ -1,35 +0,0 @@ -. - -declare(strict_types=1); - -namespace tool_moodlenet\task; - -/** - * Ad-hoc task to perform post install tasks. - * We use this to set the active activity chooser footer plugin to tool_moodlenet. - * We couldn't do this directly in install.php, because there is an admin_apply_default_settings() call after all plugins are - * installed and that would reset whatever value we had set earlier to 'hidden'. - * - * @package tool_moodlenet - * @copyright 2022 Shamim Rezaie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class post_install extends \core\task\adhoc_task { - public function execute() { - set_config('activitychooseractivefooter', 'tool_moodlenet'); - } -} diff --git a/admin/tool/moodlenet/db/install.php b/admin/tool/moodlenet/db/install.php index d9c1a0f8669..4a43df97ceb 100644 --- a/admin/tool/moodlenet/db/install.php +++ b/admin/tool/moodlenet/db/install.php @@ -28,12 +28,5 @@ declare(strict_types=1); * Perform the post-install procedures. */ function xmldb_tool_moodlenet_install() { - // Use an ad-hoc task to set the active activity chooser footer plugin to tool_moodlenet. - // We couldn't do this in admin/settings/courses.php for 2 reasons: - // - First, because it would be a breach of component communications principles to do so there. - // - Second, because we can't call get_plugins_with_function() during install and upgrade (or it will return []). - // We couldn't do this directly here either, because there is an admin_apply_default_settings() call after all plugins are - // installed and that would reset whatever value we set here to 'hidden'. - $postinstall = new tool_moodlenet\task\post_install(); - core\task\manager::queue_adhoc_task($postinstall); + } diff --git a/lang/en/admin.php b/lang/en/admin.php index e5567a35a5a..8a87c535da2 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -966,7 +966,7 @@ $string['maxtimelimit'] = 'Maximum time limit'; $string['maxtimelimit_desc'] = 'To restrict the maximum PHP execution time that Moodle will allow without any output being displayed, enter a value in seconds here. 0 means that Moodle default restrictions are used. If you have a front-end server with its own time limit, set this value lower to receive PHP errors in logs. Does not apply to CLI scripts.'; $string['moodlebrandedapp'] = 'Branded Moodle app'; $string['moodlebrandedappreference'] = 'Alternatively, get a Branded Moodle app with your own custom branding.'; -$string['moodlenetremovalwarning'] = 'The MoodleNet service will be shut down on 20 April 2026. If you wish to continue using MoodleNet on your site, install the MoodleNet plugin from the Moodle plugins directory and connect it to a self-hosted MoodleNet instance. Following this, the MoodleNet profile ID field will be removed; please migrate that data if you are using it for other purposes.'; +$string['moodlenetremovalwarning'] = 'The MoodleNet service will be shut down on 20 April 2026. If you wish to continue using MoodleNet on your site, install the MoodleNet plugin from the Moodle HQ GitHub repository and connect it to a self-hosted MoodleNet instance. Following this, the MoodleNet profile ID field will be removed; please migrate that data if you are using it for other purposes.'; $string['noreplyaddress'] = 'No-reply address'; $string['noreplydomain'] = 'No-reply and domain'; $string['noreplydomaindetail'] = 'Settings for No-reply and configured domains'; diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 224aa2becac..949c6494add 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2017,5 +2017,53 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2025041406.05); } + if ($oldversion < 2025041406.07) { + // Clean up tool_moodlenet configurations unless pointing to a custom installation. + $moodleneturl = get_config('tool_moodlenet', 'defaultmoodlenet'); + + $shouldcleanup = true; + + // Check if pointing to a custom MoodleNet installation. + if (!empty($moodleneturl)) { + $parsed = parse_url(strtolower(trim($moodleneturl))); + $host = $parsed['host'] ?? ''; + + // Don't cleanup if it's a custom installation (not moodle.net). + if ($host !== 'moodle.net' && $host !== 'www.moodle.net') { + $shouldcleanup = false; + } + } + + if ($shouldcleanup) { + // Reset configs to defaults. + set_config('defaultmoodlenet', '', 'tool_moodlenet'); + set_config('enablemoodlenet', 0, 'tool_moodlenet'); + + // Hide activity chooser footer if set to MoodleNet. + $footer = get_config('core', 'activitychooseractivefooter'); + if ($footer === 'tool_moodlenet') { + set_config('activitychooseractivefooter', 'hidden'); + } + + // Remove the enablesharingtomoodlenet config setting. + unset_config('enablesharingtomoodlenet'); + + // Remove MoodleNet outbound OAuth2 configuration. + unset_config('oauthservice', 'moodlenet'); + $issuerids = $DB->get_fieldset_select('oauth2_issuer', 'id', "servicetype = ?", ['moodlenet']); + if (!empty($issuerids)) { + $DB->delete_records_list('oauth2_endpoint', 'issuerid', $issuerids); + $DB->delete_records_list('oauth2_access_token', 'issuerid', $issuerids); + $DB->delete_records_list('oauth2_refresh_token', 'issuerid', $issuerids); + $DB->delete_records_list('oauth2_system_account', 'issuerid', $issuerids); + $DB->delete_records_list('oauth2_user_field_mapping', 'issuerid', $issuerids); + $DB->delete_records_list('oauth2_issuer', 'id', $issuerids); + } + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2025041406.07); + } + return true; } diff --git a/version.php b/version.php index bb9c711c67c..2fc15f402e9 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2025041406.06; // 20250414 = branching date YYYYMMDD - do not modify! +$version = 2025041406.07; // 20250414 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '5.0.6+ (Build: 20260306)'; // Human-friendly version name