/** * Send the question type specific files to a new context. * * @param text $qtype The qtype name to send. * @param int $oldctxid Old context id. * @param int $newctxid New context id. * @param \core\progress $progress Progress object to use. */ private function send_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); } } }
protected function define_execution() { global $DB; // Let's process only created questions $questionsrs = $DB->get_recordset_sql("SELECT bi.itemid, bi.newitemid, bi.parentitemid, q.qtype FROM {backup_ids_temp} bi JOIN {question} q ON q.id = bi.newitemid WHERE bi.backupid = ? AND bi.itemname = 'question_created'", array($this->get_restoreid())); foreach ($questionsrs as $question) { // Get question_category mapping, it contains the target context for the question if (!$qcatmapping = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'question_category', $question->parentitemid)) { // Something went really wrong, cannot find the question_category for the question debugging('Error fetching target context for question', DEBUG_DEVELOPER); continue; } // Calculate source and target contexts $oldctxid = $qcatmapping->info->contextid; $newctxid = $qcatmapping->parentitemid; // Add common question files (question and question_answer ones) restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'questiontext', $oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true); restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'generalfeedback', $oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true); restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'answer', $oldctxid, $this->task->get_userid(), 'question_answer', null, $newctxid, true); restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'answerfeedback', $oldctxid, $this->task->get_userid(), 'question_answer', null, $newctxid, true); restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'hint', $oldctxid, $this->task->get_userid(), 'question_hint', null, $newctxid, true); // Add qtype dependent files $components = backup_qtype_plugin::get_components_and_fileareas($question->qtype); foreach ($components as $component => $fileareas) { foreach ($fileareas as $filearea => $mapping) { // Use itemid only if mapping is question_created $itemid = ($mapping == 'question_created') ? $question->itemid : null; restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), $component, $filearea, $oldctxid, $this->task->get_userid(), $mapping, $itemid, $newctxid, true); } } } $questionsrs->close(); }
protected function define_execution() { global $DB; // Get all the different contexts for the final question_categories // annotated along the whole backup $rs = $DB->get_recordset_sql("SELECT DISTINCT qc.contextid\n FROM {question_categories} qc\n JOIN {backup_ids_temp} bi ON bi.itemid = qc.id\n WHERE bi.backupid = ?\n AND bi.itemname = 'question_categoryfinal'", array($this->get_backupid())); // To know about qtype specific components/fileareas $components = backup_qtype_plugin::get_components_and_fileareas(); // Let's loop foreach ($rs as $record) { // We don't need to specify filearea nor itemid as far as by // component and context it's enough to annotate the whole bank files // This backups "questiontext", "generalfeedback" and "answerfeedback" fileareas (all them // belonging to the "question" component backup_structure_dbops::annotate_files($this->get_backupid(), $record->contextid, 'question', null, null); // Again, it is enough to pick files only by context and component // Do it for qtype specific components foreach ($components as $component => $fileareas) { backup_structure_dbops::annotate_files($this->get_backupid(), $record->contextid, $component, null, null); } } $rs->close(); }
protected function define_execution() { global $DB; // Get all the different contexts for the final question_categories // annotated along the whole backup $rs = $DB->get_recordset_sql("SELECT DISTINCT qc.contextid\n FROM {question_categories} qc\n JOIN {backup_ids_temp} bi ON bi.itemid = qc.id\n WHERE bi.backupid = ?\n AND bi.itemname = 'question_categoryfinal'", array($this->get_backupid())); // To know about qtype specific components/fileareas $components = backup_qtype_plugin::get_components_and_fileareas(); // Let's loop foreach ($rs as $record) { // Backup all the file areas the are managed by the core question component. // That is, by the question_type base class. In particular, we don't want // to include files belonging to responses here. backup_structure_dbops::annotate_files($this->get_backupid(), $record->contextid, 'question', 'questiontext', null); backup_structure_dbops::annotate_files($this->get_backupid(), $record->contextid, 'question', 'generalfeedback', null); backup_structure_dbops::annotate_files($this->get_backupid(), $record->contextid, 'question', 'answer', null); backup_structure_dbops::annotate_files($this->get_backupid(), $record->contextid, 'question', 'answerfeedback', null); backup_structure_dbops::annotate_files($this->get_backupid(), $record->contextid, 'question', 'hint', null); backup_structure_dbops::annotate_files($this->get_backupid(), $record->contextid, 'question', 'correctfeedback', null); backup_structure_dbops::annotate_files($this->get_backupid(), $record->contextid, 'question', 'partiallycorrectfeedback', null); backup_structure_dbops::annotate_files($this->get_backupid(), $record->contextid, 'question', 'incorrectfeedback', null); // For files belonging to question types, we make the leap of faith that // all the files belonging to the question type are part of the question definition, // so we can just backup all the files in bulk, without specifying each // file area name separately. foreach ($components as $component => $fileareas) { backup_structure_dbops::annotate_files($this->get_backupid(), $record->contextid, $component, null, null); } } $rs->close(); }