Merge branch 'MDL-53140-master' of git://github.com/rezaies/moodle
[moodle.git] / lib / questionlib.php
index e0b3014..a089358 100644 (file)
@@ -380,6 +380,11 @@ function question_delete_question($questionid) {
     // Finally delete the question record itself
     $DB->delete_records('question', array('id' => $questionid));
     question_bank::notify_question_edited($questionid);
+
+    // Log the deletion of this question.
+    $event = \core\event\question_deleted::create_from_question_instance($question);
+    $event->add_record_snapshot('question', $question);
+    $event->trigger();
 }
 
 /**
@@ -673,7 +678,7 @@ function question_move_questions_to_category($questionids, $newcategoryid) {
             array('id' => $newcategoryid));
     list($questionidcondition, $params) = $DB->get_in_or_equal($questionids);
     $questions = $DB->get_records_sql("
-            SELECT q.id, q.qtype, qc.contextid, q.idnumber
+            SELECT q.id, q.qtype, qc.contextid, q.idnumber, q.category
               FROM {question} q
               JOIN {question_categories} qc ON q.category = qc.id
              WHERE  q.id $questionidcondition", $params);
@@ -703,6 +708,11 @@ function question_move_questions_to_category($questionids, $newcategoryid) {
             $q->idnumber = $question->idnumber . '_' . $unique;
             $DB->update_record('question', $q);
         }
+
+        // Log this question move.
+        $event = \core\event\question_moved::create_from_question_instance($question, context::instance_by_id($question->contextid),
+                ['oldcategoryid' => $question->category, 'newcategoryid' => $newcategoryid]);
+        $event->trigger();
     }
 
     // Move the questions themselves.