Skip to content

Commit

Permalink
fix: support empty question forms
Browse files Browse the repository at this point in the history
  • Loading branch information
MHajoha committed Mar 13, 2024
1 parent 720d98a commit 390ff62
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion classes/question_service.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public function get_question(int $questionid): object {
* @throws moodle_exception
*/
public function upsert_question(object $question): void {
if (!isset($question->qpy_form)) {
// This happens when the package defines an empty options form, which we do want to support.
$question->qpy_form = [];
}

global $DB;

$pkgversionid = $this->get_package($question->qpy_package_hash);
Expand All @@ -105,7 +110,7 @@ public function upsert_question(object $question): void {
$response = $this->api->create_question(
$question->qpy_package_hash,
$existingrecord ? $existingrecord->state : null,
(object)$question->qpy_form ?? new stdClass()
(object)$question->qpy_form
);

if ($existingrecord) {
Expand Down

0 comments on commit 390ff62

Please sign in to comment.