MDL-61208 enrol: Standard enrol plugins should use tasks instead of cron

This commit is contained in:
Farhan Karmali 2018-01-13 13:07:12 +05:30
parent 2bd2660751
commit fe5b5be1dd
32 changed files with 738 additions and 77 deletions

View File

@ -0,0 +1,63 @@
<?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/>.
/**
* Syncing enrolments task.
*
* @package enrol_category
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_category\task;
defined('MOODLE_INTERNAL') || die();
/**
* Syncing enrolments task.
*
* @package enrol_category
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_category_sync extends \core\task\scheduled_task {
/**
* Name for this task.
*
* @return string
*/
public function get_name() {
return get_string('enrolcategorysynctask', 'enrol_category');
}
/**
* Run task for syncing category enrolments.
*/
public function execute() {
global $CFG;
if (!enrol_is_enabled('category')) {
return;
}
require_once("$CFG->dirroot/enrol/category/locallib.php");
$trace = new null_progress_trace();
enrol_category_sync_full($trace);
}
}

View 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/>.
/**
* Task definition for enrol_category.
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @package enrol_category
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = array(
array(
'classname' => '\enrol_category\task\enrol_category_sync',
'blocking' => 0,
'minute' => '*',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*',
'disabled' => 0
)
);

View File

@ -24,5 +24,6 @@
$string['category:config'] = 'Configure category enrol instances';
$string['category:synchronised'] = 'Role assignments synchronised to course enrolment';
$string['enrolcategorysynctask'] = 'Category enrolment sync task';
$string['pluginname'] = 'Category enrolments';
$string['pluginname_desc'] = 'The category enrolments plugin synchronises any role assignments in the category context for roles with the capability enrol/category:synchronised allowed.';

View File

@ -74,22 +74,6 @@ class enrol_category_plugin extends enrol_plugin {
return null;
}
/**
* Called for all enabled enrol plugins that returned true from is_cron_required().
* @return void
*/
public function cron() {
global $CFG;
if (!enrol_is_enabled('category')) {
return;
}
require_once("$CFG->dirroot/enrol/category/locallib.php");
$trace = new null_progress_trace();
enrol_category_sync_full($trace);
}
/**
* Called after updating/inserting course.
*

View File

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

View File

@ -0,0 +1,60 @@
<?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/>.
/**
* Syncing enrolments task.
*
* @package enrol_cohort
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_cohort\task;
defined('MOODLE_INTERNAL') || die();
/**
* Syncing enrolments task.
*
* @package enrol_cohort
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_cohort_sync extends \core\task\scheduled_task {
/**
* Name for this task.
*
* @return string
*/
public function get_name() {
return get_string('enrolcohortsynctask', 'enrol_cohort');
}
/**
* Run task for syncing cohort enrolments.
*/
public function execute() {
global $CFG;
require_once("$CFG->dirroot/enrol/cohort/locallib.php");
$trace = new null_progress_trace();
enrol_cohort_sync($trace);
$trace->finished();
}
}

39
enrol/cohort/db/tasks.php Normal file
View 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/>.
/**
* Task definition for enrol_cohort.
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @package enrol_cohort
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = array(
array(
'classname' => '\enrol_cohort\task\enrol_cohort_sync',
'blocking' => 0,
'minute' => 'R',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*',
'disabled' => 0
)
);

View File

@ -27,6 +27,7 @@ $string['assignrole'] = 'Assign role';
$string['cohort:config'] = 'Configure cohort instances';
$string['cohort:unenrol'] = 'Unenrol suspended users';
$string['defaultgroupnametext'] = '{$a->name} cohort {$a->increment}';
$string['enrolcohortsynctask'] = 'Cohort enrolment sync task';
$string['instanceexists'] = 'Cohort is already synchronised with selected role';
$string['pluginname'] = 'Cohort sync';
$string['pluginname_desc'] = 'Cohort enrolment plugin synchronises cohort members with course participants.';

View File

@ -161,19 +161,6 @@ class enrol_cohort_plugin extends enrol_plugin {
return $result;
}
/**
* Called for all enabled enrol plugins that returned true from is_cron_required().
* @return void
*/
public function cron() {
global $CFG;
require_once("$CFG->dirroot/enrol/cohort/locallib.php");
$trace = new null_progress_trace();
enrol_cohort_sync($trace);
$trace->finished();
}
/**
* Called after updating/inserting course.
*

View File

@ -24,7 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017111300; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2018040900; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2017110800; // Requires this Moodle version
$plugin->component = 'enrol_cohort'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 60*60; // run cron every hour by default, it is not out-of-sync often

View File

@ -0,0 +1,58 @@
<?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/>.
/**
* The send expiry notifications task.
*
* @package enrol_manual
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_manual\task;
defined('MOODLE_INTERNAL') || die();
/**
* The send expiry notifications task.
*
* @package enrol_manual
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class send_expiry_notifications extends \core\task\scheduled_task {
/**
* Name for this task.
*
* @return string
*/
public function get_name() {
return get_string('sendexpirynotificationstask', 'enrol_manual');
}
/**
* Run task for sending expiry notifications.
*/
public function execute() {
$enrol = enrol_get_plugin('manual');
$trace = new \text_progress_trace();
$enrol->send_expiry_notifications($trace);
}
}

View File

@ -0,0 +1,57 @@
<?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/>.
/**
* Syncing enrolments task.
*
* @package enrol_manual
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_manual\task;
defined('MOODLE_INTERNAL') || die();
/**
* Syncing enrolments task.
*
* @package enrol_manual
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sync_enrolments extends \core\task\scheduled_task {
/**
* Name for this task.
*
* @return string
*/
public function get_name() {
return get_string('syncenrolmentstask', 'enrol_manual');
}
/**
* Run task for syncing enrolments.
*/
public function execute() {
$enrol = enrol_get_plugin('manual');
$trace = new \text_progress_trace();
$enrol->sync($trace);
}
}

49
enrol/manual/db/tasks.php Normal file
View File

@ -0,0 +1,49 @@
<?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/>.
/**
* Task definition for enrol_manual.
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @package enrol_manual
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = array(
array(
'classname' => '\enrol_manual\task\sync_enrolments',
'blocking' => 0,
'minute' => '*/10',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*',
'disabled' => 0
),
array(
'classname' => '\enrol_manual\task\send_expiry_notifications',
'blocking' => 0,
'minute' => '*/10',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*',
'disabled' => 0
)
);

View File

@ -66,11 +66,13 @@ $string['pluginname_desc'] = 'The manual enrolments plugin allows users to be en
$string['selection'] = 'Selection';
$string['selectusers'] = 'Select users';
$string['selectcohorts'] = 'Select cohorts';
$string['sendexpirynotificationstask'] = "Manual enrolment send expiry notifications task";
$string['status'] = 'Enable manual enrolments';
$string['status_desc'] = 'Allow course access of internally enrolled users. This should be kept enabled in most cases.';
$string['status_help'] = 'This setting determines whether users can be enrolled manually, via a link in the course administration settings, by a user with appropriate permissions such as a teacher.';
$string['statusenabled'] = 'Enabled';
$string['statusdisabled'] = 'Disabled';
$string['syncenrolmentstask'] = 'Manual enrolment synchronise enrolments task';
$string['unenrol'] = 'Unenrol user';
$string['unenrolselectedusers'] = 'Unenrol selected users';
$string['unenrolselfconfirm'] = 'Do you really want to unenrol yourself from course "{$a}"?';

View File

@ -227,16 +227,6 @@ class enrol_manual_plugin extends enrol_plugin {
return $button;
}
/**
* Enrol cron support.
* @return void
*/
public function cron() {
$trace = new text_progress_trace();
$this->sync($trace, null);
$this->send_expiry_notifications($trace);
}
/**
* Sync all meta course links.
*

View File

@ -24,7 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017111300; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2018040900; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2017110800; // Requires this Moodle version
$plugin->component = 'enrol_manual'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 600;

View File

@ -0,0 +1,58 @@
<?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/>.
/**
* Meta sync enrolments task.
*
* @package enrol_meta
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_meta\task;
defined('MOODLE_INTERNAL') || die();
/**
* Meta sync enrolments task.
*
* @package enrol_meta
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_meta_sync extends \core\task\scheduled_task {
/**
* Name for this task.
*
* @return string
*/
public function get_name() {
return get_string('enrolmetasynctask', 'enrol_meta');
}
/**
* Run task for syncing meta enrolments.
*/
public function execute() {
global $CFG;
require_once("$CFG->dirroot/enrol/meta/locallib.php");
enrol_meta_sync();
}
}

39
enrol/meta/db/tasks.php Normal file
View 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/>.
/**
* Task definition for enrol_meta.
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @package enrol_meta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = array(
array(
'classname' => '\enrol_meta\task\enrol_meta_sync',
'blocking' => 0,
'minute' => 'R',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*',
'disabled' => 0
)
);

View File

@ -27,6 +27,7 @@ $string['coursesort'] = 'Sort course list';
$string['coursesort_help'] = 'This determines whether the list of courses that can be linked are sorted by sort order (i.e. the order set in Site administration > Courses > Manage courses and categories) or alphabetically by course setting.';
$string['creategroup'] = 'Create new group';
$string['defaultgroupnametext'] = '{$a->name} course {$a->increment}';
$string['enrolmetasynctask'] = 'Meta enrolment sync task';
$string['linkedcourse'] = 'Link course';
$string['meta:config'] = 'Configure meta enrol instances';
$string['meta:selectaslinked'] = 'Select course as meta linked';

View File

@ -183,17 +183,6 @@ class enrol_meta_plugin extends enrol_plugin {
enrol_meta_sync($instance->courseid);
}
/**
* Called for all enabled enrol plugins that returned true from is_cron_required().
* @return void
*/
public function cron() {
global $CFG;
require_once("$CFG->dirroot/enrol/meta/locallib.php");
enrol_meta_sync();
}
/**
* Is it possible to delete enrol instance via standard UI?
*

View File

@ -24,7 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017111300; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2018040900; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2017110800; // Requires this Moodle version
$plugin->component = 'enrol_meta'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 60*60; // run cron every hour by default, it is not out-of-sync often

View File

@ -0,0 +1,58 @@
<?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/>.
/**
* Process expirations task.
*
* @package enrol_paypal
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_paypal\task;
defined('MOODLE_INTERNAL') || die();
/**
* Process expirations task.
*
* @package enrol_paypal
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class process_expirations extends \core\task\scheduled_task {
/**
* Name for this task.
*
* @return string
*/
public function get_name() {
return get_string('processexpirationstask', 'enrol_paypal');
}
/**
* Run task for processing expirations.
*/
public function execute() {
$enrol = enrol_get_plugin('paypal');
$trace = new \text_progress_trace();
$enrol->process_expirations($trace);
}
}

39
enrol/paypal/db/tasks.php Normal file
View 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/>.
/**
* Task definition for enrol_paypal.
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @package enrol_paypal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = array(
array(
'classname' => '\enrol_paypal\task\process_expirations',
'blocking' => 0,
'minute' => '*',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*',
'disabled' => 0
)
);

View File

@ -56,6 +56,7 @@ $string['paypal:unenrolself'] = 'Unenrol self from the course';
$string['paypalaccepted'] = 'PayPal payments accepted';
$string['pluginname'] = 'PayPal';
$string['pluginname_desc'] = 'The PayPal module allows you to set up paid courses. If the cost for any course is zero, then students are not asked to pay for entry. There is a site-wide cost that you set here as a default for the whole site and then a course setting that you can set for each course individually. The course cost overrides the site cost.';
$string['processexpirationstask'] = 'Process expirations task';
$string['sendpaymentbutton'] = 'Send payment via PayPal';
$string['status'] = 'Allow PayPal enrolments';
$string['status_desc'] = 'Allow users to use PayPal to enrol into a course by default.';

View File

@ -270,11 +270,6 @@ class enrol_paypal_plugin extends enrol_plugin {
$this->enrol_user($instance, $userid, null, $data->timestart, $data->timeend, $data->status);
}
public function cron() {
$trace = new text_progress_trace();
$this->process_expirations($trace);
}
/**
* Return an array of valid options for the status.
*

View File

@ -25,7 +25,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017111300; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2018040900; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2017110800; // Requires this Moodle version
$plugin->component = 'enrol_paypal'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 60;

View File

@ -0,0 +1,58 @@
<?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/>.
/**
* Send expiry notifications task.
*
* @package enrol_self
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_self\task;
defined('MOODLE_INTERNAL') || die();
/**
* Send expiry notifications task.
*
* @package enrol_self
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class send_expiry_notifications extends \core\task\scheduled_task {
/**
* Name for this task.
*
* @return string
*/
public function get_name() {
return get_string('sendexpirynotificationstask', 'enrol_self');
}
/**
* Run task for sending expiry notifications.
*/
public function execute() {
$enrol = enrol_get_plugin('self');
$trace = new \text_progress_trace();
$enrol->send_expiry_notifications($trace);
}
}

View File

@ -0,0 +1,58 @@
<?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/>.
/**
* Sync enrolments task.
*
* @package enrol_self
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_self\task;
defined('MOODLE_INTERNAL') || die();
/**
* Sync enrolments task.
*
* @package enrol_self
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sync_enrolments extends \core\task\scheduled_task {
/**
* Name for this task.
*
* @return string
*/
public function get_name() {
return get_string('syncenrolmentstask', 'enrol_self');
}
/**
* Run task for syncing enrolments.
*/
public function execute() {
$enrol = enrol_get_plugin('self');
$trace = new \text_progress_trace();
$enrol->sync($trace);
}
}

49
enrol/self/db/tasks.php Normal file
View File

@ -0,0 +1,49 @@
<?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/>.
/**
* Task definition for enrol_self.
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @package enrol_self
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = array(
array(
'classname' => '\enrol_self\task\sync_enrolments',
'blocking' => 0,
'minute' => '*/10',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*',
'disabled' => 0
),
array(
'classname' => '\enrol_self\task\send_expiry_notifications',
'blocking' => 0,
'minute' => '*/10',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*',
'disabled' => 0
)
);

View File

@ -102,11 +102,13 @@ $string['self:unenrol'] = 'Unenrol users from course';
$string['self:unenrolself'] = 'Unenrol self from the course';
$string['sendcoursewelcomemessage'] = 'Send course welcome message';
$string['sendcoursewelcomemessage_help'] = 'When a user self enrols in the course, they may be sent a welcome message email. If sent from the course contact (by default the teacher), and more than one user has this role, the email is sent from the first user to be assigned the role.';
$string['sendexpirynotificationstask'] = "Self enrolment send expiry notifications task";
$string['showhint'] = 'Show hint';
$string['showhint_desc'] = 'Show first letter of the guest access key.';
$string['status'] = 'Allow existing enrolments';
$string['status_desc'] = 'Enable self enrolment method in new courses.';
$string['status_help'] = 'If enabled together with \'Allow new enrolments\' disabled, only users who self enrolled previously can access the course. If disabled, this self enrolment method is effectively disabled, since all existing self enrolments are suspended and new users cannot self enrol.';
$string['syncenrolmentstask'] = 'Self enrolment synchronise enrolments task';
$string['unenrol'] = 'Unenrol user';
$string['unenrolselfconfirm'] = 'Do you really want to unenrol yourself from course "{$a}"?';
$string['unenroluser'] = 'Do you really want to unenrol "{$a->user}" from course "{$a->course}"?';

View File

@ -405,16 +405,6 @@ class enrol_self_plugin extends enrol_plugin {
email_to_user($user, $contact, $subject, $messagetext, $messagehtml);
}
/**
* Enrol self cron support.
* @return void
*/
public function cron() {
$trace = new text_progress_trace();
$this->sync($trace, null);
$this->send_expiry_notifications($trace);
}
/**
* Sync all meta course links.
*

View File

@ -24,7 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017111300; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2018040900; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2017110800; // Requires this Moodle version
$plugin->component = 'enrol_self'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 600;