MDL-30484 question engine: don't lose response files when regrading.
The problem was mostly that, in the past, we did not worry if question_attempt_step.id changed during regrade (because we deleted the old step row and inserted a new one). However, now that steps can have associated files, we can't be that slack, becuase the step id is used as the file itemid. So, now, we have to update the existing rows during a regrade. We do this by having the question engine tell the question_engine_unit_of_work that the step has first been deleted, and then added back. Then we make the unit-of-work spot that delete + add = update. This also means that during regrading, we have to pass around some extra ids so that new steps know the id of the step they are replacing. Naturally, this requires some quite trickly logic, so I finally got around to writing unit tests for question_engine_unit_of_work, which is a good thing. Along the way I also got around to renaming question_attempt->set_number_in_usage, which got missed out when everthing else was renamed to slot ages ago. Finally, while working on this code, I noticed and fixed some PHPdoc comments.
This commit is contained in:
@@ -98,8 +98,11 @@ class question_attempt_step {
|
||||
* @param array $data the submitted data that defines this step.
|
||||
* @param int $timestamp the time to record for the action. (If not given, use now.)
|
||||
* @param int $userid the user to attribute the aciton to. (If not given, use the current user.)
|
||||
* @param int $existingstepid if this step is going to replace an existing step
|
||||
* (for example, during a regrade) this is the id of the previous step we are replacing.
|
||||
*/
|
||||
public function __construct($data = array(), $timecreated = null, $userid = null) {
|
||||
public function __construct($data = array(), $timecreated = null, $userid = null,
|
||||
$existingstepid = null) {
|
||||
global $USER;
|
||||
|
||||
if (!is_array($data)) {
|
||||
@@ -117,6 +120,18 @@ class question_attempt_step {
|
||||
} else {
|
||||
$this->userid = $userid;
|
||||
}
|
||||
|
||||
if (!is_null($existingstepid)) {
|
||||
$this->id = $existingstepid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null The id of this step in the database. null if this step
|
||||
* is not stored in the database.
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/** @return question_state The state after this step. */
|
||||
|
||||
Reference in New Issue
Block a user