Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'MDL-36683_22' of git://github.com/timhunt/moodle into M…

…OODLE_22_STABLE
  • Loading branch information...
commit a9d6e9821126f79383a4801b8283c999822065b0 2 parents b7696aa + 3fec0aa
Eloy Lafuente (stronk7) stronk7 authored
19 question/type/match/backup/moodle2/restore_qtype_match_plugin.class.php
@@ -137,6 +137,25 @@ public function process_match($data) {
137 137 array($newquestionid, $data->questiontext, $data->answertext),
138 138 'id', IGNORE_MULTIPLE);
139 139
  140 + // Not able to find the answer, let's try cleaning the answertext
  141 + // of all the question answers in DB as slower fallback. MDL-36683 / MDL-30018.
  142 + if (!$sub) {
  143 + $params = array('question' => $newquestionid);
  144 + $potentialsubs = $DB->get_records('question_match_sub', array('question' => $newquestionid), '', 'id, questiontext, answertext');
  145 + foreach ($potentialsubs as $potentialsub) {
  146 + // Clean in the same way than {@link xml_writer::xml_safe_utf8()}.
  147 + $cleanquestion = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is', '', $potentialsub->questiontext); // Clean CTRL chars.
  148 + $cleanquestion = preg_replace("/\r\n|\r/", "\n", $cleanquestion); // Normalize line ending.
  149 +
  150 + $cleananswer = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is', '', $potentialsub->answertext); // Clean CTRL chars.
  151 + $cleananswer = preg_replace("/\r\n|\r/", "\n", $cleananswer); // Normalize line ending.
  152 +
  153 + if ($cleanquestion === $data->questiontext && $cleananswer == $data->answertext) {
  154 + $sub = $potentialsub;
  155 + }
  156 + }
  157 + }
  158 +
140 159 // Found, let's create the mapping
141 160 if ($sub) {
142 161 $this->set_mapping('question_match_sub', $oldid, $sub->id);

0 comments on commit a9d6e98

Please sign in to comment.
Something went wrong with that request. Please try again.