Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'MDL-28329_21' of git://github.com/timhunt/moodle into M…
…OODLE_21_STABLE
  • Loading branch information
Sam Hemelryk committed Sep 19, 2011
2 parents 26c28d0 + 9acc573 commit 5585910
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
32 changes: 25 additions & 7 deletions local/qeupgradehelper/lib.php
Expand Up @@ -25,9 +25,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once (dirname(__FILE__) . '/locallib.php');


/**
* Standard cron function
*/
Expand All @@ -51,11 +48,16 @@ function local_qeupgradehelper_cron() {
* This function does the cron process within the time range according to settings.
*/
function local_qeupgradehelper_process($settings) {
global $CFG;
require_once(dirname(__FILE__) . '/locallib.php');

if (!local_qeupgradehelper_is_upgraded()) {
mtrace('qeupgradehelper: site not yet upgraded. Doing nothing.');
return;
}

require_once(dirname(__FILE__) . '/afterupgradelib.php');

$hour = (int) date('H');
if ($hour < $settings->starthour || $hour >= $settings->stophour) {
mtrace('qeupgradehelper: not between starthour and stophour, so doing nothing (hour = ' .
Expand All @@ -64,11 +66,27 @@ function local_qeupgradehelper_process($settings) {
}

$stoptime = time() + $settings->procesingtime;

mtrace('qeupgradehelper: processing ...');
while (time() < $stoptime) {
mtrace('qeupgradehelper: processing ...');

// TODO
mtrace('qeupgradehelper: sorry, not implemented yet.');
return;
$quiz = local_qeupgradehelper_get_quiz_for_upgrade();
if (!$quiz) {
mtrace('qeupgradehelper: No more quizzes to process. You should probably disable the qeupgradehelper cron settings now.');
break; // No more to do;
}

$quizid = $quiz->id;
$quizsummary = local_qeupgradehelper_get_quiz($quizid);
if ($quizsummary) {
mtrace(' starting upgrade of attempts at quiz ' . $quizid);
$upgrader = new local_qeupgradehelper_attempt_upgrader(
$quizsummary->id, $quizsummary->numtoconvert);
$upgrader->convert_all_quiz_attempts();
mtrace(' upgrade of quiz ' . $quizid . ' complete.');
}
}

mtrace('qeupgradehelper: Done.');
return;
}
12 changes: 12 additions & 0 deletions local/qeupgradehelper/locallib.php
Expand Up @@ -659,3 +659,15 @@ function local_qeupgradehelper_load_question($questionid, $quizid) {

return $question;
}

function local_qeupgradehelper_get_quiz_for_upgrade() {
global $DB;

return $DB->get_record_sql("SELECT quiz.id
FROM {quiz_attempts} quiza
JOIN {quiz} quiz ON quiz.id = quiza.quiz
JOIN {course} c ON c.id = quiz.course
WHERE quiza.preview = 0 AND quiza.needsupgradetonewqe = 1
GROUP BY quiz.id, quiz.name, c.shortname, c.id
ORDER BY quiza.timemodified DESC", array(), IGNORE_MULTIPLE);
}

0 comments on commit 5585910

Please sign in to comment.