Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sudoku using glossary does not work with Moodle 4.x #60

Open
ak4t0sh opened this issue Sep 28, 2023 · 0 comments
Open

sudoku using glossary does not work with Moodle 4.x #60

ak4t0sh opened this issue Sep 28, 2023 · 0 comments

Comments

@ak4t0sh
Copy link
Contributor

ak4t0sh commented Sep 28, 2023

Steps to reproduce

  • Create a sudoku which is using glossary as source.
  • Try to launch the game.

Result

Unknown column 'qv.questionbankentryid' in 'field list'
SELECT ge.id,qv.questionbankentryid,qv.version FROM mdl_glossary_entries ge WHERE (glossaryid='1' OR sourceglossaryid='1') ORDER BY qv.questionbankentryid,qv.version DESC
[array (
)]
Error code: dmlreadexception 

line 494 of /lib/dml/moodle_database.php: dml_read_exception thrown
line 293 of /lib/dml/moodle_read_slave_trait.php: call to moodle_database->query_end()
line 1282 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->query_end()
line 621 of /mod/game/locallib.php: call to mysqli_native_moodle_database->get_records_sql()
line 580 of /mod/game/locallib.php: call to game_questions_selectrandom_detail()
line 79 of /mod/game/sudoku/play.php: call to game_questions_selectrandom()
line 280 of /mod/game/attempt.php: call to game_sudoku_continue()
line 242 of /mod/game/attempt.php: call to game_create()
line 40 of /mod/game/attempt.php: call to game_do_attempt()

Analysis

In 9316457 you introduced question/quiz specific fields in the query used in

$sql = "SELECT $idfield{$fields} FROM $table WHERE $select $order";
making it no more compatible with glossary as source.

Solution / Workaround

Waiting a cleaner solution below an ugly patch I've done as workaround to prevent glossaries to crash.

---
 locallib.php | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/locallib.php b/locallib.php
index 87118bd..595bbd3 100644
--- a/locallib.php
+++ b/locallib.php
@@ -614,8 +614,9 @@ function game_questions_selectrandom_detail( $table, $select, $idfield="id", $co
     global $DB;
 
     $versions = game_get_moodle_version() >= '04.00';
-    $fields = $versions ? ',qv.questionbankentryid,qv.version' : '';
-    $order = $versions ? ' ORDER BY qv.questionbankentryid,qv.version DESC' : '';
+    $usequestionbank = !in_array($table, ["{glossary_entries} ge"]);
+    $fields = ($usequestionbank && $versions) ? ',qv.questionbankentryid,qv.version' : '';
+    $order = ($usequestionbank && $versions) ? ' ORDER BY qv.questionbankentryid,qv.version DESC' : '';
 
     $sql = "SELECT $idfield{$fields} FROM $table WHERE $select $order";
     if (($recs = $DB->get_records_sql( $sql)) == false) {
@@ -626,7 +627,7 @@ function game_questions_selectrandom_detail( $table, $select, $idfield="id", $co
     $map = array();
     $a = array();
     foreach ($recs as $rec) {
-        if( $versions) {
+        if( $usequestionback && $versions) {
             if( array_key_exists( $rec->questionbankentryid, $map)) {
                 continue;
             } else {
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant