Skip to content

Commit

Permalink
MDL-27408 fix a few minor bugs with the upgrade from 2.0.
Browse files Browse the repository at this point in the history
More testing, and adaptive mode, still to come.
  • Loading branch information
timhunt committed May 12, 2011
1 parent bb28e3b commit 39759ac
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/moodlelib.php
Expand Up @@ -7067,7 +7067,8 @@ function get_plugin_types($fullpaths=true) {
static $fullinfo = null;

if (!$info) {
$info = array('mod' => 'mod',
$info = array('qtype' => 'question/type',
'mod' => 'mod',
'auth' => 'auth',
'enrol' => 'enrol',
'message' => 'message/output',
Expand All @@ -7087,7 +7088,6 @@ function get_plugin_types($fullpaths=true) {
'portfolio' => 'portfolio',
'qbehaviour' => 'question/behaviour',
'qformat' => 'question/format',
'qtype' => 'question/type',
'plagiarism' => 'plagiarism',
'theme' => 'theme'); // this is a bit hacky, themes may be in $CFG->themedir too

Expand Down
9 changes: 9 additions & 0 deletions local/qeupgradehelper/README.txt
Expand Up @@ -5,6 +5,15 @@ With a lot of question attempts, doing the whole conversion on upgrade is very
slow. The plugin can help with that in various ways.


To install using git, type this command in the root of your Moodle install
git clone git://github.com/timhunt/moodle-local_qeupgradehelper.git local/qeupgradehelper
Then add /local/qeupgradehelper to your git ignore.

Alternatively, download the zip from
https://github.com/timhunt/moodle-local_qeupgradehelper/zipball/master
unzip it into the local folder, and then rename the new folder to qeupgradehelper.


When installed in a Moodle 2.0 site:

1. It provies a report of how much data there is to upgrade.
Expand Down
1 change: 1 addition & 0 deletions mod/quiz/lang/en/quiz.php
Expand Up @@ -96,6 +96,7 @@
$string['attemptsnumthisgroup'] = 'Attempts: {$a->total} ({$a->group} from this group)';
$string['attemptsnumyourgroups'] = 'Attempts: {$a->total} ({$a->group} from your groups)';
$string['attemptsonly'] = 'Show only students with attempts';
$string['attemptstillinprogress'] = 'Attempt still in progress';
$string['attemptsunlimited'] = 'Unlimited attempts';
$string['back'] = 'Back to preview question';
$string['backtocourse'] = 'Back to the course';
Expand Down
1 change: 1 addition & 0 deletions mod/quiz/locallib.php
Expand Up @@ -34,6 +34,7 @@

require_once($CFG->dirroot . '/mod/quiz/lib.php');
require_once($CFG->dirroot . '/mod/quiz/accessrules.php');
require_once($CFG->dirroot . '/mod/quiz/renderer.php');
require_once($CFG->dirroot . '/mod/quiz/attemptlib.php');
require_once($CFG->dirroot . '/question/editlib.php');
require_once($CFG->libdir . '/eventslib.php');
Expand Down
13 changes: 9 additions & 4 deletions question/engine/upgrade/upgradelib.php
Expand Up @@ -28,6 +28,7 @@
defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->dirroot . '/question/engine/bank.php');
require_once($CFG->dirroot . '/question/engine/upgrade/logger.php');
require_once($CFG->dirroot . '/question/engine/upgrade/behaviourconverters.php');

Expand Down Expand Up @@ -282,9 +283,12 @@ public function load_question($questionid, $quizid = null) {
}

public function get_next_question_session($attempt, moodle_recordset $questionsessionsrs) {
if (!$questionsessionsrs->valid()) {
return false;
}

$qsession = $questionsessionsrs->current();
print_object($qsession); // DONOTCOMMIT
if (!$qsession || $qsession->attemptid != $attempt->uniqueid) {
if ($qsession->attemptid != $attempt->uniqueid) {
// No more question sessions belonging to this attempt.
return false;
}
Expand All @@ -297,8 +301,9 @@ public function get_next_question_session($attempt, moodle_recordset $questionse
public function get_question_states($attempt, $question, moodle_recordset $questionsstatesrs) {
$qstates = array();

while ($state = $questionsstatesrs->current()) {
if (!$state || $state->attempt != $attempt->uniqueid ||
while ($questionsstatesrs->valid()) {
$state = $questionsstatesrs->current();
if ($state->attempt != $attempt->uniqueid ||
$state->question != $question->id) {
// We have found all the states for this attempt. Stop.
break;
Expand Down
24 changes: 23 additions & 1 deletion question/type/numerical/db/upgradelib.php
Expand Up @@ -68,8 +68,30 @@ public function supply_missing_first_step_data(&$data) {
}

public function set_data_elements_for_step($state, &$data) {
if (!empty($state->answer)) {
if (empty($state->answer)) {
return;
}
if (strpos($state->answer, '|||||') === false) {
$data['answer'] = $state->answer;
} else {
list($answer, $unit) = explode('|||||', $state->answer, 2);
if ($this->question->options->showunits == 1) {
// Multichoice units.
$data['answer'] = $answer;
$data['unit'] = $unit;
} else if (!empty($this->question->options->unitsleft)) {
if (!empty($unit)) {
$data['answer'] = $unit . ' ' . $answer;
} else {
$data['answer'] = $answer;
}
} else {
if (!empty($unit)) {
$data['answer'] = $answer . ' ' . $unit;
} else {
$data['answer'] = $answer;
}
}
}
}
}

0 comments on commit 39759ac

Please sign in to comment.