From 9a601adc9e2516725e12e3d097b5fa1024a1e020 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 24 May 2016 17:01:33 +0800 Subject: [PATCH] MDL-35987 qtype_multianswer: Prevent restore failure due to bad sequence --- .../moodle2/restore_qtype_multianswer_plugin.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/question/type/multianswer/backup/moodle2/restore_qtype_multianswer_plugin.class.php b/question/type/multianswer/backup/moodle2/restore_qtype_multianswer_plugin.class.php index c61c2dd5f5c..80865b11523 100644 --- a/question/type/multianswer/backup/moodle2/restore_qtype_multianswer_plugin.class.php +++ b/question/type/multianswer/backup/moodle2/restore_qtype_multianswer_plugin.class.php @@ -102,7 +102,11 @@ class restore_qtype_multianswer_plugin extends restore_qtype_plugin { AND bi.itemname = 'question_created'", array($this->get_restoreid())); foreach ($rs as $rec) { - $sequencearr = explode(',', $rec->sequence); + $sequencearr = preg_split('/,/', $rec->sequence, -1, PREG_SPLIT_NO_EMPTY); + if (substr_count($rec->sequence, ',') + 1 != count($sequencearr)) { + $this->task->log('Invalid sequence found in restored multianswer question ' . $rec->id, backup::LOG_WARNING); + } + foreach ($sequencearr as $key => $question) { $sequencearr[$key] = $this->get_mappingid('question', $question); } -- 2.43.0