mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-60683 quiz: Replace quiz legacy cron with tasks
This commit is contained in:
parent
124999563a
commit
b09c036bb8
52
mod/quiz/classes/task/legacy_quiz_accessrules_cron.php
Normal file
52
mod/quiz/classes/task/legacy_quiz_accessrules_cron.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Legacy Cron Quiz Access Rules Task
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @copyright 2017 Michael Hughes
|
||||
* @author Michael Hughes
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace mod_quiz\task;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
|
||||
/**
|
||||
* Legacy Cron Quiz Access Rules Task
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @copyright 2017 Michael Hughes
|
||||
* @author Michael Hughes
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
*/
|
||||
class legacy_quiz_accessrules_cron extends \core\task\scheduled_task {
|
||||
|
||||
public function get_name() {
|
||||
return get_string('legacyquizaccessrulescron', 'mod_quiz');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute all quizaccess subplugins legacy cron tasks.
|
||||
*/
|
||||
public function execute() {
|
||||
cron_execute_plugin_type('quizaccess', 'quiz access rules');
|
||||
}
|
||||
}
|
53
mod/quiz/classes/task/legacy_quiz_reports_cron.php
Normal file
53
mod/quiz/classes/task/legacy_quiz_reports_cron.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Legacy Cron Quiz Reports Task
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @copyright 2017 Michael Hughes
|
||||
* @author Michael Hughes
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace mod_quiz\task;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
|
||||
/**
|
||||
* Legacy Cron Quiz Reports Task
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @copyright 2017 Michael Hughes
|
||||
* @author Michael Hughes
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
*/
|
||||
class legacy_quiz_reports_cron extends \core\task\scheduled_task {
|
||||
|
||||
public function get_name() {
|
||||
return get_string('legacyquizreportscron', 'mod_quiz');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute all quizreport sub-plugins cron tasks.
|
||||
*/
|
||||
public function execute() {
|
||||
cron_execute_plugin_type('quiz', 'quiz reports');
|
||||
}
|
||||
}
|
65
mod/quiz/classes/task/update_overdue_attempts.php
Normal file
65
mod/quiz/classes/task/update_overdue_attempts.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Update Overdue Attempts Task
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @copyright 2017 Michael Hughes
|
||||
* @author Michael Hughes
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace mod_quiz\task;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
|
||||
/**
|
||||
* Update Overdue Attempts Task
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @copyright 2017 Michael Hughes
|
||||
* @author Michael Hughes
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
*/
|
||||
class update_overdue_attempts extends \core\task\scheduled_task {
|
||||
|
||||
public function get_name() {
|
||||
return get_string('updateoverdueattemptstask', 'mod_quiz');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Close off any overdue attempts.
|
||||
*/
|
||||
public function execute() {
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/cronlib.php');
|
||||
$timenow = time();
|
||||
$overduehander = new \mod_quiz_overdue_attempt_updater();
|
||||
|
||||
$processto = $timenow - get_config('quiz', 'graceperiodmin');
|
||||
|
||||
mtrace(' Looking for quiz overdue quiz attempts...');
|
||||
|
||||
list($count, $quizcount) = $overduehander->update_overdue_attempts($timenow, $processto);
|
||||
|
||||
mtrace(' Considered ' . $count . ' attempts in ' . $quizcount . ' quizzes.');
|
||||
}
|
||||
}
|
56
mod/quiz/db/tasks.php
Normal file
56
mod/quiz/db/tasks.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Definition of Quiz scheduled tasks.
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @category task
|
||||
* @copyright 2017 Michael Hughes <michaelhughes@strath.ac.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$tasks = [
|
||||
[
|
||||
'classname' => 'mod_quiz\task\update_overdue_attempts',
|
||||
'blocking' => 0,
|
||||
'minute' => '*',
|
||||
'hour' => '*',
|
||||
'day' => '*',
|
||||
'dayofweek' => '*',
|
||||
'month' => '*'
|
||||
],
|
||||
[
|
||||
'classname' => 'mod_quiz\task\legacy_quiz_reports_cron',
|
||||
'blocking' => 0,
|
||||
'minute' => '*',
|
||||
'hour' => '*',
|
||||
'day' => '*',
|
||||
'dayofweek' => '*',
|
||||
'month' => '*'
|
||||
],
|
||||
[
|
||||
'classname' => 'mod_quiz\task\legacy_quiz_accessrules_cron',
|
||||
'blocking' => 0,
|
||||
'minute' => '*',
|
||||
'hour' => '*',
|
||||
'day' => '*',
|
||||
'dayofweek' => '*',
|
||||
'month' => '*'
|
||||
]
|
||||
];
|
@ -453,6 +453,8 @@ $string['layoutasshown'] = 'Page layout as shown.';
|
||||
$string['layoutasshownwithpages'] = 'Page layout as shown. <small>(Automatic new page every {$a} questions.)</small>';
|
||||
$string['layoutshuffledandpaged'] = 'Questions randomly shuffled with {$a} questions per page.';
|
||||
$string['layoutshuffledsinglepage'] = 'Questions randomly shuffled, all on one page.';
|
||||
$string['legacyquizaccessrulescron'] = 'Legacy Cron Quiz Access Rules';
|
||||
$string['legacyquizreportscron'] = 'Legacy Cron Quiz Reports';
|
||||
$string['link'] = 'Link';
|
||||
$string['listitems'] = 'Listing of items in quiz';
|
||||
$string['literal'] = 'Literal';
|
||||
@ -958,6 +960,7 @@ $string['unfinished'] = 'open';
|
||||
$string['ungraded'] = 'Ungraded';
|
||||
$string['unit'] = 'Unit';
|
||||
$string['unknowntype'] = 'Question type not supported at line {$a}. The question will be ignored';
|
||||
$string['updateoverdueattemptstask'] = 'Updating overdue quiz attempts';
|
||||
$string['updatesettings'] = 'Update quiz settings';
|
||||
$string['updatequizslotswithrandomxofy'] = 'Updating quiz slots with "random" question data ({$a->done}/{$a->total})';
|
||||
$string['updatingatttemptgrades'] = 'Updating attempt grades.';
|
||||
|
@ -578,32 +578,6 @@ function quiz_user_complete($course, $user, $mod, $quiz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quiz periodic clean-up tasks.
|
||||
*/
|
||||
function quiz_cron() {
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/cronlib.php');
|
||||
mtrace('');
|
||||
|
||||
$timenow = time();
|
||||
$overduehander = new mod_quiz_overdue_attempt_updater();
|
||||
|
||||
$processto = $timenow - get_config('quiz', 'graceperiodmin');
|
||||
|
||||
mtrace(' Looking for quiz overdue quiz attempts...');
|
||||
|
||||
list($count, $quizcount) = $overduehander->update_overdue_attempts($timenow, $processto);
|
||||
|
||||
mtrace(' Considered ' . $count . ' attempts in ' . $quizcount . ' quizzes.');
|
||||
|
||||
// Run cron for our sub-plugin types.
|
||||
cron_execute_plugin_type('quiz', 'quiz reports');
|
||||
cron_execute_plugin_type('quizaccess', 'quiz access rules');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|array $quizids A quiz ID, or an array of quiz IDs.
|
||||
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Legacy Cron Quiz Reports Task
|
||||
*
|
||||
* @package quiz_statistics
|
||||
* @copyright 2017 Michael Hughes, University of Strathclyde
|
||||
* @author Michael Hughes <michaelhughes@strath.ac.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace quiz_statistics\task;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Legacy Cron Quiz Reports Task
|
||||
*
|
||||
* @package quiz_statistics
|
||||
* @copyright 2017 Michael Hughes
|
||||
* @author Michael Hughes
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
*/
|
||||
class quiz_statistics_cleanup extends \core\task\scheduled_task {
|
||||
public function get_name() {
|
||||
return get_string('quizstatisticscleanuptask', 'quiz_statistics');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the clean up task.
|
||||
*/
|
||||
public function execute() {
|
||||
global $DB;
|
||||
|
||||
$expiretime = time() - 4 * HOURSECS;
|
||||
$DB->delete_records_select('quiz_statistics', 'timemodified < ?', array($expiretime));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
39
mod/quiz/report/statistics/db/tasks.php
Normal file
39
mod/quiz/report/statistics/db/tasks.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Legacy Cron Quiz Reports Task
|
||||
*
|
||||
* @package quiz_statistics
|
||||
* @copyright 2017 Michael Hughes, University of Strathclyde
|
||||
* @author Michael Hughes <michaelhughes@strath.ac.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$tasks = [
|
||||
[
|
||||
'classname' => 'quiz_statistics\task\quiz_statistics_cleanup',
|
||||
'blocking' => 0,
|
||||
'minute' => 'R',
|
||||
'hour' => '*/5',
|
||||
'day' => '*',
|
||||
'dayofweek' => '*',
|
||||
'month' => '*'
|
||||
]
|
||||
];
|
@ -93,6 +93,7 @@ $string['questioninformation'] = 'Question information';
|
||||
$string['questionname'] = 'Question name';
|
||||
$string['questionnumber'] = 'Q#';
|
||||
$string['questionstatistics'] = 'Question statistics';
|
||||
$string['quizstatisticscleanuptask'] = 'Clean up old quiz statistics cache records';
|
||||
$string['questionstatsfilename'] = 'questionstats';
|
||||
$string['questiontype'] = 'Question type';
|
||||
$string['quizinformation'] = 'Quiz information';
|
||||
|
@ -59,17 +59,3 @@ function quiz_statistics_question_preview_pluginfile($previewcontext, $questioni
|
||||
|
||||
send_stored_file($file, 0, 0, $forcedownload, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quiz statistics report cron code. Deletes cached data more than a certain age.
|
||||
*/
|
||||
function quiz_statistics_cron() {
|
||||
global $DB;
|
||||
|
||||
mtrace("\n Cleaning up old quiz statistics cache records...", '');
|
||||
|
||||
$expiretime = time() - 5*HOURSECS;
|
||||
$DB->delete_records_select('quiz_statistics', 'timemodified < ?', array($expiretime));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -26,5 +26,4 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2018120300;
|
||||
$plugin->requires = 2018112800;
|
||||
$plugin->cron = 18000;
|
||||
$plugin->component = 'quiz_statistics';
|
||||
|
@ -1,5 +1,10 @@
|
||||
This files describes API changes in the quiz code.
|
||||
|
||||
=== 3.7 ===
|
||||
|
||||
* Quiz_cron() has been removed. Sub-plugins should implemented scheduled tasks, however legacy cron in subplugins are
|
||||
supported.
|
||||
|
||||
=== 3.6 ===
|
||||
|
||||
* The following renamed classes have been completely removed:
|
||||
|
@ -27,4 +27,3 @@ defined('MOODLE_INTERNAL') || die();
|
||||
$plugin->version = 2018120300;
|
||||
$plugin->requires = 2018112800;
|
||||
$plugin->component = 'mod_quiz';
|
||||
$plugin->cron = 60;
|
||||
|
Loading…
x
Reference in New Issue
Block a user