Skip to content

Commit 9d617d0

Browse files
committed
Merge from development
2 parents 5fe31dc + 8f322d7 commit 9d617d0

File tree

383 files changed

+12057
-13113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

383 files changed

+12057
-13113
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,15 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
include:
12+
- php: '8.3'
13+
moodle-branch: 'MOODLE_405_STABLE'
14+
database: 'mariadb'
1215
- php: '8.2'
1316
moodle-branch: 'MOODLE_404_STABLE'
1417
database: 'pgsql'
1518
- php: '8.1'
1619
moodle-branch: 'MOODLE_403_STABLE'
1720
database: 'mariadb'
18-
- php: '8.0'
19-
moodle-branch: 'MOODLE_402_STABLE'
20-
database: 'pgsql'
21-
- php: '7.4'
22-
moodle-branch: 'MOODLE_401_STABLE'
23-
database: 'pgsql'
24-
- php: '7.3'
25-
moodle-branch: 'MOODLE_400_STABLE'
26-
database: 'mariadb'
27-
2821
services:
2922
postgres:
3023
image: postgres:13

amd/build/ui_ace_gapfiller.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/ui_ace_gapfiller.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/ui_ace_gapfiller.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ define(['jquery'], function($) {
592592
// Create markers
593593
this.editor.session.addMarker(this.range, "ace-gap-outline", "text", true);
594594
this.editor.session.addMarker(this.range, "ace-gap-background", "text", false);
595+
const startPosition = this.range.start;
596+
this.editor.session.insert(startPosition, "<!-- BEGIN CODE GAP -->");
595597
}
596598

597599
Gap.prototype.cursorInGap = function(cursor) {

backup/moodle2/restore_qtype_coderunner_plugin.class.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,84 @@ public function process_coderunner_options($data) {
143143
}
144144
// Nothing to remap if the question already existed.
145145
}
146+
147+
// Add the extra methods required by MDL-83541.
148+
// #[Override] // This breaks the restore at run time if used with older versions of moodle so commented out.
149+
public static function convert_backup_to_questiondata(array $backupdata): stdClass {
150+
$questiondata = parent::convert_backup_to_questiondata($backupdata);
151+
$qtype = $questiondata->qtype;
152+
153+
if (isset($backupdata["plugin_qtype_{$qtype}_question"]['coderunner_testcases'])) {
154+
$questiondata->options->testcases = [];
155+
foreach ($backupdata["plugin_qtype_{$qtype}_question"]['coderunner_testcases']['coderunner_testcase'] as $record) {
156+
$testcase = new stdClass();
157+
$fields = [ 'testcode', 'testtype', 'expected', 'useasexample', 'display',
158+
'hiderestiffail', 'mark', 'stdin', 'extra'];
159+
foreach ($fields as $field) {
160+
if (isset($record[$field])) { // Old backups don't have testtype.
161+
$testcase->$field = $record[$field];
162+
}
163+
}
164+
$questiondata->options->testcases[] = $testcase;
165+
}
166+
}
167+
168+
if (isset($backupdata["plugin_qtype_{$qtype}_question"]['coderunner_options'])) {
169+
$questiondata->options = (object) array_merge(
170+
(array) $questiondata->options,
171+
$backupdata["plugin_qtype_{$qtype}_question"]['coderunner_options']['coderunner_option'][0]
172+
);
173+
}
174+
175+
return $questiondata;
176+
}
177+
178+
// #[Override] // This breaks the restore at run time if used with older versions of moodle so commented out.
179+
protected function define_excluded_identity_hash_fields(): array {
180+
return [
181+
'/answers',
182+
'/hints',
183+
'/prototype',
184+
'/options/customise',
185+
'/options/templateparamsevald',
186+
'/options/testcases/id',
187+
'/options/testcases/questionid',
188+
];
189+
}
190+
191+
// #[Override] // This breaks the restore at run time if used with older versions of moodle so commented out.
192+
public static function remove_excluded_question_data(stdClass $questiondata, array $excludefields = []): stdClass {
193+
if (isset($questiondata->options->customise)) {
194+
unset($questiondata->options->customise);
195+
}
196+
if (isset($questiondata->prototype)) {
197+
unset($questiondata->prototype);
198+
}
199+
if (isset($questiondata->answers)) {
200+
unset($questiondata->answers);
201+
}
202+
if (isset($questiondata->options->answers)) {
203+
unset($questiondata->options->answers);
204+
}
205+
if (isset($questiondata->hints)) {
206+
unset($questiondata->hints);
207+
}
208+
209+
// Hack: convert all cases of allowmultiplestdins being false to null.
210+
if (isset($questiondata->options) && ! ($questiondata->options->allowmultiplestdins ?? null)) {
211+
$questiondata->options->allowmultiplestdins = null;
212+
}
213+
214+
if (isset($questiondata->options->testcases)) {
215+
foreach ($questiondata->options->testcases as $testcase) {
216+
if (isset($testcase->id)) {
217+
unset($testcase->id);
218+
}
219+
if (isset($testcase->questionid)) {
220+
unset($testcase->questionid);
221+
}
222+
}
223+
}
224+
return parent::remove_excluded_question_data($questiondata, $excludefields);
225+
}
146226
}

bulktest.php

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,58 @@
2525
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2626
*/
2727

28+
namespace qtype_coderunner;
29+
2830
define('NO_OUTPUT_BUFFERING', true);
2931

3032
require_once(__DIR__ . '/../../../config.php');
3133
require_once($CFG->libdir . '/questionlib.php');
3234

3335
// Get the parameters from the URL.
34-
$contextid = required_param('contextid', PARAM_INT);
36+
$contextid = required_param('contextid', PARAM_INT); // Set to 0 if providing a list of question IDs to check.
3537
$categoryid = optional_param('categoryid', null, PARAM_INT);
38+
$randomseed = optional_param('randomseed', -1, PARAM_INT);
39+
$repeatrandomonly = optional_param('repeatrandomonly', 1, PARAM_INT);
40+
$nruns = optional_param('nruns', 1, PARAM_INT);
41+
$questionids = optional_param('questionids', '', PARAM_RAW); // A list of specific questions to check, eg, for rechecking failed tests.
42+
$clearcachefirst = optional_param('clearcachefirst', 0, PARAM_INT);
43+
3644

3745
// Login and check permissions.
38-
$context = context::instance_by_id($contextid);
3946
require_login();
47+
$context = \context::instance_by_id($contextid);
4048
require_capability('moodle/question:editall', $context);
41-
$PAGE->set_url('/question/type/coderunner/bulktest.php', ['contextid' => $context->id]);
49+
50+
$urlparams = ['contextid' => $context->id, 'categoryid' => $categoryid, 'randomseed' => $randomseed,
51+
'repeatrandomonly' => $repeatrandomonly, 'nruns' => $nruns, 'clearcachefirst' => $clearcachefirst, 'questionids' => $questionids];
52+
$PAGE->set_url('/question/type/coderunner/bulktest.php', $urlparams);
4253
$PAGE->set_context($context);
4354
$title = get_string('bulktesttitle', 'qtype_coderunner', $context->get_context_name());
4455
$PAGE->set_title($title);
4556

57+
if ($questionids != '') {
58+
$questionids = array_map('intval', explode(',', $questionids));
59+
} else {
60+
$questionids = [];
61+
}
62+
4663
if ($context->contextlevel == CONTEXT_MODULE) {
4764
// Calling $PAGE->set_context should be enough, but it seems that it is not.
4865
// Therefore, we get the right $cm and $course, and set things up ourselves.
4966
$cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST);
5067
$PAGE->set_cm($cm, $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST));
5168
}
5269

70+
5371
// Create the helper class.
54-
$bulktester = new qtype_coderunner_bulk_tester();
72+
$bulktester = new bulk_tester(
73+
$context,
74+
$categoryid,
75+
$randomseed,
76+
$repeatrandomonly,
77+
$nruns,
78+
$clearcachefirst
79+
);
5580

5681
// Was: Release the session, so the user can do other things while this runs.
5782
// Seems like Moodle 4.5 doesn't like this - gives an error. So commented out.
@@ -60,11 +85,23 @@
6085

6186
// Display.
6287
echo $OUTPUT->header();
63-
echo $OUTPUT->heading($title);
88+
echo $OUTPUT->heading($title, 4);
89+
90+
// Release the session, so the user can do other things while this runs.
91+
\core\session\manager::write_close();
92+
93+
94+
ini_set('memory_limit', '1024M'); // For big question banks - TODO: make this a setting?
6495
6596
// Run the tests.
66-
[$numpasses, $failingtests, $missinganswers] = $bulktester->run_all_tests_for_context($context, $categoryid);
97+
if (count($questionids) == 0) {
98+
$bulktester->run_all_tests_for_context();
99+
} else {
100+
$bulktester->run_all_tests_for_context($questionids);
101+
}
102+
103+
// Prints the summary of failed/missing tests
104+
$bulktester->print_overall_result();
105+
67106

68-
// Display the final summary.
69-
$bulktester->print_overall_result($numpasses, $failingtests, $missinganswers);
70107
echo $OUTPUT->footer();

bulktestall.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
* @copyright 2016 Richard Lobb, The University of Canterbury
2424
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2525
*/
26+
namespace qtype_coderunner;
27+
28+
use context;
29+
use context_system;
30+
use context_course;
31+
use html_writer;
32+
use moodle_url;
2633

2734
define('NO_OUTPUT_BUFFERING', true);
2835

@@ -45,8 +52,7 @@
4552
$title = get_string('bulktesttitle', 'qtype_coderunner', $context->get_context_name());
4653
$PAGE->set_title($title);
4754

48-
// Create the helper class.
49-
$bulktester = new qtype_coderunner_bulk_tester();
55+
5056
$numpasses = 0;
5157
$allfailingtests = [];
5258
$allmissinganswers = [];
@@ -60,15 +66,20 @@
6066
echo $OUTPUT->heading($title, 1);
6167

6268
// Run the tests.
63-
foreach ($bulktester->get_num_coderunner_questions_by_context() as $contextid => $numcoderunnerquestions) {
69+
ini_set('memory_limit', '2048M'); // For big question banks - TODO: make this a setting?
70+
$contextdata = bulk_tester::get_num_coderunner_questions_by_context();
71+
foreach ($contextdata as $contextid => $numcoderunnerquestions) {
6472
if ($skipping && $contextid != $startfromcontextid) {
6573
continue;
6674
}
6775
$skipping = false;
68-
6976
$testcontext = context::instance_by_id($contextid);
7077
if (has_capability('moodle/question:editall', $context)) {
78+
$PAGE->set_context($testcontext); // Helps grading cache pickup right course id.
79+
$bulktester = new bulk_tester($testcontext);
7180
echo $OUTPUT->heading(get_string('bulktesttitle', 'qtype_coderunner', $testcontext->get_context_name()));
81+
$adminpluginscachelink = html_writer::link(new moodle_url('/cache/admin.php'), 'admin-plugins-cache', ['target' => '_blank']);
82+
echo html_writer::tag('p', 'Note: Grading cache not cleared -- do it from ' . $adminpluginscachelink . ' if you really want to clear the cache for all course!');
7283
echo html_writer::tag('p', html_writer::link(
7384
new moodle_url(
7485
'/question/type/coderunner/bulktestall.php',
@@ -77,13 +88,13 @@
7788
get_string('bulktestcontinuefromhere', 'qtype_coderunner')
7889
));
7990

80-
[$passes, $failingtests, $missinganswers] = $bulktester->run_all_tests_for_context($testcontext);
91+
[$passes, $failingtests, $missinganswers] = $bulktester->run_all_tests_for_context();
8192
$numpasses += $passes;
8293
$allfailingtests = array_merge($allfailingtests, $failingtests);
8394
$allmissinganswers = array_merge($allmissinganswers, $missinganswers);
8495
}
8596
}
8697

8798
// Display the final summary.
88-
$bulktester->print_overall_result($numpasses, $allfailingtests, $allmissinganswers);
99+
bulk_tester::print_summary_after_bulktestall($numpasses, $allfailingtests, $allmissinganswers);
89100
echo $OUTPUT->footer();

0 commit comments

Comments
 (0)