Restore Deleted Quiz Grades

This forum post has been removed

Number of replies: 6
The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

Re: Restore Deleted Quiz Grades

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

In the database there is the grade_..._history tables. The data may be in there, but I don't know step-by-step instructions for getting the data out of there.

Average of ratings: Useful (1)
In reply to Deleted user

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

Re: Restore Deleted Quiz Grades

by Michael Haskell -

I was able to retrieve grades for an accidentally deleted quiz using the SQL code below. Hope this helps someone else.

-- find grades for students
-- replace <old_grade_item_id> with the id of the quiz that was deleted.
-- if you don't know the id, inspect the grade_items_history table using the other queries below.

select u.username, from_unixtime(ggh.timemodified), source, ggh.finalgrade from mdl_grade_grades_history ggh
join mdl_user u on ggh.userid = u.id
where ggh.itemid= <old_grade_item_id>
and ggh.action = 3 -- delete action
and ggh.finalgrade is not null
order by u.username asc


-- Find the 'Old ID' by inspecting the grade item history
-- There may be multiple entries
-- The 'source' should be mod/quiz and should have a modification
-- date around when you expect the quiz was deleted.

select * from mdl_grade_items_history gih
where gih.courseid = <id_of_course>

select * from mdl_grade_items_history gih
where gih.loggeduser = <id_of_user_that_deleted_the_grade_item>

Average of ratings: Useful (5)
In reply to Michael Haskell

Re: Restore Deleted Quiz Grades

by M Horn -

Thank you SO much! This query was a life saver! 

(It is now saved under my SQL queries on my server; I make use of the Ad-hoc Database Queries plugin - https://moodle.org/plugins/view/report_customsql)

Average of ratings: Useful (1)
In reply to M Horn

Re: Restore Deleted Quiz Grades

by Michael Haskell -

M Horn,

Could you share your ad-hoc query with the community.  That plugin is very convenient and it seems like this happens more often than you would think. smile

- Michael H.

In reply to Michael Haskell

Re: Restore Deleted Quiz Grades

by Paul Lindgreen -
Picture of Particularly helpful Moodlers

Thanks for the query.

I just used it to retrieve grades for an accidentally deleted assignment, immensely helpful considering the alternative was restoring a tape backup!