From b34f2c75c9c7e2368afa65359337af0876a68192 Mon Sep 17 00:00:00 2001 From: Michael Hawkins Date: Thu, 27 Feb 2020 13:16:00 +0800 Subject: [PATCH] MDL-68061 gradereport_history: Restrict per page config value to int --- grade/report/history/db/upgrade.php | 47 +++++++++++++++++++++++++++++ grade/report/history/settings.php | 3 +- grade/report/history/version.php | 2 +- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 grade/report/history/db/upgrade.php diff --git a/grade/report/history/db/upgrade.php b/grade/report/history/db/upgrade.php new file mode 100644 index 00000000000..d2c61351f3f --- /dev/null +++ b/grade/report/history/db/upgrade.php @@ -0,0 +1,47 @@ +. + +/** + * Grade overview report upgrade steps. + * + * @package gradereport_history + * @copyright 2020 Michael Hawkins + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Function to upgrade grade history report. + * + * @param int $oldversion the version we are upgrading from + * @return bool result + */ +function xmldb_gradereport_history_upgrade($oldversion) { + + if ($oldversion < 2019111801) { + $perpageconfig = get_config('moodle', 'grade_report_historyperpage'); + + // For existing installations with a non-integer 'per page' config, update the value to the default. + if (!empty($perpageconfig) && filter_var($perpageconfig, FILTER_VALIDATE_INT) === false) { + set_config('grade_report_historyperpage', 50); + } + + upgrade_plugin_savepoint(true, 2019111801, 'gradereport', 'history'); + } + + return true; +} diff --git a/grade/report/history/settings.php b/grade/report/history/settings.php index c841c805713..3653f073361 100644 --- a/grade/report/history/settings.php +++ b/grade/report/history/settings.php @@ -30,7 +30,8 @@ if ($ADMIN->fulltree) { $settings->add(new admin_setting_configtext('grade_report_historyperpage', new lang_string('historyperpage', 'gradereport_history'), new lang_string('historyperpage_help', 'gradereport_history'), - 50 + 50, + PARAM_INT )); } diff --git a/grade/report/history/version.php b/grade/report/history/version.php index b19225b2a08..885b84a6622 100644 --- a/grade/report/history/version.php +++ b/grade/report/history/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019111800; +$plugin->version = 2019111801; $plugin->requires = 2019111200; $plugin->component = 'gradereport_history';