Skip to content

Commit

Permalink
MDL-20636 Add warning about very old attempts to listpreupgrade.php.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed May 13, 2011
1 parent 1ab31a1 commit d02ac70
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions local/qeupgradehelper/lang/en/local_qeupgradehelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
$string['invalidquizid'] = 'Invaid quiz id. Either the quiz does not exist, or it has no attempts to convert.';
$string['listpreupgrade'] = 'List quizzes and attempts';
$string['listpreupgrade_desc'] = 'This will show a report of all the quizzes on the system and how many attempts they have. This will give you an idea of the scope of the upgrade you have to do.';
$string['listpreupgradeintro'] = 'These are the number of quiz attempts that will need to be processed when you upgrade your site. A few tens of thousands is no worry. Much beyond that and you need to think carefully.';
$string['listpreupgradeintro'] = 'These are the number of quiz attempts that will need to be processed when you upgrade your site. A few tens of thousands is no worry. Much beyond that and you need to think about how long the upgrade will take.';
$string['listtodo'] = 'List quizzes still to upgrade';
$string['listtodo_desc'] = 'This will show a report of all the quizzes on the system (if any) that have attempts that still need to be upgraded to the new question engine.';
$string['listtodointro'] = 'These are all the quizzes with attempt data that still needs to be converted. You can convert the attempts by clicking the link.';
Expand All @@ -72,4 +72,4 @@
$string['upgradingquizattempts'] = 'Upgrading the attempts for quiz \'{$a->name}\' in course {$a->shortname}';
$string['upgradedsitedetected'] = 'This appears to be a site that has been upgraded to include the new question engine.';
$string['upgradedsiterequired'] = 'This script can only work after the site has been upgraded.';

$string['veryoldattemtps'] = 'Your site has {$a} quiz attempts that were never completely updated during the upgrade from Moodle 1.4 to Moodle 1.5. These attempts will be dealt wiht before the main upgrade. You need to to consider the extra time required for this.';
3 changes: 2 additions & 1 deletion local/qeupgradehelper/listpreupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
$renderer = $PAGE->get_renderer('local_qeupgradehelper');

$quizzes = new local_qeupgradehelper_pre_upgrade_quiz_list();
$numveryoldattemtps = local_qeupgradehelper_get_num_very_old_attempts();

if ($quizzes->is_empty()) {
echo $renderer->simple_message_page(get_string('noquizattempts', 'local_qeupgradehelper'));

} else {
// TODO, once we have a way to limit which quizzes will be included in the upgrade,
// display that information too.
echo $renderer->quiz_list_page($quizzes);
echo $renderer->quiz_list_page($quizzes, $numveryoldattemtps);
}
38 changes: 18 additions & 20 deletions local/qeupgradehelper/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,26 +262,6 @@ public function get_row($quizinfo) {
}


function local_qeupgradehelper_get_pre_upgrade_quizzes() {
global $DB;
return $DB->get_records_sql("
SELECT
quiz.id,
quiz.name,
c.shortname,
c.id AS courseid,
COUNT(1) AS attemptcount
FROM {quiz_attempts} quiza
JOIN {quiz} quiz ON quiz.id = quiza.quiz
JOIN {course} c ON c.id = quiz.course
WHERE quiza.preview = 0
GROUP BY quiz.id, quiz.name, c.shortname, c.id
ORDER BY c.shortname, quiz.name, quiz.id");
}

/**
* A list of quizzes that still need to be upgraded after the main upgrade.
*
Expand All @@ -298,6 +278,24 @@ protected function extra_where_clause() {
}
}


/**
* List the number of quiz attempts that were never upgraded from 1.4 -> 1.5.
* @return int the number of such attempts.
*/
function local_qeupgradehelper_get_num_very_old_attempts() {
global $DB;
return $DB->count_records_sql('
SELECT COUNT(1)
FROM {quiz_attempts} quiza
WHERE uniqueid IN (
SELECT DISTINCT qst.attempt
FROM {question_states} qst
LEFT JOIN {question_sessions} qsess ON
qst.question = qsess.questionid AND qst.attempt = qsess.attemptid
WHERE qsess.id IS NULL)');
}

/**
* Get the information about a quiz to be upgraded.
* @param integer $quizid the quiz id.
Expand Down
9 changes: 8 additions & 1 deletion local/qeupgradehelper/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ public function simple_message_page($message) {
/**
* Render the list of quizzes that still need to be upgraded page.
* @param array $quizzes of data about quizzes.
* @param int $numveryoldattemtps only relevant before upgrade.
* @return string html to output.
*/
public function quiz_list_page(local_qeupgradehelper_quiz_list $quizzes) {
public function quiz_list_page(local_qeupgradehelper_quiz_list $quizzes,
$numveryoldattemtps = null) {
$output = '';
$output .= $this->header();
$output .= $this->heading($quizzes->title);
Expand All @@ -90,6 +92,11 @@ public function quiz_list_page(local_qeupgradehelper_quiz_list $quizzes) {
$table->data[] = $quizzes->get_total_row();
$output .= html_writer::table($table);

if ($numveryoldattemtps) {
$output .= $this->box(get_string('veryoldattemtps', 'local_qeupgradehelper',
$numveryoldattemtps));
}

$output .= $this->back_to_index();
$output .= $this->footer();
return $output;
Expand Down

0 comments on commit d02ac70

Please sign in to comment.