protected function after_execute_question() {
        global $DB;

        $essayswithoutoptions = $DB->get_records_sql("
                    SELECT q.*
                      FROM {question} q
                      JOIN {backup_ids_temp} bi ON bi.newitemid = q.id
                 LEFT JOIN {qtype_essay_options} qeo ON qeo.questionid = q.id
                     WHERE q.qtype = ?
                       AND qeo.id IS NULL
                       AND bi.backupid = ?
                       AND bi.itemname = ?
                ", array('essay', $this->get_restoreid(), 'question_created'));

        foreach ($essayswithoutoptions as $q) {
            $defaultoptions = new stdClass();
            $defaultoptions->questionid = $q->id;
            $defaultoptions->responseformat = 'editor';
            $defaultoptions->responserequired = 1;
            $defaultoptions->responsefieldlines = 15;
            $defaultoptions->attachments = 0;
            $defaultoptions->attachmentsrequired = 0;
            $defaultoptions->graderinfo = '';
            $defaultoptions->graderinfoformat = FORMAT_HTML;
            $defaultoptions->responsetemplate = '';
            $defaultoptions->responsetemplateformat = FORMAT_HTML;
            $DB->insert_record('qtype_essay_options', $defaultoptions);
        }
    }
protected function after_execute_question() {
        global $DB;

        $essayswithoutoptions = $DB->get_records_sql("
                    SELECT q.*
                      FROM {question} q
                      JOIN {backup_ids_temp} bi ON bi.newitemid = q.id
                 LEFT JOIN {qtype_essay_options} qeo ON qeo.questionid = q.id
                     WHERE q.qtype = ?
                       AND qeo.id IS NULL
                       AND bi.backupid = ?
                       AND bi.itemname = ?
                ", array('essay', $this->get_restoreid(), 'question_created'));

        foreach ($essayswithoutoptions as $q) {
            $defaultoptions = new stdClass();
            $defaultoptions->questionid = $q->id;
            $defaultoptions->responseformat = 'editor';
            $defaultoptions->responserequired = 1;
            $defaultoptions->responsefieldlines = 15;
            $defaultoptions->attachments = 0;
            $defaultoptions->attachmentsrequired = 0;
            $defaultoptions->graderinfo = '';
            $defaultoptions->graderinfoformat = FORMAT_HTML;
            $defaultoptions->responsetemplate = '';
            $defaultoptions->responsetemplateformat = FORMAT_HTML;
            $DB->insert_record('qtype_essay_options', $defaultoptions);
        }
    }
protected function after_execute_question ( ) { global $ DB ; $ essayswithoutoptions = $ DB -> get_records_sql ( "
                    SELECT q.*
                      FROM {question} q
                      JOIN {backup_ids_temp} bi ON bi.newitemid = q.id
                 LEFT JOIN {qtype_essay_options} qeo ON qeo.questionid = q.id
                     WHERE q.qtype = ?
                       AND qeo.id IS NULL
                       AND bi.backupid = ?
                       AND bi.itemname = ?
                " , array ( 'essay' , $ this -> get_restoreid ( ) , 'question_created' ) ) ; foreach ( $ essayswithoutoptions as $ q ) { $ defaultoptions = new stdClass ( ) ; $ defaultoptions -> questionid = $ q -> id ; $ defaultoptions -> responseformat = 'editor' ; $ defaultoptions -> responserequired = 1 ; $ defaultoptions -> responsefieldlines = 15 ; $ defaultoptions -> attachments = 0 ; $ defaultoptions -> attachmentsrequired = 0 ; $ defaultoptions -> graderinfo = '' ; $ defaultoptions -> graderinfoformat = FORMAT_HTML ; $ defaultoptions -> responsetemplate = '' ; $ defaultoptions -> responsetemplateformat = FORMAT_HTML ; $ DB -> insert_record ( 'qtype_essay_options' , $ defaultoptions ) ; } }
When restoring old data, that does not have the essay options information
in the XML, supply defaults.
When restoring old data that does not have the essay options information in the XML supply defaults .