MDL-33424 Images missing when restoring a 1.9 backup
[moodle.git] / question / type / match / backup / moodle1 / lib.php
CommitLineData
0a562baf
DM
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * @package qtype
20 * @subpackage match
21 * @copyright 2011 David Mudrak <david@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27/**
28 * Matching question type conversion handler
29 */
30class moodle1_qtype_match_handler extends moodle1_qtype_handler {
31
32 /**
33 * @return array
34 */
35 public function get_question_subpaths() {
36 return array(
37 'MATCHOPTIONS',
38 'MATCHS/MATCH'
39 );
40 }
41
42 /**
43 * Appends the match specific information to the question
44 */
45 public function process_question(array $data, array $raw) {
46 global $CFG;
47
48 // populate the list of matches first to get their ids
49 // note that the field is re-populated on restore anyway but let us
50 // do our best to produce valid backup files
51 $matchids = array();
52 if (isset($data['matchs']['match'])) {
53 foreach ($data['matchs']['match'] as $match) {
54 $matchids[] = $match['id'];
55 }
56 }
57
58 // convert match options
c9b8a56f
TH
59 if (isset($data['matchoptions'])) {
60 $matchoptions = $data['matchoptions'][0];
61 } else {
62 $matchoptions = array('shuffleanswers' => 1);
63 }
0a562baf
DM
64 $matchoptions['id'] = $this->converter->get_nextid();
65 $matchoptions['subquestions'] = implode(',', $matchids);
66 $this->write_xml('matchoptions', $matchoptions, array('/matchoptions/id'));
67
68 // convert matches
69 $this->xmlwriter->begin_tag('matches');
70 if (isset($data['matchs']['match'])) {
71 foreach ($data['matchs']['match'] as $match) {
72 // replay the upgrade step 2009072100
73 $match['questiontextformat'] = 0;
74 if ($CFG->texteditors !== 'textarea' and $data['oldquestiontextformat'] == FORMAT_MOODLE) {
75 $match['questiontext'] = text_to_html($match['questiontext'], false, false, true);
76 $match['questiontextformat'] = FORMAT_HTML;
77 } else {
78 $match['questiontextformat'] = $data['oldquestiontextformat'];
79 }
80
888b6ee5
JMV
81 $match['questiontext'] = $this->migrate_files(
82 $match['questiontext'], 'qtype_match', 'subquestion', $match['id']);
0a562baf
DM
83 $this->write_xml('match', $match, array('/match/id'));
84 }
85 }
86 $this->xmlwriter->end_tag('matches');
87 }
88}