mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-28329 local_qeupgradehelper make cron work.
This commit is contained in:
parent
9cfaebbd0e
commit
545299f471
@ -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;
|
||||
while (time() < $stoptime) {
|
||||
mtrace('qeupgradehelper: processing ...');
|
||||
|
||||
// TODO
|
||||
mtrace('qeupgradehelper: sorry, not implemented yet.');
|
||||
return;
|
||||
mtrace('qeupgradehelper: processing ...');
|
||||
while (time() < $stoptime) {
|
||||
|
||||
$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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user