Skip to content

Commit 998648d

Browse files
committed
Remove notificationhours inactivity check feature
The inactivity notification was unreliable and not useful in practice. Removes the setting, the check/send functions, and the lang strings.
1 parent 951e2a7 commit 998648d

File tree

3 files changed

+0
-101
lines changed

3 files changed

+0
-101
lines changed

lang/en/local_psaelmsync.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@
8383
$string['not_enrolled'] = 'Not Enrolled';
8484
$string['notificationemails'] = 'Alert emails';
8585
$string['notificationemails_desc'] = 'When issues arise with the processing of records, send an alert to these (comma-separated) addresses.';
86-
$string['notificationhours'] = 'Hours without processing a record';
87-
$string['notificationhours_desc'] = 'After each run we check to see how long it\'s been since we last processed an enrol or suspend. If it\'s been longer than this value it\'ll send a notification to \'notificationemails\'';
8886
$string['person_id'] = 'Person ID';
8987
$string['plugindesc'] = 'Read enrolment data posted to CData from ELM and then return completion data back.';
9088
$string['pluginname'] = 'PSALS Sync';

lib.php

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ function local_psaelmsync_sync() {
6666
// Fetch API URL and token from config.
6767
$apiurl = get_config('local_psaelmsync', 'apiurl');
6868
$apitoken = get_config('local_psaelmsync', 'apitoken');
69-
$notificationhours = get_config('local_psaelmsync', 'notificationhours');
70-
7169
if (!$apiurl || !$apitoken) {
7270
mtrace('PSA Enrol Sync: API URL or Token not set.');
7371
return;
@@ -162,12 +160,6 @@ function local_psaelmsync_sync() {
162160
'skippedcount' => $skippedcount,
163161
];
164162
$DB->insert_record('local_psaelmsync_runs', (object)$log);
165-
166-
// Check for the time since the last enrolment or suspend.
167-
// If it has been more than N hours then send an email to the
168-
// admin list notifying them that the bridge might be blocked
169-
// on the ELM side.
170-
check_last_enrolment_or_suspend($notificationhours);
171163
}
172164

173165
/**
@@ -814,86 +806,3 @@ function send_failure_notification(
814806
}
815807
}
816808
}
817-
818-
/**
819-
* Check the time since the last enrolment or suspend action and send
820-
* an inactivity notification if the threshold has been exceeded.
821-
*
822-
* Only sends notifications between 6 AM and 6 PM on weekdays.
823-
*
824-
* @param int $notificationhours The number of hours of inactivity before notifying.
825-
* @return void
826-
*/
827-
function check_last_enrolment_or_suspend($notificationhours) {
828-
global $DB;
829-
830-
// Calculate the threshold time.
831-
$thresholdtime = time() - ($notificationhours * 3600);
832-
833-
// Check if the current time is between 6 AM and 6 PM on a weekday.
834-
$currenttime = time();
835-
// Day of week: 1 for Monday through 7 for Sunday.
836-
$dayofweek = date('N', $currenttime);
837-
// Hour of day: 0 through 23.
838-
$hourofday = date('G', $currenttime);
839-
840-
if ($dayofweek >= 6 || $hourofday < 6 || $hourofday >= 18) {
841-
// Do not send notifications outside of 6 AM to 6 PM, Monday to Friday.
842-
return;
843-
}
844-
845-
// Query the last enrolment or suspend record.
846-
$lastaction = $DB->get_record_sql("
847-
SELECT MAX(timestamp) AS lasttime
848-
FROM {local_psaelmsync_logs}
849-
WHERE action IN ('Enrol', 'Suspend')
850-
");
851-
852-
if ($lastaction && $lastaction->lasttime < $thresholdtime) {
853-
// If the last action was before the threshold, send a notification.
854-
send_inactivity_notification($notificationhours);
855-
}
856-
}
857-
858-
/**
859-
* Send an inactivity notification email to configured administrators.
860-
*
861-
* @param int $notificationhours The number of hours of inactivity that triggered this notification.
862-
* @return void
863-
*/
864-
function send_inactivity_notification($notificationhours) {
865-
global $CFG;
866-
867-
$adminemails = get_config('local_psaelmsync', 'notificationemails');
868-
869-
if (!empty($adminemails)) {
870-
$emails = explode(',', $adminemails);
871-
$subject = "PSA Enrol Sync Inactivity Notification";
872-
$message = "No enrolment or suspension records have been "
873-
. "processed in the last {$notificationhours} hours. "
874-
. "Please check the system.";
875-
876-
$dummyuser = new stdClass();
877-
$dummyuser->email = 'noreply-psalssync@gov.bc.ca';
878-
$dummyuser->firstname = 'System';
879-
$dummyuser->lastname = 'Notifier';
880-
$dummyuser->id = -99;
881-
882-
foreach ($emails as $adminemail) {
883-
$adminemail = trim($adminemail);
884-
885-
$recipient = new stdClass();
886-
$recipient->email = $adminemail;
887-
$recipient->id = -99;
888-
$recipient->firstname = 'Admin';
889-
$recipient->lastname = 'User';
890-
891-
email_to_user(
892-
$recipient,
893-
$dummyuser,
894-
$subject,
895-
$message
896-
);
897-
}
898-
}
899-
}

settings.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@
5858
'',
5959
));
6060

61-
$settings->add(new admin_setting_configtext(
62-
'local_psaelmsync/notificationhours',
63-
get_string('notificationhours', 'local_psaelmsync'),
64-
get_string('notificationhours_desc', 'local_psaelmsync'),
65-
1,
66-
PARAM_INT,
67-
));
68-
6961
$settings->add(new admin_setting_configtext(
7062
'local_psaelmsync/completion_apiurl',
7163
get_string('completion_apiurl', 'local_psaelmsync'),

0 commit comments

Comments
 (0)