From b889c63bedfadbfab0131fb3dab0bb64706de750 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Mon, 7 Apr 2025 10:55:05 +0800 Subject: [PATCH] MDL-85116 factor_sms: Set default weight and duration properly --- admin/tool/mfa/factor/sms/db/upgrade.php | 14 ++++++++++---- admin/tool/mfa/factor/sms/version.php | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/admin/tool/mfa/factor/sms/db/upgrade.php b/admin/tool/mfa/factor/sms/db/upgrade.php index 30b1fdeafed..67aa15a579c 100644 --- a/admin/tool/mfa/factor/sms/db/upgrade.php +++ b/admin/tool/mfa/factor/sms/db/upgrade.php @@ -76,18 +76,24 @@ function xmldb_factor_sms_upgrade(int $oldversion): bool { // Automatically generated Moodle v4.5.0 release upgrade line. // Put any upgrade step following this. - if ($oldversion < 2024100701) { + if ($oldversion < 2024100702) { // Ensure default values are applied for the MFA SMS factor when upgrading. $config = get_config('factor_sms'); - if ((int)$config->weight === 0) { + + // Set the weight to the default value (100) if it is misconfigured (e.g. set to 0). + $weight = $config->weight ?? null; + if (isset($weight) && (int)$weight <= 0) { set_config('weight', 100, 'factor_sms'); } - if ((int)$config->duration === 0) { + + // Set the duration to the default value (30 minutes) if it is misconfigured (e.g. set to 0). + $duration = $config->duration ?? null; + if (isset($duration) && (int)$duration <= 0) { set_config('duration', 30 * MINSECS, 'factor_sms'); } // MFA savepoint reached. - upgrade_plugin_savepoint(true, 2024100701, 'factor', 'sms'); + upgrade_plugin_savepoint(true, 2024100702, 'factor', 'sms'); } return true; diff --git a/admin/tool/mfa/factor/sms/version.php b/admin/tool/mfa/factor/sms/version.php index 22009b58c72..7084907bf31 100644 --- a/admin/tool/mfa/factor/sms/version.php +++ b/admin/tool/mfa/factor/sms/version.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024100701; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2024100702; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2024100100; // Requires this Moodle version. $plugin->component = 'factor_sms'; // Full name of the plugin (used for diagnostics). $plugin->maturity = MATURITY_STABLE;