diff --git a/auth/mnet/auth.php b/auth/mnet/auth.php index b3b22f534b1..2744dcddcb6 100644 --- a/auth/mnet/auth.php +++ b/auth/mnet/auth.php @@ -737,25 +737,6 @@ class auth_plugin_mnet extends auth_plugin_base { return array('code' => 1, 'message' => $returnString, 'last log id' => $remoteclient->last_log_id); } - /** - * Cron function will be called automatically by cron.php every 5 minutes - * - * @return void - */ - function cron() { - global $DB; - - // run the keepalive client - $this->keepalive_client(); - - $random100 = rand(0,100); - if ($random100 < 10) { // Approximately 10% of the time. - // nuke olden sessions - $longtime = time() - (1 * 3600 * 24); - $DB->delete_records_select('mnet_session', "expires < ?", array($longtime)); - } - } - /** * Cleanup any remote mnet_sessions, kill the local mnet_session data * diff --git a/auth/mnet/classes/task/cron_task.php b/auth/mnet/classes/task/cron_task.php new file mode 100644 index 00000000000..dbd8e177dbc --- /dev/null +++ b/auth/mnet/classes/task/cron_task.php @@ -0,0 +1,52 @@ +. + +namespace auth_mnet\task; +defined('MOODLE_INTERNAL') || die(); + +/** + * A schedule task for mnet cron. + * + * @package auth_mnet + * @copyright 2019 Simey Lameze + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +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', 'auth_mnet'); + } + /** + * Run auth mnet cron. + */ + public function execute() { + global $DB, $CFG; + + require_once($CFG->dirroot . '/auth/mnet/auth.php'); + $mnetplugin = new \auth_plugin_mnet(); + $mnetplugin->keepalive_client(); + + $random100 = rand(0,100); + if ($random100 < 10) { + $longtime = time() - DAYSECS; + $DB->delete_records_select('mnet_session', "expires < ?", [$longtime]); + } + } +} diff --git a/auth/mnet/db/tasks.php b/auth/mnet/db/tasks.php new file mode 100644 index 00000000000..e85dc3d6619 --- /dev/null +++ b/auth/mnet/db/tasks.php @@ -0,0 +1,34 @@ +. +/** + * Definition of chat scheduled tasks. + * + * @package auth_mnet + * @copyright 2019 Simey Lameze + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die(); +$tasks = array( + array( + 'classname' => '\auth_mnet\task\cron_task', + 'blocking' => 0, + 'minute' => '*', + 'hour' => '*', + 'day' => '*', + 'month' => '*', + 'dayofweek' => '*' + ) +); diff --git a/auth/mnet/lang/en/auth_mnet.php b/auth/mnet/lang/en/auth_mnet.php index a8c7ed3cc47..4836214200b 100644 --- a/auth/mnet/lang/en/auth_mnet.php +++ b/auth/mnet/lang/en/auth_mnet.php @@ -28,6 +28,7 @@ $string['auth_mnet_roamin'] = 'These host\'s users can roam in to your site'; $string['auth_mnet_roamout'] = 'Your users can roam out to these hosts'; $string['auth_mnet_rpc_negotiation_timeout'] = 'The timeout in seconds for authentication over the XMLRPC transport.'; $string['auto_add_remote_users'] = 'Auto add remote users'; +$string['crontask'] = 'Background processing for MNET authentication'; $string['rpc_negotiation_timeout'] = 'RPC negotiation timeout'; $string['sso_idp_description'] = 'Publish this service to allow your users to roam to the {$a} site without having to re-login there.
Subscribe to this service to allow authenticated users from {$a} to access your site without having to re-login.
'; $string['sso_idp_name'] = 'SSO (Identity Provider)'; diff --git a/auth/mnet/version.php b/auth/mnet/version.php index ae88a9ff731..bf5d4412333 100644 --- a/auth/mnet/version.php +++ b/auth/mnet/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2018120300; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2018120301; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2018112800; // Requires this Moodle version $plugin->component = 'auth_mnet'; // Full name of the plugin (used for diagnostics)