MDL-46880 mod_forum: move cron to scheduled task

Note that this is a very basic conversion without doing any refactoring
to split the tasks up better. That will come in MDL-44734, this is about
being a safe backportable change to give admins better control over the
running of the forum cron task.
This commit is contained in:
Dan Poltawski 2014-08-19 11:26:01 +01:00
parent e609e6cf02
commit cae945d272
5 changed files with 96 additions and 13 deletions

View File

@ -0,0 +1,48 @@
<?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/>.
/**
* A scheduled task for forum cron.
*
* @todo MDL-44734 This job will be split up properly.
*
* @package mod_forum
* @copyright 2014 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\task;
class cron_task extends \core\task\scheduled_task {
/**
* Get a descriptive name for this task (shown to admins).
*
* @return string
*/
public function get_name() {
return get_string('crontask', 'mod_forum');
}
/**
* Run forum cron.
*/
public function execute() {
global $CFG;
require_once($CFG->dirroot . '/mod/forum/lib.php');
forum_cron();
}
}

38
mod/forum/db/tasks.php Normal file
View File

@ -0,0 +1,38 @@
<?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 Forum scheduled tasks.
*
* @package mod_forum
* @category task
* @copyright 2014 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = array(
array(
'classname' => 'mod_forum\task\cron_task',
'blocking' => 0,
'minute' => '*',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*'
)
);

View File

@ -110,6 +110,7 @@ $string['confirmunsubscribe'] = 'Do you really want to unsubscribe from forum \'
$string['couldnotadd'] = 'Could not add your post due to an unknown error';
$string['couldnotdeletereplies'] = 'Sorry, that cannot be deleted as people have already responded to it';
$string['couldnotupdate'] = 'Could not update your post due to an unknown error';
$string['crontask'] = 'Forum mailings and maintenance jobs';
$string['delete'] = 'Delete';
$string['deleteddiscussion'] = 'The discussion topic has been deleted';
$string['deletedpost'] = 'The post has been deleted';

View File

@ -434,18 +434,15 @@ function forum_cron_minimise_user_record(stdClass $user) {
}
/**
* Function to be run periodically according to the moodle cron
* Finds all posts that have yet to be mailed out, and mails them
* out to all subscribers
* Function to be run periodically according to the scheduled task.
*
* @global object
* @global object
* @global object
* @uses CONTEXT_MODULE
* @uses CONTEXT_COURSE
* @uses SITEID
* @uses FORMAT_PLAIN
* @return void
* Finds all posts that have yet to be mailed out, and mails them
* out to all subscribers as well as other maintance tasks.
*
* NOTE: Since 2.7.2 this function is run by scheduled task rather
* than standard cron.
*
* @todo MDL-44734 The function will be split up into seperate tasks.
*/
function forum_cron() {
global $CFG, $USER, $DB;

View File

@ -24,7 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014081900; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2014082100; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2014050800; // Requires this Moodle version
$plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 60;