1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* factor_email upgrade library.
|
|
|
19 |
*
|
|
|
20 |
* @package factor_email
|
|
|
21 |
* @copyright 2024 David Woloszyn <david.woloszyn@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* MFA upgrade helper function.
|
|
|
27 |
*
|
|
|
28 |
* @param int $oldversion
|
|
|
29 |
*/
|
|
|
30 |
function xmldb_factor_email_upgrade($oldversion): bool {
|
|
|
31 |
if ($oldversion < 2024122400) {
|
|
|
32 |
// Check for sites that don't have MFA enabled.
|
|
|
33 |
if (!get_config('tool_mfa', 'enabled')) {
|
|
|
34 |
// Enable email factor.
|
|
|
35 |
set_config('enabled', 1, 'factor_email');
|
|
|
36 |
|
|
|
37 |
// Check factor order config to ensure email is situated in there.
|
|
|
38 |
$factororderconfig = get_config('tool_mfa', 'factor_order');
|
|
|
39 |
if (!$factororderconfig) {
|
|
|
40 |
set_config('factor_order', 'email', 'tool_mfa');
|
|
|
41 |
} else {
|
|
|
42 |
$order = explode(',', $factororderconfig);
|
|
|
43 |
// Remove any empty entries (this happens with entries like ',sms,email').
|
|
|
44 |
$order = array_filter($order);
|
|
|
45 |
if (!in_array('email', $order)) {
|
|
|
46 |
array_unshift($order, 'email');
|
|
|
47 |
$orderstring = implode(',', $order);
|
|
|
48 |
set_config('factor_order', $orderstring, 'tool_mfa');
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
upgrade_plugin_savepoint(true, 2024122400, 'factor', 'email');
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
// Automatically generated Moodle v5.0.0 release upgrade line.
|
|
|
57 |
// Put any upgrade step following this.
|
|
|
58 |
|
|
|
59 |
return true;
|
|
|
60 |
}
|