From 3b87330bb1f0003248f6a414a38f59800d728f33 Mon Sep 17 00:00:00 2001 From: Sarah Cotton Date: Wed, 14 Dec 2022 14:51:49 +0000 Subject: [PATCH] Fix for Moodle 4.1 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. --- settings.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/settings.php b/settings.php index cfb919e..068986c 100644 --- a/settings.php +++ b/settings.php @@ -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'), @@ -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 .= '

'.get_string('ipblockersyntax', 'admin').'

'; - $description .= '

'.get_string('ips_combine', 'auth_outage').'

'; + $description .= '

' . get_string('ipblockersyntax', 'admin') . '

'; + $description .= '

' . get_string('ips_combine', 'auth_outage') . '

'; $iplist = new admin_setting_configiplist( 'auth_outage/allowedips', @@ -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') ) ); }