Moodle
  1. Moodle
  2. MDL-36914

Assignment 2.2 upgrade utility deletes outcomes data

    Details

    • Testing Instructions:
      Hide
      1. Enable Outcomes in "Site administration" => "Advanced features"
      2. Add an outcome in "Site administration" => "Grades" => "Outcomes"
      3. Enable the "Assignment (2.2)" activity in "Site administration" => "Plugins" => "Activity modules" => "Manage activity modules"
      4. In a test course with at least one student, Go to the outcomes page in the course settings block and add the outcome to the course.
      5. Create an instance of the old "Online text" assignment, and select the new outcome in the settings page.
      6. Login as a student and make a submission
      7. Login as a teacher and grade the submission, assigning it an outcome as well.
      8. Use the assignment upgrade tool to upgrade the assignment to the new assignment module
      9. Go to the gradebook for the course and see that there is a column for the outcome and it has the assigned value for the student.
      10. Click the header for the outcome column and see that it takes you to the upgraded assignment.
      Show
      Enable Outcomes in "Site administration" => "Advanced features" Add an outcome in "Site administration" => "Grades" => "Outcomes" Enable the "Assignment (2.2)" activity in "Site administration" => "Plugins" => "Activity modules" => "Manage activity modules" In a test course with at least one student, Go to the outcomes page in the course settings block and add the outcome to the course. Create an instance of the old "Online text" assignment, and select the new outcome in the settings page. Login as a student and make a submission Login as a teacher and grade the submission, assigning it an outcome as well. Use the assignment upgrade tool to upgrade the assignment to the new assignment module Go to the gradebook for the course and see that there is a column for the outcome and it has the assigned value for the student. Click the header for the outcome column and see that it takes you to the upgraded assignment.
    • Affected Branches:
      MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-36914-master
    • Rank:
      46451

      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.

        Activity

        Hide
        Nathan Mares added a comment -

        And here's a patch that fixes the issue by re-associating all grade_items from the original course module instance to the new one, not just one of them.

        Show
        Nathan Mares added a comment - And here's a patch that fixes the issue by re-associating all grade_items from the original course module instance to the new one, not just one of them.
        Hide
        Damyon Wiese added a comment -

        Thanks for reporting this Nathan,

        I'll take a look now.

        Show
        Damyon Wiese added a comment - Thanks for reporting this Nathan, I'll take a look now.
        Hide
        Damyon Wiese added a comment -

        Hi Nathan,

        I added a patch to clean up some formatting/sql issues. Also - your rollback was incorrect (It was setting the component back to 'assign' and not 'assignment').

        I'll just need to do some more testing on this myself before I send it for integration.

        • Damyon
        Show
        Damyon Wiese added a comment - Hi Nathan, I added a patch to clean up some formatting/sql issues. Also - your rollback was incorrect (It was setting the component back to 'assign' and not 'assignment'). I'll just need to do some more testing on this myself before I send it for integration. Damyon
        Hide
        Nathan Mares added a comment -

        Ahh yes - well spotted! Looks good, thanks for that.

        Show
        Nathan Mares added a comment - Ahh yes - well spotted! Looks good, thanks for that.
        Hide
        Damyon Wiese added a comment -

        Note: I tested this with these test instructions on 2.3 and 2.4dev.

        Show
        Damyon Wiese added a comment - Note: I tested this with these test instructions on 2.3 and 2.4dev.
        Hide
        Dan Poltawski added a comment -

        Integrated, thanks Nathan/Damyon

        Show
        Dan Poltawski added a comment - Integrated, thanks Nathan/Damyon
        Hide
        Dan Poltawski added a comment -

        Tested during integration and passed

        Show
        Dan Poltawski added a comment - Tested during integration and passed
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Just in time for Moodle 2.4.0 release, thanks!

        Closing, ciao

        Show
        Eloy Lafuente (stronk7) added a comment - Just in time for Moodle 2.4.0 release, thanks! Closing, ciao

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: