General developer forum

Programatically restore forum activity from backup file

Picture of Eva E
Programatically restore forum activity from backup file


I need to programatically back up and restore a forum activity.

I am trying to follow the restore process described here but I am getting errors. 

I have my backup file in $CFG->dataroot . '/temp/backup/test/' named backup123.mbz, and I want to restore it into course id 456, so I am doing:

$folder             = '/test/'; // as found in: $CFG->dataroot . '/temp/backup/'
$courseid         = '456'; //
$user_doing_the_backup   = 2; // e.g. 2 == admin
// Restore backup into course.
$controller = new restore_controller($folder, $courseid,
        backup::INTERACTIVE_NO, backup::MODE_SAMESITE, $user_doing_the_backup,

I am not sure what to use if I am trying to restore into an existing course, so I go with TARGET_EXISTING_ADDING, I have tried all other options as well (TARGET_CURRENT_DELETING, TARGET_CURRENT_ADDING, TARGET_EXISTING_DELETING, TARGET_EXISTING_ADDING) but all produce the same error. For the folder i tried 'test' and 'test/' and '/test/' and tried adding the exact backup file name as well, all produce the same error. In fact, even if I use the code as it is straight out of the link above and try to restore my activity into a new course (as is the case in the link) I still get the exact same error which is:

Default exception handler: error/cannot_precheck_wrong_status Debug: 
Error code: cannot_precheck_wrong_status
$a contents: 200

Someone here had the same error however I cannot message them or comment on that post to find out the exact solution.

Someone here seems to be doing it successfully, I have tried using literally their code, still getting the error above.

Any help is greatly appreciated.

Average of ratings: -