Skip to content

Commit

Permalink
MDL-20636 Make extracttestcase.php work after the upgrade too.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed May 13, 2011
1 parent 2d43a02 commit 1ab31a1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
1 change: 0 additions & 1 deletion local/qeupgradehelper/extracttestcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
local_qeupgradehelper_require_not_upgraded();

admin_externalpage_setup('qeupgradehelper', '', array(),
local_qeupgradehelper_url('extracttestcase'));
Expand Down
1 change: 1 addition & 0 deletions local/qeupgradehelper/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$detected = get_string('upgradedsitedetected', 'local_qeupgradehelper');
$actions[] = local_qeupgradehelper_action::make('listtodo');
$actions[] = local_qeupgradehelper_action::make('listupgraded');
$actions[] = local_qeupgradehelper_action::make('extracttestcase');
$actions[] = local_qeupgradehelper_action::make('cronsetup');

} else {
Expand Down
41 changes: 25 additions & 16 deletions local/qeupgradehelper/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,21 +463,23 @@ function local_qeupgradehelper_generate_unit_test($questionsessionid, $namesuffi

$question = local_qeupgradehelper_load_question($qsession->questionid, $quiz->id);

if (!$quiz->optionflags) {
$quiz->preferredbehaviour = 'deferredfeedback';
} else if (!$quiz->penaltyscheme) {
$quiz->preferredbehaviour = 'adaptive';
} else {
$quiz->preferredbehaviour = 'adaptivenopenalty';
if (!local_qeupgradehelper_is_upgraded()) {
if (!$quiz->optionflags) {
$quiz->preferredbehaviour = 'deferredfeedback';
} else if (!$quiz->penaltyscheme) {
$quiz->preferredbehaviour = 'adaptive';
} else {
$quiz->preferredbehaviour = 'adaptivenopenalty';
}
unset($quiz->optionflags);
unset($quiz->penaltyscheme);

$question->defaultmark = $question->defaultgrade;
unset($question->defaultgrade);
}
unset($quiz->optionflags);
unset($quiz->penaltyscheme);

$attempt->needsupgradetonewqe = 1;

$question->defaultmark = $question->defaultgrade;
unset($question->defaultgrade);

echo "<pre>
public function test_{$question->qtype}_{$quiz->preferredbehaviour}_{$namesuffix}() {
";
Expand Down Expand Up @@ -560,7 +562,7 @@ function local_qeupgradehelper_display_convert_attempt_input($quiz, $attempt,
}

function local_qeupgradehelper_load_question($questionid, $quizid) {
global $DB, $QTYPES;
global $CFG, $DB;

$question = $DB->get_record_sql('
SELECT q.*, qqi.grade AS maxmark
Expand All @@ -569,12 +571,19 @@ function local_qeupgradehelper_load_question($questionid, $quizid) {
WHERE q.id = :questionid AND qqi.quiz = :quizid',
array('questionid' => $questionid, 'quizid' => $quizid));

if (!array_key_exists($question->qtype, $QTYPES)) {
$question->qtype = 'missingtype';
$question->questiontext = '<p>' . get_string('warningmissingtype', 'quiz') . '</p>' . $question->questiontext;
if (local_qeupgradehelper_is_upgraded()) {
require_once($CFG->dirroot . '/question/engine/bank.php');
$qtype = question_bank::get_qtype($question->qtype, false);
} else {
global $QTYPES;
if (!array_key_exists($question->qtype, $QTYPES)) {
$question->qtype = 'missingtype';
$question->questiontext = '<p>' . get_string('warningmissingtype', 'quiz') . '</p>' . $question->questiontext;
}
$qtype = $QTYPES[$question->qtype];
}

$QTYPES[$question->qtype]->get_question_options($question);
$qtype->get_question_options($question);

return $question;
}

0 comments on commit 1ab31a1

Please sign in to comment.