Restore an activity from .mbz to a course

Restore an activity from .mbz to a course

by Franco Pantoja -
Number of replies: 4
Picture of Particularly helpful Moodlers

Hi Everyone.


We are trying to restore a mbz (it is located in temp/backup/restore/baa6149889a780d8d0dc4aaa903471ee7a45b8c4.mbz) that contains  just a quiz. We want to restore in a created course (eg courseid=49)

// Transaction
      $transaction = $DB->start_delegated_transaction();

      $folder = 'restore';
      $mycourse = 49;

      $controller = new restore_controller($folder, $mycourse,backup::INTERACTIVE_YES, backup::MODE_GENERAL, $USER->id,backup::TARGET_CURRENT_ADDING);
      $controller->get_logger()->set_next( new output_indented_logger(backup::LOG_INFO, false, true) );
      $controller->execute_precheck();
      $controller->execute_plan();
      $controller->destroy();
We found Excepción - Call to a member function set_excluding_activities() on null
How can we do it? The function parameters are right?

Thanks in advanced

Regards!!
Average of ratings: Useful (1)
In reply to Franco Pantoja

Re: Restore an activity from .mbz to a course

by Franco Pantoja -
Picture of Particularly helpful Moodlers

Hi,

In case it can be useful, you have to leave the uncompressed files of the .mbz in moodledata/temp/backup/rs

Then if you want to restore in a created course (eg 48) you may use

     $folder = '/rs/';
     $mycourse = 48;
     echo "Overwriting current content of existing course -> Course ID: $mycourse\n";
     $rc = new restore_controller($folder, $mycourse, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id, 0);
     $rc->execute_precheck();
     $rc->execute_plan();
     $rc->destroy();
Regards!!
Average of ratings: Useful (1)
In reply to Franco Pantoja

Re: Restore an activity from .mbz to a course

by Ken Task -
Picture of Particularly helpful Moodlers

Am not a developer ... so pardon 'stupid' questions ... how else should one learn! smile

First, the /rs/ directory is required ... I see that in the code clip.

But the entire clip above ... what is it?  Entire contents of a [name].php script that resides where?

Or is the code clip inserted into some core code?

Thanks, in advance, Ken


In reply to Ken Task

Re: Restore an activity from .mbz to a course

by Franco Pantoja -
Picture of Particularly helpful Moodlers

No problem Ken smile

the /rs/ directory is my own name in this example, just have to exist  moodledata/temp/backup/rs

here the files of the copy

The code is part of the development of a block, as external plugin


Regards!!