mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-60683 quiz: Replace quiz legacy cron with tasks
- Loading branch information
Showing
13 changed files
with
329 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' => '*' | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
mod/quiz/report/statistics/classes/task/quiz_statistics_cleanup.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' => '*' | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.