Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
2.3.3
-
MOODLE_23_STABLE
-
MOODLE_23_STABLE
-
MDL-36914-master -
Description
The assignment 2.2 upgrade functionality doesn't seem to know about outcomes.
Turn debugging up to Developer mode.
In Site Administration > Advanced Features > Tick Enable Outcomes
In Site Administration > Grades > Outcomes > click add a new outcome and create an outcome. Repeat this again to create a second outcome
Select a course with at least one student enrolled and goto Course Administration > Outcomes > move the outcome you just created to the left to enable it for that course
Return to the course homepage and create a new "Upload a single file" 2.2 assignment
Enter a title and description and under Outcomes tick your new outcomes
Open the gradebook for that assignment, select a student and click Grade.
Assign a grade and select any value for each outcome (except of course "No outcome"). Click Save Changes
Connect to your database and run the following SQL:
select id, courseid, itemname, itemmodule, iteminstance, outcomeid
from mdl_grade_items
order by id desc
limit 10;
You should see some new grade_item records like those shown below (in this example I have created two outcomes)
moodle=# select id, courseid, itemname, itemmodule, iteminstance, outcomeid from mdl_grade_items order by id desc;
|
id | courseid | itemname | itemmodule | iteminstance | outcomeid
|
----+----------+--------------+------------+--------------+-----------
|
24 | 2 | Outcome 2 | assignment | 5 | 2
|
23 | 2 | Outcome 1 | assignment | 5 | 1
|
22 | 2 | Outcome test | assignment | 5 |
|
Get the mdl_grade_grade records for those grade_item records
moodle=# select id, itemid, rawgrade, finalgrade from mdl_grade_grades order by itemid desc;
|
id | itemid | rawgrade | finalgrade
|
----+--------+----------+------------
|
15 | 24 | | 3.00000
|
14 | 23 | | 1.00000
|
16 | 22 | 11.00000 | 11.00000
|
Return to the assignment and click View the assignment upgrade tool and upgrade your assignment whilst you are watching the php error logs.
You will see a notice in the error log like that shown below:
[Wed Nov 28 09:37:13 2012] [error] [client 172.16.180.1] PHP Notice: Error: mdb->get_record() found more than one record!<ul style="text-align: left"><li>line 1372 of /lib/dml/moodle_database.php: call to debugging()</li><li>line 1332 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()</li><li>line 1311 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()</li><li>line 234 of /mod/assign/upgradelib.php: call to moodle_database->get_record()</li><li>line 190 of /admin/tool/assignmentupgrade/locallib.php: call to assign_upgrade_manager->upgrade_assignment()</li><li>line 63 of /admin/tool/assignmentupgrade/batchupgrade.php: call to tool_assignmentupgrade_upgrade_assignment()</li></ul> in /var/moodle/www/lib/weblib.php on line 2865, referer: http://moodle.local.net/admin/tool/assignmentupgrade/listnotupgraded.php
|
Re-run the SQL "select id, courseid, itemname, itemmodule, iteminstance, outcomeid from mdl_grade_items order by id desc;" and you'll see that only one of the grade items has been transferred across to the new assign module instance. The other grade_item records have been deleted along with their grade_grades records.
Go back to the setup for the assign instance and you'll see that at least one of the previously selected outcomes is unchecked. In the grade book the value assigned to one of the outcomes will also have disappeared.
During the assignment upgrade process the grade_items are transferred from the old assignment 2.2. course module instance to the new assign course module instance starting at line 234 in mod/assign/upgradelib.php.
$gradeitem = $DB->get_record('grade_items', array('iteminstance'=>$oldassignment->id, 'itemmodule'=>'assignment'), 'id', IGNORE_MISSING);
|
235 if ($gradeitem) {
|
236 $gradeitem->iteminstance = $newassignment->get_instance()->id;
|
237 $gradeitem->itemmodule = 'assign';
|
238 $DB->update_record('grade_items', $gradeitem);
|
239 }
|
That code will only ever re-associate a single grade_item record. Further down at line 289 the old course module is deleted which is where I the grade_items that have been left behind are also deleted.