From a9937aec06eecde600f81efe1ff2f53d86df0bf1 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 3 Oct 2014 11:37:12 +0800 Subject: [PATCH] MDL-47062 Grades: Add an upgrade step to warn about changes in upgrade. Puts a notice on the grader report about the change in aggregation method from "Sum of grades" to "Natural". Part of: MDL-46576 --- grade/lib.php | 42 +++++++++++++++++++++++++++++++++++ grade/report/grader/index.php | 7 ++++++ lang/en/grades.php | 2 ++ lib/db/upgrade.php | 20 +++++++++++++++++ version.php | 2 +- 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/grade/lib.php b/grade/lib.php index 28e5d02c22e..643bdb96132 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -458,6 +458,48 @@ function grade_get_graded_users_select($report, $course, $userid, $groupid, $inc return $select; } +/** + * Hide warning about changed grades during upgrade to 2.8. + * + * @param int $courseid The current course id. + */ +function hide_natural_aggregation_upgrade_notice($courseid) { + set_config('show_sumofgrades_upgrade_' . $courseid, false); +} + +/** + * Print warning about changed grades during upgrade to 2.8. + * + * @param int $courseid The current course id. + * @param context $context The course context. + * @param boolean $return return as string + * + * @return nothing or string if $return true + */ +function print_natural_aggregation_upgrade_notice($courseid, $context, $return=false) { + global $OUTPUT; + $html = ''; + $show = get_config('core', 'show_sumofgrades_upgrade_' . $courseid); + + if ($show) { + $message = get_string('sumofgradesupgradedgrades', 'grades'); + $hidemessage = get_string('sumofgradesupgradedgradeshidemessage', 'grades'); + $urlparams = array( 'id' => $courseid, + 'seensumofgradesupgradedgrades' => true, + 'sesskey' => sesskey()); + $goawayurl = new moodle_url('/grade/report/grader/index.php', $urlparams); + $goawaybutton = $OUTPUT->single_button($goawayurl, $hidemessage, 'get'); + $html .= $OUTPUT->notification($message, 'notifysuccess'); + $html .= $goawaybutton; + } + + if ($return) { + return $html; + } else { + echo $html; + } +} + /** * Print grading plugin selection popup form. * diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php index 66b944772c7..cc2f4235270 100644 --- a/grade/report/grader/index.php +++ b/grade/report/grader/index.php @@ -128,6 +128,13 @@ $reportname = get_string('pluginname', 'gradereport_grader'); // Print header print_grade_page_head($COURSE->id, 'report', 'grader', $reportname, false, $buttons); +// Hide the following warning if the user told it to go away. +if (optional_param('seensumofgradesupgradedgrades', false, PARAM_BOOL) && confirm_sesskey()) { + hide_natural_aggregation_upgrade_notice($courseid); +} +// This shows a notice about the upgrade to Natural aggregation. +print_natural_aggregation_upgrade_notice($COURSE->id, $context); + //Initialise the grader report object that produces the table //the class grade_report_grader_ajax was removed as part of MDL-21562 $report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid); diff --git a/lang/en/grades.php b/lang/en/grades.php index 81b2fcfbc29..fa0726395a0 100644 --- a/lang/en/grades.php +++ b/lang/en/grades.php @@ -669,6 +669,8 @@ $string['studentsperpagereduced'] = 'Reduced maximum students per page from {$a- $string['subcategory'] = 'Normal category'; $string['submissions'] = 'Submissions'; $string['submittedon'] = 'Submitted: {$a}'; +$string['sumofgradesupgradedgrades'] = 'A recent upgrade has changed the aggregation method "Sum of grades" to "Natural". Please review the grades in this course as it was previously using "Sum of grades".'; +$string['sumofgradesupgradedgradeshidemessage'] = 'Got it'; $string['switchtofullview'] = 'Switch to full view'; $string['switchtosimpleview'] = 'Switch to simple view'; $string['tabs'] = 'Tabs'; diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index af4bdec0fdc..48e5b15b9fa 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3903,6 +3903,26 @@ function xmldb_main_upgrade($oldversion) { // Main savepoint reached. upgrade_main_savepoint(true, 2014092200.01); } + if ($oldversion < 2014100300.00) { + // Set flags so we can display a notice on all courses that might + // be affected by the uprade to natural aggregation. + if (!get_config('grades_sumofgrades_upgrade_flagged', 'core')) { + // 13 == SUM_OF_GRADES. + $sql = 'SELECT DISTINCT courseid + FROM {grade_categories} + WHERE aggregation = ?'; + $courses = $DB->get_records_sql($sql, array(13)); + + foreach ($courses as $course) { + set_config('show_sumofgrades_upgrade_' . $course->courseid, 1); + } + + set_config('grades_sumofgrades_upgrade_flagged', 1); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2014100300.00); + } return true; } diff --git a/version.php b/version.php index b1c47a58d63..d4cc4ae6177 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2014100200.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2014100300.00; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.