Skip to content

Commit

Permalink
Fix for Moodle 4.1
Browse files Browse the repository at this point in the history
The settings page is ignored on install so when the admin settings page
is next loaded, the default settings cannot be found and undefined offset
warnings are thrown.
  • Loading branch information
sarahjcotton committed Feb 8, 2023
1 parent 1627bce commit 3b87330
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,30 @@
* @var admin_settingpage $settings
* @var bootstrap_renderer $OUTPUT
* @var admin_root $ADMIN
* @var moodle_page $PAGE
*/
use auth_outage\local\outagelib;

defined('MOODLE_INTERNAL') || die;

if ($hassiteconfig && is_enabled_auth('outage')) {
if ($hassiteconfig) {
$defaults = outagelib::get_config_defaults();
$settings->visiblename = get_string('menusettings', 'auth_outage');
$description = outagelib::generate_plugin_configuration_warning();

$settings->add(new admin_setting_heading(
'defaults',
get_string('settingssectiondefaults', 'auth_outage'),
get_string('settingssectiondefaultsdescription', 'auth_outage')));
get_string('settingssectiondefaultsdescription', 'auth_outage') . $description
));

$settings->add(new admin_setting_configcheckbox(
'auth_outage/default_autostart',
get_string('defaultoutageautostart', 'auth_outage'),
get_string('defaultoutageautostartdescription', 'auth_outage'),
$defaults['default_autostart']
));

$settings->add(new admin_setting_configduration(
'auth_outage/default_warning_duration',
get_string('defaultwarningduration', 'auth_outage'),
Expand Down Expand Up @@ -96,21 +101,22 @@

// Create 'Allowed IPs' settings.
$allowedips = outagelib::get_config()->allowedips;
$description = outagelib::generate_plugin_configuration_warning();
if (trim($allowedips) == '') {
$message = 'allowedipsempty';
$type = 'notifymessage';
} else if (remoteip_in_list($allowedips)) {
$message = 'allowedipshasmyip';
$type = 'notifysuccess';
} else {
$message = 'allowedipshasntmyip';
$type = 'notifyerror';
if (remoteip_in_list($allowedips)) {
$message = 'allowedipshasmyip';
$type = 'notifysuccess';
} else {
$message = 'allowedipshasntmyip';
$type = 'notifyerror';
}
};
$description .= $OUTPUT->notification(get_string($message, 'auth_outage', ['ip' => getremoteaddr()]), $type);
$description = $OUTPUT->notification(get_string($message, 'auth_outage', ['ip' => getremoteaddr()]), $type);

$description .= '<p>'.get_string('ipblockersyntax', 'admin').'</p>';
$description .= '<p>'.get_string('ips_combine', 'auth_outage').'</p>';
$description .= '<p>' . get_string('ipblockersyntax', 'admin') . '</p>';
$description .= '<p>' . get_string('ips_combine', 'auth_outage') . '</p>';

$iplist = new admin_setting_configiplist(
'auth_outage/allowedips',
Expand Down Expand Up @@ -150,7 +156,7 @@
new admin_externalpage(
'auth_outage_manage',
get_string('menumanage', 'auth_outage'),
new moodle_url($CFG->wwwroot.'/auth/outage/manage.php')
new moodle_url($CFG->wwwroot . '/auth/outage/manage.php')
)
);
}

0 comments on commit 3b87330

Please sign in to comment.