We have Customized Moodle to accelerate the course restore process for courses which have quizzes with images.

 
 
What is Course Restore?

In Moodle we will restore all the backed up courses which will retain all the activities and the course standard structure. We will be performing this course restore either from within a course under the course administration settings or from the Site administration settings.

Course administration settings:    

We can restore courses from course administration settings and the option is present here as observed in the below screenshot.

    
 

Site administration settings:

We can also restore courses from site administration. This is the path which we follow to restore course under the site administrator settings.

Site Administration —-> Courses—->Restore Course—>Choose a backed up course to upload.

 
 

Complication to restore courses which have quizzes with images

  • We are facing a problem where the courses which have quizzes are taking much time to restore in Moodle 2.6+.

  • Because of this a significant amount of time is wasted when we try to restore these courses with quizzes in Moodle. 

  • To resolve this we need to modify the following file at the following path.

  • After performing the code customizations, the courses are restored fast and successfully as observed here.

 
Solution:
Step 1 : Find the filebackup/moodle2/restore_stepslib.php;
Step 2 : Find the following function 
class restore_create_question_filesextends restore_execution_step {
    protected functiondefine_execution() { }
}
Step 3:
Replace the class with the following code :
Codesnippet :
class restore_create_question_filesextends restore_execution_step {
    /** @var arrayQuestion-type specific component items cache. */
    private$qtypecomponentscache = array();
    /**
     *Preform the restore_create_question_files step.
     */
   protected function define_execution() {
        global $DB;
       // Track progress, as this task can take a long time.
       //$progress = $this->task->get_progress();
       //$progress->start_progress($this->get_name(),coreprogressbase::INDETERMINATE);
                
                
                $progress= $this->task->get_progress();
       $progress->start_progress($this->get_name(),core_backup_progress::INDETERMINATE);
        //Parentitemids of question_createds in backup_ids_temp are thecategory it is in.
        // MUST use a recordset, as there isno unique key in the first (or any) column.
        $catqtypes =$DB->get_recordset_sql("SELECT DISTINCT bi.parentitemid AScategoryid, q.qtype as qtype
                                              FROM {backup_ids_temp} bi
                                              JOIN {question} q ON q.id = bi.newitemid
                                             WHERE bi.backupid = ?
                                               AND bi.itemname =’question_created’
                                          ORDER BY categoryid ASC", array($this->get_restoreid()));
       $currentcatid = -1;
        foreach ($catqtypes as$categoryid => $row) {
            $qtype = $row->qtype;
           // Check if we are in a new category.
            if($currentcatid !== $categoryid) {
                // Reportprogress for each category.
               $progress->progress();
                if(!$qcatmapping =restore_dbops::get_backup_ids_record($this->get_restoreid(),
                       ‘question_category’, $categoryid)) {
                   // Something went really wrong, cannot find thequestion_category for the question_created records.
                   debugging(‘Error fetching target context for question’,DEBUG_DEVELOPER);
                    continue;
               }
                // Calculate source and targetcontexts.
                $oldctxid =$qcatmapping->info->contextid;
                $newctxid =$qcatmapping->parentitemid;
               $this->send_common_files($oldctxid, $newctxid, $progress);
               $currentcatid = $categoryid;
            }
           $this->send_qtype_files($qtype, $oldctxid, $newctxid,$progress);
        }
        $catqtypes->close();
       $progress->end_progress();
    }
    /**
    * Send the common question files to a new context.
     *
    * @param int             $oldctxid Old context id.
     *@param int             $newctxid New context id.
     * @paramcoreprogress  $progress Progress object to use.
     */
   private function send_common_files($oldctxid, $newctxid, $progress){
        // Add common question files (question andquestion_answer ones).
       restore_dbops::send_files_to_pool($this->get_basepath(),$this->get_restoreid(), ‘question’, ‘questiontext’,
               $oldctxid, $this->task->get_userid(), ‘question_created’,null, $newctxid, true, $progress);
       restore_dbops::send_files_to_pool($this->get_basepath(),$this->get_restoreid(), ‘question’, ‘generalfeedback’,
               $oldctxid, $this->task->get_userid(),’question_created’, null, $newctxid, true, $progress);
       restore_dbops::send_files_to_pool($this->get_basepath(),$this->get_restoreid(), ‘question’, ‘answer’,
               $oldctxid, $this->task->get_userid(), ‘question_answer’, null,$newctxid, true, $progress);
       restore_dbops::send_files_to_pool($this->get_basepath(),$this->get_restoreid(), ‘question’, ‘answerfeedback’,
               $oldctxid, $this->task->get_userid(),’question_answer’, null, $newctxid, true, $progress);
       restore_dbops::send_files_to_pool($this->get_basepath(),$this->get_restoreid(), ‘question’, ‘hint’,
               $oldctxid, $this->task->get_userid(), ‘question_hint’, null,$newctxid, true, $progress);
       restore_dbops::send_files_to_pool($this->get_basepath(),$this->get_restoreid(), ‘question’, ‘correctfeedback’,
               $oldctxid, $this->task->get_userid(),’question_created’, null, $newctxid, true, $progress);
       restore_dbops::send_files_to_pool($this->get_basepath(),$this->get_restoreid(), ‘question’, ‘partiallycorrectfeedback’,
               $oldctxid, $this->task->get_userid(),’question_created’, null, $newctxid, true, $progress);
       restore_dbops::send_files_to_pool($this->get_basepath(),$this->get_restoreid(), ‘question’, ‘incorrectfeedback’,
               $oldctxid, $this->task->get_userid(),’question_created’, null, $newctxid, true, $progress);
    }
   /**
     * Send the question type specific files to a newcontext.
     *
     * @param text            $qtype Theqtype name to send.
     * @param int             $oldctxid Oldcontext id.
     * @param int             $newctxid New contextid.
     * @param coreprogress  $progress Progress object touse.
     */
        
    private functionsend_qtype_files($qtype, $oldctxid, $newctxid, $progress) {
       if (!isset($this->qtypecomponentscache[$qtype])) {
           $this->qtypecomponentscache[$qtype] =backup_qtype_plugin::get_components_and_fileareas($qtype);
       }
        $components = $this->qtypecomponentscache[$qtype];
       foreach ($components as $component => $fileareas) {
           foreach ($fileareas as $filearea => $mapping) {
               restore_dbops::send_files_to_pool($this->get_basepath(),$this->get_restoreid(), $component, $filearea,
                       $oldctxid, $this->task->get_userid(), $mapping, null,$newctxid, true, $progress);
            }
        }
   }
}

Please check our next blog on adding value to enrolled courses and related search functionality in moodle