From fe5b5be1ddbfc848a720da8928ddf9fd2882a3b8 Mon Sep 17 00:00:00 2001 From: Farhan Karmali Date: Sat, 13 Jan 2018 13:07:12 +0530 Subject: [PATCH] MDL-61208 enrol: Standard enrol plugins should use tasks instead of cron --- .../category/classes/task/enrol_category_sync.php | 63 ++++++++++++++++++++++ .../{paypal/version.php => category/db/tasks.php} | 28 ++++++---- enrol/category/lang/en/enrol_category.php | 1 + enrol/category/lib.php | 16 ------ enrol/category/version.php | 3 +- enrol/cohort/classes/task/enrol_cohort_sync.php | 60 +++++++++++++++++++++ enrol/{self/version.php => cohort/db/tasks.php} | 27 ++++++---- enrol/cohort/lang/en/enrol_cohort.php | 1 + enrol/cohort/lib.php | 13 ----- enrol/cohort/version.php | 3 +- .../classes/task/send_expiry_notifications.php | 58 ++++++++++++++++++++ enrol/manual/classes/task/sync_enrolments.php | 57 ++++++++++++++++++++ enrol/manual/db/tasks.php | 49 +++++++++++++++++ enrol/manual/lang/en/enrol_manual.php | 2 + enrol/manual/lib.php | 10 ---- enrol/manual/version.php | 3 +- enrol/meta/classes/task/enrol_meta_sync.php | 58 ++++++++++++++++++++ enrol/{self/version.php => meta/db/tasks.php} | 27 ++++++---- enrol/meta/lang/en/enrol_meta.php | 1 + enrol/meta/lib.php | 11 ---- enrol/meta/version.php | 3 +- enrol/paypal/classes/task/process_expirations.php | 58 ++++++++++++++++++++ enrol/{self/version.php => paypal/db/tasks.php} | 27 ++++++---- enrol/paypal/lang/en/enrol_paypal.php | 1 + enrol/paypal/lib.php | 5 -- enrol/paypal/version.php | 3 +- .../classes/task/send_expiry_notifications.php | 58 ++++++++++++++++++++ enrol/self/classes/task/sync_enrolments.php | 58 ++++++++++++++++++++ enrol/self/db/tasks.php | 49 +++++++++++++++++ enrol/self/lang/en/enrol_self.php | 2 + enrol/self/lib.php | 10 ---- enrol/self/version.php | 3 +- 32 files changed, 654 insertions(+), 114 deletions(-) create mode 100644 enrol/category/classes/task/enrol_category_sync.php copy enrol/{paypal/version.php => category/db/tasks.php} (59%) create mode 100644 enrol/cohort/classes/task/enrol_cohort_sync.php copy enrol/{self/version.php => cohort/db/tasks.php} (60%) create mode 100644 enrol/manual/classes/task/send_expiry_notifications.php create mode 100644 enrol/manual/classes/task/sync_enrolments.php create mode 100644 enrol/manual/db/tasks.php create mode 100644 enrol/meta/classes/task/enrol_meta_sync.php copy enrol/{self/version.php => meta/db/tasks.php} (60%) create mode 100644 enrol/paypal/classes/task/process_expirations.php copy enrol/{self/version.php => paypal/db/tasks.php} (60%) create mode 100644 enrol/self/classes/task/send_expiry_notifications.php create mode 100644 enrol/self/classes/task/sync_enrolments.php create mode 100644 enrol/self/db/tasks.php diff --git a/enrol/category/classes/task/enrol_category_sync.php b/enrol/category/classes/task/enrol_category_sync.php new file mode 100644 index 00000000000..addc0f6ff66 --- /dev/null +++ b/enrol/category/classes/task/enrol_category_sync.php @@ -0,0 +1,63 @@ +. + +/** + * Syncing enrolments task. + * + * @package enrol_category + * @author Farhan Karmali + * @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 + * @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); + } +} diff --git a/enrol/paypal/version.php b/enrol/category/db/tasks.php similarity index 59% copy from enrol/paypal/version.php copy to enrol/category/db/tasks.php index a0aad9687b9..3a0f24842a3 100644 --- a/enrol/paypal/version.php +++ b/enrol/category/db/tasks.php @@ -15,17 +15,25 @@ // along with Moodle. If not, see . /** - * Paypal enrolment plugin version specification. - * - * @package enrol_paypal - * @copyright 2010 Eugene Venter - * @author Eugene Venter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * Task definition for enrol_category. + * @author Farhan Karmali + * @copyright Farhan Karmali + * @package enrol_category + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017111300; // 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; +$tasks = array( + array( + 'classname' => '\enrol_category\task\enrol_category_sync', + 'blocking' => 0, + 'minute' => '*', + 'hour' => '*', + 'day' => '*', + 'month' => '*', + 'dayofweek' => '*', + 'disabled' => 0 + ) +); + diff --git a/enrol/category/lang/en/enrol_category.php b/enrol/category/lang/en/enrol_category.php index 5857ccc3148..1c36a0f507f 100644 --- a/enrol/category/lang/en/enrol_category.php +++ b/enrol/category/lang/en/enrol_category.php @@ -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.'; diff --git a/enrol/category/lib.php b/enrol/category/lib.php index ef1699d42e1..f63e005cd6a 100644 --- a/enrol/category/lib.php +++ b/enrol/category/lib.php @@ -75,22 +75,6 @@ class enrol_category_plugin extends enrol_plugin { } /** - * 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. * * @param bool $inserted true if course just inserted diff --git a/enrol/category/version.php b/enrol/category/version.php index 9fdeda59110..70babaa6197 100644 --- a/enrol/category/version.php +++ b/enrol/category/version.php @@ -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; diff --git a/enrol/cohort/classes/task/enrol_cohort_sync.php b/enrol/cohort/classes/task/enrol_cohort_sync.php new file mode 100644 index 00000000000..d288a5d534a --- /dev/null +++ b/enrol/cohort/classes/task/enrol_cohort_sync.php @@ -0,0 +1,60 @@ +. + +/** + * Syncing enrolments task. + * + * @package enrol_cohort + * @author Farhan Karmali + * @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 + * @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(); + } +} diff --git a/enrol/self/version.php b/enrol/cohort/db/tasks.php similarity index 60% copy from enrol/self/version.php copy to enrol/cohort/db/tasks.php index 59626164162..4b258be76dd 100644 --- a/enrol/self/version.php +++ b/enrol/cohort/db/tasks.php @@ -15,16 +15,25 @@ // along with Moodle. If not, see . /** - * Self enrolment plugin version specification. - * - * @package enrol_self - * @copyright 2010 Petr Skoda {@link http://skodak.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * Task definition for enrol_cohort. + * @author Farhan Karmali + * @copyright Farhan Karmali + * @package enrol_cohort + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017111300; // 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; +$tasks = array( + array( + 'classname' => '\enrol_cohort\task\enrol_cohort_sync', + 'blocking' => 0, + 'minute' => 'R', + 'hour' => '*', + 'day' => '*', + 'month' => '*', + 'dayofweek' => '*', + 'disabled' => 0 + ) +); + diff --git a/enrol/cohort/lang/en/enrol_cohort.php b/enrol/cohort/lang/en/enrol_cohort.php index c96d02d1e64..50fdd26ebf4 100644 --- a/enrol/cohort/lang/en/enrol_cohort.php +++ b/enrol/cohort/lang/en/enrol_cohort.php @@ -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.'; diff --git a/enrol/cohort/lib.php b/enrol/cohort/lib.php index dfe7d828168..aaca643ba58 100644 --- a/enrol/cohort/lib.php +++ b/enrol/cohort/lib.php @@ -162,19 +162,6 @@ class enrol_cohort_plugin extends enrol_plugin { } /** - * 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. * * @param bool $inserted true if course just inserted diff --git a/enrol/cohort/version.php b/enrol/cohort/version.php index ca198335c45..edcc1add7bb 100644 --- a/enrol/cohort/version.php +++ b/enrol/cohort/version.php @@ -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 diff --git a/enrol/manual/classes/task/send_expiry_notifications.php b/enrol/manual/classes/task/send_expiry_notifications.php new file mode 100644 index 00000000000..ab8388014ab --- /dev/null +++ b/enrol/manual/classes/task/send_expiry_notifications.php @@ -0,0 +1,58 @@ +. + +/** + * The send expiry notifications task. + * + * @package enrol_manual + * @author Farhan Karmali + * @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 + * @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); + } + +} diff --git a/enrol/manual/classes/task/sync_enrolments.php b/enrol/manual/classes/task/sync_enrolments.php new file mode 100644 index 00000000000..cddcde5502b --- /dev/null +++ b/enrol/manual/classes/task/sync_enrolments.php @@ -0,0 +1,57 @@ +. + +/** + * Syncing enrolments task. + * + * @package enrol_manual + * @author Farhan Karmali + * @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 + * @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); + } +} diff --git a/enrol/manual/db/tasks.php b/enrol/manual/db/tasks.php new file mode 100644 index 00000000000..c1d87a4ae0a --- /dev/null +++ b/enrol/manual/db/tasks.php @@ -0,0 +1,49 @@ +. + +/** + * Task definition for enrol_manual. + * @author Farhan Karmali + * @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 + ) +); + diff --git a/enrol/manual/lang/en/enrol_manual.php b/enrol/manual/lang/en/enrol_manual.php index 29edcc5c3b2..1d68899943a 100644 --- a/enrol/manual/lang/en/enrol_manual.php +++ b/enrol/manual/lang/en/enrol_manual.php @@ -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}"?'; diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index d0ff65a9568..a346a08a8b5 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -228,16 +228,6 @@ class enrol_manual_plugin extends enrol_plugin { } /** - * 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. * * @param progress_trace $trace diff --git a/enrol/manual/version.php b/enrol/manual/version.php index db372f603ad..d5833980712 100644 --- a/enrol/manual/version.php +++ b/enrol/manual/version.php @@ -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; diff --git a/enrol/meta/classes/task/enrol_meta_sync.php b/enrol/meta/classes/task/enrol_meta_sync.php new file mode 100644 index 00000000000..26b1f6a1303 --- /dev/null +++ b/enrol/meta/classes/task/enrol_meta_sync.php @@ -0,0 +1,58 @@ +. + +/** + * Meta sync enrolments task. + * + * @package enrol_meta + * @author Farhan Karmali + * @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 + * @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(); + } + +} diff --git a/enrol/self/version.php b/enrol/meta/db/tasks.php similarity index 60% copy from enrol/self/version.php copy to enrol/meta/db/tasks.php index 59626164162..f3aaf0a6494 100644 --- a/enrol/self/version.php +++ b/enrol/meta/db/tasks.php @@ -15,16 +15,25 @@ // along with Moodle. If not, see . /** - * Self enrolment plugin version specification. - * - * @package enrol_self - * @copyright 2010 Petr Skoda {@link http://skodak.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * Task definition for enrol_meta. + * @author Farhan Karmali + * @copyright Farhan Karmali + * @package enrol_meta + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017111300; // 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; +$tasks = array( + array( + 'classname' => '\enrol_meta\task\enrol_meta_sync', + 'blocking' => 0, + 'minute' => 'R', + 'hour' => '*', + 'day' => '*', + 'month' => '*', + 'dayofweek' => '*', + 'disabled' => 0 + ) +); + diff --git a/enrol/meta/lang/en/enrol_meta.php b/enrol/meta/lang/en/enrol_meta.php index e5c2f21cb09..e2b43d3e16c 100644 --- a/enrol/meta/lang/en/enrol_meta.php +++ b/enrol/meta/lang/en/enrol_meta.php @@ -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'; diff --git a/enrol/meta/lib.php b/enrol/meta/lib.php index 3d9e09ec8f4..b64817b7140 100644 --- a/enrol/meta/lib.php +++ b/enrol/meta/lib.php @@ -184,17 +184,6 @@ class enrol_meta_plugin extends enrol_plugin { } /** - * 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? * * @param stdClass $instance diff --git a/enrol/meta/version.php b/enrol/meta/version.php index 3fac2acf3c5..b9340787bad 100644 --- a/enrol/meta/version.php +++ b/enrol/meta/version.php @@ -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 diff --git a/enrol/paypal/classes/task/process_expirations.php b/enrol/paypal/classes/task/process_expirations.php new file mode 100644 index 00000000000..0eeda0a08c8 --- /dev/null +++ b/enrol/paypal/classes/task/process_expirations.php @@ -0,0 +1,58 @@ +. + +/** + * Process expirations task. + * + * @package enrol_paypal + * @author Farhan Karmali + * @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 + * @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); + } + +} diff --git a/enrol/self/version.php b/enrol/paypal/db/tasks.php similarity index 60% copy from enrol/self/version.php copy to enrol/paypal/db/tasks.php index 59626164162..afc8e80aca8 100644 --- a/enrol/self/version.php +++ b/enrol/paypal/db/tasks.php @@ -15,16 +15,25 @@ // along with Moodle. If not, see . /** - * Self enrolment plugin version specification. - * - * @package enrol_self - * @copyright 2010 Petr Skoda {@link http://skodak.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * Task definition for enrol_paypal. + * @author Farhan Karmali + * @copyright Farhan Karmali + * @package enrol_paypal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017111300; // 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; +$tasks = array( + array( + 'classname' => '\enrol_paypal\task\process_expirations', + 'blocking' => 0, + 'minute' => '*', + 'hour' => '*', + 'day' => '*', + 'month' => '*', + 'dayofweek' => '*', + 'disabled' => 0 + ) +); + diff --git a/enrol/paypal/lang/en/enrol_paypal.php b/enrol/paypal/lang/en/enrol_paypal.php index 80abf1835e6..500e69350a4 100644 --- a/enrol/paypal/lang/en/enrol_paypal.php +++ b/enrol/paypal/lang/en/enrol_paypal.php @@ -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.'; diff --git a/enrol/paypal/lib.php b/enrol/paypal/lib.php index c22e6f2b522..21e77e94829 100644 --- a/enrol/paypal/lib.php +++ b/enrol/paypal/lib.php @@ -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. * diff --git a/enrol/paypal/version.php b/enrol/paypal/version.php index a0aad9687b9..e2263aebc86 100644 --- a/enrol/paypal/version.php +++ b/enrol/paypal/version.php @@ -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; diff --git a/enrol/self/classes/task/send_expiry_notifications.php b/enrol/self/classes/task/send_expiry_notifications.php new file mode 100644 index 00000000000..bded37f5e9b --- /dev/null +++ b/enrol/self/classes/task/send_expiry_notifications.php @@ -0,0 +1,58 @@ +. + +/** + * Send expiry notifications task. + * + * @package enrol_self + * @author Farhan Karmali + * @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 + * @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); + } + +} diff --git a/enrol/self/classes/task/sync_enrolments.php b/enrol/self/classes/task/sync_enrolments.php new file mode 100644 index 00000000000..706bfe570fe --- /dev/null +++ b/enrol/self/classes/task/sync_enrolments.php @@ -0,0 +1,58 @@ +. + +/** + * Sync enrolments task. + * + * @package enrol_self + * @author Farhan Karmali + * @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 + * @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); + } + +} diff --git a/enrol/self/db/tasks.php b/enrol/self/db/tasks.php new file mode 100644 index 00000000000..f7f71948a91 --- /dev/null +++ b/enrol/self/db/tasks.php @@ -0,0 +1,49 @@ +. + +/** + * Task definition for enrol_self. + * @author Farhan Karmali + * @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 + ) +); + diff --git a/enrol/self/lang/en/enrol_self.php b/enrol/self/lang/en/enrol_self.php index 9cfb17a81f7..c5aabd62e38 100644 --- a/enrol/self/lang/en/enrol_self.php +++ b/enrol/self/lang/en/enrol_self.php @@ -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}"?'; diff --git a/enrol/self/lib.php b/enrol/self/lib.php index e521c2ef929..87e9c141112 100644 --- a/enrol/self/lib.php +++ b/enrol/self/lib.php @@ -406,16 +406,6 @@ class enrol_self_plugin extends enrol_plugin { } /** - * 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. * * @param progress_trace $trace diff --git a/enrol/self/version.php b/enrol/self/version.php index 59626164162..b7046fb4aba 100644 --- a/enrol/self/version.php +++ b/enrol/self/version.php @@ -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; -- 2.11.4.GIT