Skip to content

Commit

Permalink
MDL-46880 mod_forum: move cron to scheduled task
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danpoltawski committed Aug 21, 2014
1 parent e609e6c commit cae945d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 12 deletions.
48 changes: 48 additions & 0 deletions mod/forum/classes/task/cron_task.php
@@ -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 changes: 38 additions & 0 deletions mod/forum/db/tasks.php
@@ -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' => '*'
)
);
1 change: 1 addition & 0 deletions mod/forum/lang/en/forum.php
Expand Up @@ -110,6 +110,7 @@
$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';
Expand Down
17 changes: 7 additions & 10 deletions mod/forum/lib.php
Expand Up @@ -434,18 +434,15 @@ function forum_cron_minimise_user_record(stdClass $user) {
}

/**
* Function to be run periodically according to the moodle cron
* Function to be run periodically according to the scheduled task.
*
* Finds all posts that have yet to be mailed out, and mails them
* out to all subscribers
* out to all subscribers as well as other maintance tasks.
*
* @global object
* @global object
* @global object
* @uses CONTEXT_MODULE
* @uses CONTEXT_COURSE
* @uses SITEID
* @uses FORMAT_PLAIN
* @return void
* 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;
Expand Down
3 changes: 1 addition & 2 deletions mod/forum/version.php
Expand Up @@ -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;

0 comments on commit cae945d

Please sign in to comment.