diff --git a/mod/quiz/classes/structure.php b/mod/quiz/classes/structure.php index 342af00a7d2..5f56a8adf1a 100644 --- a/mod/quiz/classes/structure.php +++ b/mod/quiz/classes/structure.php @@ -914,6 +914,7 @@ class structure { $maxslot = $DB->get_field_sql('SELECT MAX(slot) FROM {quiz_slots} WHERE quizid = ?', array($this->get_quizid())); $trans = $DB->start_delegated_transaction(); + $DB->delete_records('quiz_slot_tags', array('slotid' => $slot->id)); $DB->delete_records('quiz_slots', array('id' => $slot->id)); for ($i = $slot->slot + 1; $i <= $maxslot; $i++) { $DB->set_field('quiz_slots', 'slot', $i - 1, diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 629edc02f1d..8c8fc91291c 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -183,7 +183,9 @@ function quiz_delete_instance($id) { WHERE slot.quizid = ? AND q.qtype = ?"; $questionids = $DB->get_fieldset_sql($sql, array($quiz->id, 'random')); - // We need to do this before we try and delete randoms, otherwise they would still be 'in use'. + // We need to do the following deletes before we try and delete randoms, otherwise they would still be 'in use'. + $quizslots = $DB->get_fieldset_select('quiz_slots', 'id', 'quizid = ?', array($quiz->id)); + $DB->delete_records_list('quiz_slot_tags', 'slotid', $quizslots); $DB->delete_records('quiz_slots', array('quizid' => $quiz->id)); $DB->delete_records('quiz_sections', array('quizid' => $quiz->id));