/** * This function does the cron process within the time range according to settings. */ function tool_qeupgradehelper_process($settings) { global $CFG; require_once dirname(__FILE__) . '/locallib.php'; if (!tool_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 = ' . $hour . ').'); return; } $stoptime = time() + $settings->procesingtime; mtrace('qeupgradehelper: processing ...'); while (time() < $stoptime) { $quiz = tool_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 = tool_qeupgradehelper_get_quiz($quizid); if ($quizsummary) { mtrace(' starting upgrade of attempts at quiz ' . $quizid); $upgrader = new tool_qeupgradehelper_attempt_upgrader($quizsummary->id, $quizsummary->numtoconvert); $upgrader->convert_all_quiz_attempts(); mtrace(' upgrade of quiz ' . $quizid . ' complete.'); } } mtrace('qeupgradehelper: Done.'); return; }
// If we are doing a quiz id, limit to one. if ($options['quiz']) { $options['countlimit'] = 1; } $count = 0; mtrace('qeupgradehelper: processing ...'); /* This while statement does a few things * Basically if an option is set to false, then that subsection will return * true, and will short circuit the test condition for that option, and always * being true. Both options are anded together, so either one can trigger to stop. */ while ((!$stoptime || time() < $stoptime) && (!$options['countlimit'] || $count < $options['countlimit'])) { if ($options['quiz']) { $quizid = $options['quiz']; } else { $quiz = tool_qeupgradehelper_get_quiz_for_upgrade(); if (!$quiz) { mtrace('qeupgradehelper: No more quizzes to process.'); break; // No more to do. } $quizid = $quiz->id; } $quizsummary = tool_qeupgradehelper_get_quiz($quizid); if ($quizsummary) { mtrace(' starting upgrade of attempts at quiz ' . $quizid); $upgrader = new tool_qeupgradehelper_attempt_upgrader($quizsummary->id, $quizsummary->numtoconvert); $upgrader->convert_all_quiz_attempts(); mtrace(' upgrade of quiz ' . $quizid . ' complete.'); } else { mtrace('quiz ' . $quizid . ' not found or already upgraded.');