Permalink
Browse files

Merge branch 'MDL-28329_21' of git://github.com/timhunt/moodle into M…

…OODLE_21_STABLE
  • Loading branch information...
2 parents 26c28d0 + 9acc573 commit 5585910ea75de4e613e852db9d2076bc0884b80b Sam Hemelryk committed Sep 19, 2011
Showing with 37 additions and 7 deletions.
  1. +25 −7 local/qeupgradehelper/lib.php
  2. +12 −0 local/qeupgradehelper/locallib.php
@@ -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
*/
@@ -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 = ' .
@@ -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;
}
@@ -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.