From efa7a8a9e43f43ee088d384aed64a875a948c4b3 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Fri, 5 Jun 2015 10:49:26 +0800 Subject: [PATCH] MDL-30315 gradebook: Uploading feedback doesn't override grades. --- grade/import/csv/classes/load_data.php | 1 + grade/import/csv/tests/load_data_test.php | 1 + grade/import/lib.php | 4 ++++ lib/db/install.xml | 3 ++- lib/db/upgrade.php | 15 +++++++++++++++ version.php | 2 +- 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/grade/import/csv/classes/load_data.php b/grade/import/csv/classes/load_data.php index a099f59d1f1..e9744b1f7ed 100644 --- a/grade/import/csv/classes/load_data.php +++ b/grade/import/csv/classes/load_data.php @@ -577,6 +577,7 @@ class gradeimport_csv_load_data { } else { // The grade item for this is not updated. + $newfeedback->importonlyfeedback = true; $insertid = self::insert_grade_record($newfeedback, $this->studentid); // Check to see if the insert was successful. if (empty($insertid)) { diff --git a/grade/import/csv/tests/load_data_test.php b/grade/import/csv/tests/load_data_test.php index 118906c6629..352365e700c 100644 --- a/grade/import/csv/tests/load_data_test.php +++ b/grade/import/csv/tests/load_data_test.php @@ -210,6 +210,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $testarray[$key]->feedback = $record->feedback; $testarray[$key]->importcode = $testobject->get_importcode(); $testarray[$key]->importer = $USER->id; + $testarray[$key]->importonlyfeedback = 0; // Check that the record was inserted into the database. $this->assertEquals($gradeimportvalues, $testarray); diff --git a/grade/import/lib.php b/grade/import/lib.php index f8d8e5777cb..82a792d3911 100644 --- a/grade/import/lib.php +++ b/grade/import/lib.php @@ -114,6 +114,10 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb if (!$importfeedback) { $grade->feedback = false; // ignore it } + if ($grade->importonlyfeedback) { + // False means do not change. See grade_itme::update_final_grade(). + $grade->finalgrade = false; + } if (!$gradeitem->update_final_grade($grade->userid, $grade->finalgrade, 'import', $grade->feedback)) { $errordata = new stdClass(); $errordata->itemname = $gradeitem->itemname; diff --git a/lib/db/install.xml b/lib/db/install.xml index 193dad3d77a..fcc226d84d2 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -1941,6 +1941,7 @@ + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 7f7cafaa5c9..319524d3ac0 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -4440,5 +4440,20 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2015051100.10); } + if ($oldversion < 2015051101.07) { + + // Define field importtype to be added to grade_import_values. + $table = new xmldb_table('grade_import_values'); + $field = new xmldb_field('importonlyfeedback', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'importer'); + + // Conditionally launch add field importtype. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2015051101.07); + } + return true; } diff --git a/version.php b/version.php index 46d2eab1e33..a4d9f07b479 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2015051101.06; // 20150511 = branching date YYYYMMDD - do not modify! +$version = 2015051101.07; // 20150511 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes.