I'm trying to programatically restore single activity scorm courses. I've created a backup of the course as I want it and then hand-edited the content within the backup mbz to do extra tweaks, then recompressed it.
I am able to use the course restore interface to restore the backup into a new course in a a category of my choosing. When opening the course, I see the course format is scorm and the package is present all as expected.
When I perform the same via code (effectively https://docs.moodle.org/dev/Restore_2.0_for_developers#Automatically_triggering_restore_in_code) the same backup file results in the course being created as a single activity FORUM. I can see that the mdl_course_format_options record for the newly restored course has its activity type value set to 'forum', even though inside the extracted backup the activitytype is set to scorm 'scorm' (defined in the moodledata/temp/backup/temp-id/course/course.xml). The scorm record turns up; the course_sections are created and the course_modules are pointing to the correct instance - but the course format activity type is just wrong.
I've fiddled around with different types of backups and it seems like singleactivity courses that are restored through the interface work differently than through code, but can't figure out why. I've read so much of the
messcode inside the backup folder trying to follow the restore controller logic that my brain has turned to mush, and I can hardly understand how this system works at the best of times.
At the moment I'm having to kludge the course_format_options record after executing the plan, e.g.
$data = $DB->get_record('course_format_options', array('courseid'=>$newcourseid,'sectionid'=>0,'name'=>'activitytype'), '*', MUST_EXIST);
$data->value = 'scorm';
which kinda sucks. What else can I do?