Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'MDL-30018_23' of https://github.com/stronk7/moodle into…

… MOODLE_23_STABLE
  • Loading branch information...
commit bbd89d7b1059e112eef8f0f5409fd44cc4115333 2 parents 0815327 + 8722439
@samhemelryk samhemelryk authored
Showing with 16 additions and 0 deletions.
  1. +16 −0 backup/moodle2/restore_qtype_plugin.class.php
View
16 backup/moodle2/restore_qtype_plugin.class.php
@@ -154,6 +154,22 @@ public function process_question_answer($data) {
AND ' . $DB->sql_compare_text('answer', 255) . ' = ' . $DB->sql_compare_text('?', 255);
$params = array($newquestionid, $data->answertext);
$newitemid = $DB->get_field_sql($sql, $params);
+
+ // Not able to find the answer, let's try cleaning the answertext
+ // of all the question answers in DB as slower fallback. MDL-30018.
+ if (!$newitemid) {
+ $params = array('question' => $newquestionid);
+ $answers = $DB->get_records('question_answers', $params, '', 'id, answer');
+ foreach ($answers as $answer) {
+ // Clean in the same way than {@link xml_writer::xml_safe_utf8()}.
+ $clean = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is','', $answer->answer); // Clean CTRL chars.
+ $clean = preg_replace("/\r\n|\r/", "\n", $clean); // Normalize line ending.
+ if ($clean === $data->answertext) {
+ $newitemid = $data->id;
+ }
+ }
+ }
+
// If we haven't found the newitemid, something has gone really wrong, question in DB
// is missing answers, exception
if (!$newitemid) {
Please sign in to comment.
Something went wrong with that request. Please try again.