MDL-66834 Questions: add transaction, move trigger

This commit is contained in:
Peter Eliyahu Kornfeld
2020-02-03 12:28:19 +02:00
committed by GitHub
parent 7f697f7a44
commit 90ae31ecb1
+15 -10
View File
@@ -325,6 +325,9 @@ class question_type {
public function save_question($question, $form) {
global $USER, $DB, $OUTPUT;
// The actuall update/insert done with multiple DB access, so we do it in a transaction.
$transaction = $DB->start_delegated_transaction ();
list($question->category) = explode(',', $form->category);
$context = $this->get_context_by_category_id($question->category);
@@ -414,16 +417,6 @@ class question_type {
}
$DB->update_record('question', $question);
if ($newquestion) {
// Log the creation of this question.
$event = \core\event\question_created::create_from_question_instance($question, $context);
$event->trigger();
} else {
// Log the update of this question.
$event = \core\event\question_updated::create_from_question_instance($question, $context);
$event->trigger();
}
// Now to save all the answers and type-specific options.
$form->id = $question->id;
$form->qtype = $question->qtype;
@@ -452,6 +445,18 @@ class question_type {
$DB->set_field('question', 'version', question_hash($question),
array('id' => $question->id));
if ($newquestion) {
// Log the creation of this question.
$event = \core\event\question_created::create_from_question_instance($question, $context);
$event->trigger();
} else {
// Log the update of this question.
$event = \core\event\question_updated::create_from_question_instance($question, $context);
$event->trigger();
}
$transaction->allow_commit ();
return $question;
}