While playing with restore I've deteted that gradebook is deleted from delete_course() but it's left without change by remove_course_contents(), that is used when restoring to a existing course.
Because of this some gradebook pieces aren't restored properly (course_outcomes...). I'm going to prevent duplicates in restore of outcomes right now (
the question is... where is the correct place to delete those gradebook parts? Perhaps some of them should happen when removing contents and others when removing course completely. Is split necessary? Or is it safe to move de deletion to remove_course_contents() ?
Just exposing the problem... ciao