From 8e941204b232073a87ce9b43bddf44488d4ca617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Sat, 13 Oct 2012 21:43:28 +0200 Subject: [PATCH] MDL-35843 prepare fox expiry refactoring to core enrol feature AMOS BEGIN MOV [errorthresholdlow,enrol_manual],[errorthresholdlow,core_enrol] MOV [expirynotify,enrol_manual],[expirynotify,core_enrol] MOV [expirynotify_help,enrol_manual],[expirynotify_help,core_enrol] MOV [expirynotifyall,enrol_manual],[expirynotifyall,core_enrol] MOV [expirynotifyteacher,enrol_manual],[expirynotifyenroller,core_enrol] MOV [notifyhour,enrol_manual],[expirynotifyhour,core_enrol] MOV [expirythreshold,enrol_manual],[expirythreshold,core_enrol] MOV [expirythreshold_help,enrol_manual],[expirythreshold_help,core_enrol] AMOS END --- enrol/manual/cli/sync.php | 2 +- enrol/manual/db/upgrade.php | 8 ++++++++ enrol/manual/edit_form.php | 12 ++++++------ enrol/manual/lang/en/enrol_manual.php | 9 --------- enrol/manual/lib.php | 16 ++++++++-------- enrol/manual/settings.php | 8 ++++---- enrol/manual/tests/lib_test.php | 18 +++++++++--------- enrol/manual/version.php | 2 +- lang/en/enrol.php | 8 ++++++++ lang/en/moodle.php | 20 -------------------- 10 files changed, 45 insertions(+), 58 deletions(-) diff --git a/enrol/manual/cli/sync.php b/enrol/manual/cli/sync.php index 442822c5d8bb5..1026bb74ac30a 100644 --- a/enrol/manual/cli/sync.php +++ b/enrol/manual/cli/sync.php @@ -63,6 +63,6 @@ $result = $plugin->sync(null, $verbose); -$plugin->send_notifications($verbose); +$plugin->send_expiry_notifications($verbose); exit($result); diff --git a/enrol/manual/db/upgrade.php b/enrol/manual/db/upgrade.php index 6bc2602995ecf..5a9eb1e89a112 100644 --- a/enrol/manual/db/upgrade.php +++ b/enrol/manual/db/upgrade.php @@ -38,6 +38,14 @@ function xmldb_enrol_manual_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2012100702, 'enrol', 'manual'); } + if ($oldversion < 2012101400) { + // Delete obsoleted settings, now using expiry* prefix to make them more consistent. + unset_config('notifylast', 'enrol_manual'); + unset_config('notifyhour', 'enrol_manual'); + upgrade_plugin_savepoint(true, 2012101400, 'enrol', 'manual'); + } + + return true; } diff --git a/enrol/manual/edit_form.php b/enrol/manual/edit_form.php index 23b7f4e38d704..d148078b10a4b 100644 --- a/enrol/manual/edit_form.php +++ b/enrol/manual/edit_form.php @@ -54,12 +54,12 @@ function definition() { $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod')); $mform->addHelpButton('enrolperiod', 'defaultperiod', 'enrol_manual'); - $options = array(0 => get_string('no'), 1 => get_string('expirynotifyteacher', 'enrol_manual'), 2 => get_string('expirynotifyall', 'enrol_manual')); - $mform->addElement('select', 'expirynotify', get_string('expirynotify', 'enrol_manual'), $options); - $mform->addHelpButton('expirynotify', 'expirynotify', 'enrol_manual'); + $options = array(0 => get_string('no'), 1 => get_string('expirynotifyenroller', 'core_enrol'), 2 => get_string('expirynotifyall', 'core_enrol')); + $mform->addElement('select', 'expirynotify', get_string('expirynotify', 'core_enrol'), $options); + $mform->addHelpButton('expirynotify', 'expirynotify', 'core_enrol'); - $mform->addElement('duration', 'expirythreshold', get_string('expirythreshold', 'enrol_manual'), array('optional' => false, 'defaultunit' => 86400)); - $mform->addHelpButton('expirythreshold', 'expirythreshold', 'enrol_manual'); + $mform->addElement('duration', 'expirythreshold', get_string('expirythreshold', 'core_enrol'), array('optional' => false, 'defaultunit' => 86400)); + $mform->addHelpButton('expirythreshold', 'expirythreshold', 'core_enrol'); $mform->disabledIf('expirythreshold', 'expirynotify', 'eq', 0); $mform->addElement('hidden', 'courseid'); @@ -75,7 +75,7 @@ function validation($data, $files) { $errors = parent::validation($data, $files); if ($data['expirynotify'] > 0 and $data['expirythreshold'] < 86400) { - $errors['expirythreshold'] = get_string('errorthresholdlow', 'enrol_manual'); + $errors['expirythreshold'] = get_string('errorthresholdlow', 'core_enrol'); } return $errors; diff --git a/enrol/manual/lang/en/enrol_manual.php b/enrol/manual/lang/en/enrol_manual.php index b4494f28e3cf9..5ddf50f97cebb 100644 --- a/enrol/manual/lang/en/enrol_manual.php +++ b/enrol/manual/lang/en/enrol_manual.php @@ -35,7 +35,6 @@ $string['editselectedusers'] = 'Edit selected user enrolments'; $string['enrolledincourserole'] = 'Enrolled in "{$a->course}" as "{$a->role}"'; $string['enrolusers'] = 'Enrol users'; -$string['errorthresholdlow'] = 'Notification threshold must be at least 1 day.'; $string['expiredaction'] = 'Enrolment expiration action'; $string['expiredaction_help'] = 'Select action to carry out when user enrolment expires. Please note that some user data and settings are purged from course during course unenrolment.'; $string['expirymessageenrollersubject'] = 'Enrolment expiry notification'; @@ -50,20 +49,12 @@ This is a notification that your enrolment in the course \'{$a->course}\' is due to expire on {$a->timeend}. If you need help, please contact {$a->enroller}.'; -$string['expirynotify'] = 'Notify before enrolment expires'; -$string['expirynotify_help'] = 'This setting determines whether enrolment expiry notification messages are sent.'; -$string['expirynotifyall'] = 'Enroller and enrolled user'; -$string['expirynotifyteacher'] = 'Enroller only'; -$string['expirythreshold'] = 'Notification threshold'; -$string['expirythreshold_help'] = 'This setting specifies the number of days before enrolment expiry that a notification message is sent.'; -$string['expirythreshold_help'] = 'How long before expiration should be users notified?'; $string['manual:config'] = 'Configure manual enrol instances'; $string['manual:enrol'] = 'Enrol users'; $string['manual:manage'] = 'Manage user enrolments'; $string['manual:unenrol'] = 'Unenrol users from the course'; $string['manual:unenrolself'] = 'Unenrol self from the course'; $string['messageprovider:expiry_notification'] = 'Manual enrolment expiry notifications'; -$string['notifyhour'] = 'Hour to send enrolment expiry notifications'; $string['pluginname'] = 'Manual enrolments'; $string['pluginname_desc'] = 'The manual enrolments plugin allows users to be enrolled manually via a link in the course administration settings, by a user with appropriate permissions such as a teacher. The plugin should normally be enabled, since certain other enrolment plugins, such as self enrolment, require it.'; $string['status'] = 'Enable manual enrolments'; diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index f699be0c12d29..0f83d020c2d8c 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -280,7 +280,7 @@ public function get_manual_enrol_button(course_enrolment_manager $manager) { */ public function cron() { $this->sync(null, true); - $this->send_notifications(true); + $this->send_expiry_notifications(true); } /** @@ -380,7 +380,7 @@ public function sync($courseid = null, $verbose = false) { * * @param bool $verbose verbose CLI output */ - public function send_notifications($verbose = false) { + public function send_expiry_notifications($verbose = false) { global $DB, $CFG; // Unfortunately this may take a long time, it should not be interrupted, @@ -389,15 +389,15 @@ public function send_notifications($verbose = false) { @set_time_limit(0); raise_memory_limit(MEMORY_HUGE); - $notifylast = $this->get_config('notifylast', 0); - $notifyhour = $this->get_config('notifyhour', 6); + $expirynotifylast = $this->get_config('expirynotifylast', 0); + $expirynotifyhour = $this->get_config('expirynotifyhour', 6); $timenow = time(); - $notifytime = usergetmidnight($timenow, $CFG->timezone) + ($notifyhour * 3600); + $notifytime = usergetmidnight($timenow, $CFG->timezone) + ($expirynotifyhour * 3600); - if ($notifylast > $notifytime) { + if ($expirynotifylast > $notifytime) { if ($verbose) { - mtrace('Manual enrolment notifications were already sent today at '.userdate($notifylast, '', $CFG->timezone).'.'); + mtrace('Manual enrolment notifications were already sent today at '.userdate($expirynotifylast, '', $CFG->timezone).'.'); } return; } else if ($timenow < $notifytime) { @@ -463,7 +463,7 @@ public function send_notifications($verbose = false) { if ($verbose) { mtrace('...notification processing finished.'); } - $this->set_config('notifylast', $timenow); + $this->set_config('expirynotifylast', $timenow); } /** diff --git a/enrol/manual/settings.php b/enrol/manual/settings.php index d27d26585be5b..8905c1f2295fe 100644 --- a/enrol/manual/settings.php +++ b/enrol/manual/settings.php @@ -42,7 +42,7 @@ for ($i=0; $i<24; $i++) { $options[$i] = $i; } - $settings->add(new admin_setting_configselect('enrol_manual/notifyhour', get_string('notifyhour', 'enrol_manual'), '', 6, $options)); + $settings->add(new admin_setting_configselect('enrol_manual/expirynotifyhour', get_string('expirynotifyhour', 'core_enrol'), '', 6, $options)); //--- enrol instance defaults ---------------------------------------------------------------------------- @@ -68,11 +68,11 @@ $settings->add(new admin_setting_configduration('enrol_manual/enrolperiod', get_string('defaultperiod', 'enrol_manual'), get_string('defaultperiod_desc', 'enrol_manual'), 0)); - $options = array(0 => get_string('no'), 1 => get_string('expirynotifyteacher', 'enrol_manual'), 2 => get_string('expirynotifyall', 'enrol_manual')); + $options = array(0 => get_string('no'), 1 => get_string('expirynotifyenroller', 'core_enrol'), 2 => get_string('expirynotifyall', 'core_enrol')); $settings->add(new admin_setting_configselect('enrol_manual/expirynotify', - get_string('expirynotify', 'enrol_manual'), get_string('expirynotify_help', 'enrol_manual'), 0, $options)); + get_string('expirynotify', 'core_enrol'), get_string('expirynotify_help', 'core_enrol'), 0, $options)); $settings->add(new admin_setting_configduration('enrol_manual/expirythreshold', - get_string('expirythreshold', 'enrol_manual'), get_string('expirythreshold_help', 'enrol_manual'), 86400, 86400)); + get_string('expirythreshold', 'core_enrol'), get_string('expirythreshold_help', 'core_enrol'), 86400, 86400)); } diff --git a/enrol/manual/tests/lib_test.php b/enrol/manual/tests/lib_test.php index ffd850a2f8655..58bbb70a6353a 100644 --- a/enrol/manual/tests/lib_test.php +++ b/enrol/manual/tests/lib_test.php @@ -316,8 +316,8 @@ public function test_send_expiry_notifications() { // Note: hopefully nobody executes the unit tests the last second before midnight... - $manualplugin->set_config('notifylast', $now - 60*60*24); - $manualplugin->set_config('notifyhour', 0); + $manualplugin->set_config('expirynotifylast', $now - 60*60*24); + $manualplugin->set_config('expirynotifyhour', 0); $studentrole = $DB->get_record('role', array('shortname'=>'student')); $this->assertNotEmpty($studentrole); @@ -394,7 +394,7 @@ public function test_send_expiry_notifications() { $sink = $this->redirectMessages(); - $manualplugin->send_notifications(false); + $manualplugin->send_expiry_notifications(false); $messages = $sink->get_messages(); @@ -451,18 +451,18 @@ public function test_send_expiry_notifications() { // Make sure that notifications are not repeated. $sink->clear(); - $manualplugin->send_notifications(false); + $manualplugin->send_expiry_notifications(false); $this->assertEquals(0, $sink->count()); // use invalid notification hour to verify that before the hour the notifications are not sent. - $manualplugin->set_config('notifylast', time() - 60*60*24); - $manualplugin->set_config('notifyhour', '24'); + $manualplugin->set_config('expirynotifylast', time() - 60*60*24); + $manualplugin->set_config('expirynotifyhour', '24'); - $manualplugin->send_notifications(false); + $manualplugin->send_expiry_notifications(false); $this->assertEquals(0, $sink->count()); - $manualplugin->set_config('notifyhour', '0'); - $manualplugin->send_notifications(false); + $manualplugin->set_config('expirynotifyhour', '0'); + $manualplugin->send_expiry_notifications(false); $this->assertEquals(6, $sink->count()); } } diff --git a/enrol/manual/version.php b/enrol/manual/version.php index 6d041337004b9..cefae3224c687 100644 --- a/enrol/manual/version.php +++ b/enrol/manual/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2012100705; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2012101400; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2012100500; // Requires this Moodle version $plugin->component = 'enrol_manual'; // Full name of the plugin (used for diagnostics) $plugin->cron = 600; diff --git a/lang/en/enrol.php b/lang/en/enrol.php index 9c1621caabaaf..b81b311e855e3 100644 --- a/lang/en/enrol.php +++ b/lang/en/enrol.php @@ -66,7 +66,15 @@ $string['erroreditenrolment'] = 'An error occurred while trying to edit a users enrolment'; $string['errorenrolcohort'] = 'Error creating cohort sync enrolment instance in this course.'; $string['errorenrolcohortusers'] = 'Error enrolling cohort members in this course.'; +$string['errorthresholdlow'] = 'Notification threshold must be at least 1 day.'; $string['errorwithbulkoperation'] = 'There was an error while processing your bulk enrolment change.'; +$string['expirynotify'] = 'Notify before enrolment expires'; +$string['expirynotify_help'] = 'This setting determines whether enrolment expiry notification messages are sent.'; +$string['expirynotifyall'] = 'Enroller and enrolled user'; +$string['expirynotifyenroller'] = 'Enroller only'; +$string['expirynotifyhour'] = 'Hour to send enrolment expiry notifications'; +$string['expirythreshold'] = 'Notification threshold'; +$string['expirythreshold_help'] = 'How long before expiration should be users notified?'; $string['finishenrollingusers'] = 'Finish enrolling users'; $string['invalidenrolinstance'] = 'Invalid enrolment instance'; $string['invalidrole'] = 'Invalid role'; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index bfd4374035765..39ab8077ba60e 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -659,26 +659,6 @@ $string['existingstudents'] = 'Enrolled students'; $string['existingteachers'] = 'Existing teachers'; $string['expandall'] = 'Expand all'; -$string['expirynotify'] = 'Enrolment expiry notification'; -$string['expirynotifyemail'] = 'The following students in this course are expiring after exactly {$a->threshold} days: - -{$a->current} - -The following students in this course are expiring in less than {$a->threshold} days: - -{$a->past} - -You may go to the following page to extend their enrolment period: -{$a->extendurl}'; -$string['expirynotifystudents'] = 'Notify students'; -$string['expirynotifystudents_help'] = 'If an enrolment duration has been specified, then this setting determines whether students receive email notification when they are about to be unenrolled from the course.'; -$string['expirynotifystudentsemail'] = 'Dear {$a->studentstr}: - -This is a notification that your enrolment in the course {$a->course} will expire in {$a->threshold} days. - -Please contact {$a->teacherstr} for any further enquiries.'; -$string['expirythreshold'] = 'Threshold'; -$string['expirythreshold_help'] = 'If an enrolment duration has been specified, then this setting determines the number of days notice given before students are unenrolled from the course.'; $string['explanation'] = 'Explanation'; $string['extendenrol'] = 'Extend enrolment (individual)'; $string['extendperiod'] = 'Extended period';