Skip to content

Commit 8681463

Browse files
committed
Bug fix: updates not working in Moodle 4.6 or later.
1 parent 92853eb commit 8681463

File tree

6 files changed

+38
-18
lines changed

6 files changed

+38
-18
lines changed

changehistory.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# CHANGE HISTORY
22

3+
4+
### 23 February 2025. 5.6.2
5+
6+
* Bug fix: With Moodle 4.6 or later, updates were not working.
7+
8+
### 13 February 2025. 5.6.1
9+
10+
* New features:
11+
* Preliminary implementation of Moodle 5 compatibility. Tested only with courses imported
12+
from earlier Moodles, which do not include shared question banks.
13+
* Bulk tester includes an option to purge the grade cache for the course(s) being tested.
14+
* jobe-host is now displayed in bulk-tester results.
15+
16+
* Some on-going code tidying.
17+
318
### 23 January 2025. 5.5.0
419

520
* New features:

db/builtin_PROTOTYPES.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ disp('#<ab@17943918#@>#');
952952
<coderunnertype>pascal_function</coderunnertype>
953953
<prototypetype>1</prototypetype>
954954
<allornothing>1</allornothing>
955-
<penaltyregime>33.3, 66.7, ...</penaltyregime>
955+
<penaltyregime>10, 20, ...</penaltyregime>
956956
<precheck>0</precheck>
957957
<hidecheck>0</hidecheck>
958958
<showsource>0</showsource>
@@ -1019,7 +1019,7 @@ end.
10191019
<coderunnertype>pascal_program</coderunnertype>
10201020
<prototypetype>1</prototypetype>
10211021
<allornothing>1</allornothing>
1022-
<penaltyregime>33.3, 66.7, ...</penaltyregime>
1022+
<penaltyregime>10, 20, ...</penaltyregime>
10231023
<precheck>0</precheck>
10241024
<hidecheck>0</hidecheck>
10251025
<showsource>0</showsource>

db/install.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020

2121
function xmldb_qtype_coderunner_install() {
2222
require_once(__DIR__ . '/upgradelib.php');
23-
update_question_types(true);
23+
update_question_types();
2424
}

db/upgrade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ function xmldb_qtype_coderunner_upgrade($oldversion) {
434434
}
435435

436436
require_once(__DIR__ . '/upgradelib.php');
437-
update_question_types(false);
437+
update_question_types();
438438

439439
return true;
440440
}

db/upgradelib.php

+17-12
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,34 @@
5454
*
5555
* A further complication is that during an install of both Moodle and
5656
* CodeRunner together, the question bank module is installed after the question
57-
* type, so we can't load the prototypes during the install. Instead we
58-
* schedule a task to do it later.
57+
* type, so we can't load the prototypes during the install.
5958
*
6059
* @return bool true if successful
6160
*/
6261

6362
/**
64-
* Schedule or perform the question type update depending on whether this is an
65-
* install or an upgrade.
66-
* @param bool $isinstall true if this is being called during install.
63+
* Update the question types. In Moode 4.6 or later, this is done in a
64+
* scheduled task that runs after the install/update.
6765
* @return bool true if successful
6866
*/
69-
function update_question_types($isinstall = false) {
70-
if ($isinstall) {
71-
// During install, schedule the task for later execution.
67+
function update_question_types() {
68+
if (qtype_coderunner_util::using_mod_qbank()) {
69+
// In Moodle >=4.6, we need to update the question prototypes in a scheduled task
70+
// because (a) if this is an install, the qbank module hasn't been installed yet and
71+
// (b) we need to call question_bank_helper::get_default_open_instance_system_type
72+
// which cannot be used during install/upgrade.
7273
$task = new qtype_coderunner\task\qtype_coderunner_setup_question_prototypes();
7374
core\task\manager::queue_adhoc_task($task);
7475
return true;
7576
} else {
76-
// During upgrade, execute immediately.
77+
// In Moodle 4.5 or earlier, we can execute the update immediately.
7778
return update_question_types_internal();
7879
}
7980
}
8081

8182
/**
82-
* The function that actually does the update. May be called directly during update
83-
* or indirectly from the queued task during install.
83+
* The function that actually does the update. May be called directly during update if using
84+
* moodle4.5 or earier, or indirectly from the queued task with later versions.
8485
*/
8586
function update_question_types_internal() {
8687
mtrace("Setting up CodeRunner question prototypes...");
@@ -108,6 +109,10 @@ function update_question_types_internal() {
108109
* If we can find an existing CR_PROTOTYPES category in the (defunct) system context,
109110
* move it to the new top category in the question bank instance on the front page.
110111
* Then delete all existing prototypes in the new top category and reload them.
112+
* Note that this code is always running in a post-update scheduled task, because
113+
* question_bank_helper::get_default_open_instance_system_type, needed by
114+
* moodle5_top_category, cannot be used during update/install.
115+
*
111116
* @return bool true if successful
112117
*/
113118
function update_question_types_with_qbank() {
@@ -196,7 +201,7 @@ function moodle5_top_category() {
196201
$newmod = question_bank_helper::create_default_open_instance($course, $bankname, question_bank_helper::TYPE_SYSTEM);
197202
}
198203
} catch (Exception $e) {
199-
throw new coding_exception('Upgrade failed: error creating system question bank');
204+
throw new coding_exception("Upgrade failed: error creating system question bank: $e");
200205
}
201206
$newtopcategory = question_get_top_category($newmod->context->id, true);
202207
return $newtopcategory;

version.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
defined('MOODLE_INTERNAL') || die();
2424

25-
$plugin->version = 2025021300;
25+
$plugin->version = 2025022300;
2626
$plugin->requires = 2023100900; // Moodle 4.3
2727
$plugin->cron = 0;
2828
$plugin->component = 'qtype_coderunner';
2929
$plugin->maturity = MATURITY_STABLE;
30-
$plugin->release = '5.6.0';
30+
$plugin->release = '5.6.2';
3131

3232
$plugin->dependencies = [
3333
'qbehaviour_adaptive_adapted_for_coderunner' => 2024041800,

0 commit comments

Comments
 (0)