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

Manual grade items with calculations not restoring properly.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • 1.9.1
    • 1.9
    • Backup, Gradebook
    • None
    • MOODLE_19_STABLE
    • MOODLE_19_STABLE

      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.

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

            skodak Petr Skoda
            tomtrueluk Tom Trueluk (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.