Skip to content

Commit

Permalink
MDL-54956 quiz: Fix WS to support files submission
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Sep 22, 2020
1 parent 8bec429 commit ba2d964
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mod/quiz/classes/external.php
Expand Up @@ -1168,7 +1168,7 @@ public static function save_attempt_parameters() {
* @since Moodle 3.1
*/
public static function save_attempt($attemptid, $data, $preflightdata = array()) {
global $DB;
global $DB, $USER;

$warnings = array();

Expand All @@ -1182,11 +1182,17 @@ public static function save_attempt($attemptid, $data, $preflightdata = array())
// Add a page, required by validate_attempt.
list($attemptobj, $messages) = self::validate_attempt($params);

// Prevent functions like file_get_submitted_draft_itemid() or form library requiring a sesskey for WS requests.
if (WS_SERVER || PHPUNIT_TEST) {
$USER->ignoresesskey = true;
}
$transaction = $DB->start_delegated_transaction();
// Create the $_POST object required by the question engine.
$_POST = array();
foreach ($data as $element) {
$_POST[$element['name']] = $element['value'];
// Some deep core functions like file_get_submitted_draft_itemid() also requires $_REQUEST to be filled.
$_REQUEST[$element['name']] = $element['value'];
}
$timenow = time();
// Update the timemodifiedoffline field.
Expand Down Expand Up @@ -1261,6 +1267,7 @@ public static function process_attempt_parameters() {
* @since Moodle 3.1
*/
public static function process_attempt($attemptid, $data, $finishattempt = false, $timeup = false, $preflightdata = array()) {
global $USER;

$warnings = array();

Expand All @@ -1279,10 +1286,15 @@ public static function process_attempt($attemptid, $data, $finishattempt = false

list($attemptobj, $messages) = self::validate_attempt($params, false, $failifoverdue);

// Prevent functions like file_get_submitted_draft_itemid() or form library requiring a sesskey for WS requests.
if (WS_SERVER || PHPUNIT_TEST) {
$USER->ignoresesskey = true;
}
// Create the $_POST object required by the question engine.
$_POST = array();
foreach ($params['data'] as $element) {
$_POST[$element['name']] = $element['value'];
$_REQUEST[$element['name']] = $element['value'];
}
$timenow = time();
$finishattempt = $params['finishattempt'];
Expand Down

0 comments on commit ba2d964

Please sign in to comment.