Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-15524

Manual grade items with calculations not restoring properly.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 1.9
    • Fix Version/s: 1.9.1
    • Component/s: Backup, Gradebook
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      Manual gradebook items that use calculations do not restore properly into Moodle (most of the time). The calculation string restores to the database identical to how it reads in the xml backup file.

      Example: Say my moodle.xml backup file says the calculation of manual grade item # 300 is:

      =sum(##gi259##,##gi260##,##gi261##,##gi262##)

      But grade_item with id 259 in the moodle.xml file doesn't always receive the same ID when put into the database (in cases where the ID is already taken). The restore process needs to wait to process the calculation string for any manual grade_item for all the other grade items to be inserted into the database.

      Meaning, items 259, 260, 261, and 262 need to be inserted into the database before we can attempt to re-calculate the calculation for manual item #300.

      The suggested fix involves traversing through each item as normal, and saving any manual items into an array that will then be checked and processed after all grade_items from xml have been inserted into the database.

      All changes take place in backup/restorelib.php within the function restore_create_gradebook. Keep in mind the change may not be up to Moodle standards. There are probably a few places where current functions should be used instead but for what it's worth, this code works.

      The included text file is only of the function restore_create_gradebook in restorelib.php and code additions start with /added code/ and end with a comment as well.

      EDIT:
      Oops, forgot to mention how it works. The new code takes the calculation string that references old_ids of each grade item and parses each ##gi***## replacing the old_id (***) with the new_id using backup_getid() to retrieve the new id. By waiting until all grade items are restored to re-calculate it ensures that we have the correct ID's in the calculation string. I've only tested with the sum function, but the code only replaces ID's so any function should work.

        Attachments

        1. autoid.jpg
          autoid.jpg
          64 kB
        2. restore_create_gradebook.txt
          60 kB
        3. restorelib.php.diff
          6 kB

          Issue Links

            Activity

              People

              • Votes:
                2 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  15/May/08