Skip to content

Commit

Permalink
add user ids to emails
Browse files Browse the repository at this point in the history
  • Loading branch information
my-curiosity committed Oct 8, 2024
1 parent fb2db33 commit 076da42
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions classes/task/archive_user_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@ public function execute() {

$suspendresult = $this->change_user_deprovisionstatus($archivearray, 'suspend');
$unabletoarchive = $suspendresult['failures'];
$unabletoarchivemessages = $suspendresult['messages'];
$userarchived = $suspendresult['countersuccess'];

$result = $this->change_user_deprovisionstatus($reactivatearray, 'reactivate');
$unabletoactivate = $result['failures'];
$unabletoactivatemessages = $result['messages'];
$useractivated = $result['countersuccess'];

$deleteresult = $this->change_user_deprovisionstatus($arraytodelete, 'delete');
$unabletodelete = $deleteresult['failures'];
$unabletodeletemessages = $deleteresult['messages'];
$userdeleted = $deleteresult['countersuccess'];

// Admin is informed about the cron-job and the amount of users that are affected.
Expand All @@ -102,18 +105,20 @@ public function execute() {
} else {
// Extra information for problematic users.
$messagetext .= "\r\n\r\n" . get_string(
'e-mail-problematic_delete',
'tool_cleanupusers',
count($unabletodelete)
) . "\r\n\r\n" . get_string(
'e-mail-problematic_suspend',
'tool_cleanupusers',
count($unabletoarchive)
) . "\r\n\r\n" . get_string(
'e-mail-problematic_reactivate',
'tool_cleanupusers',
count($unabletoactivate)
);
'e-mail-problematic_delete',
'tool_cleanupusers',
count($unabletodelete)
) . "\n" . $unabletodeletemessages
. "\r\n\r\n" . get_string(
'e-mail-problematic_suspend',
'tool_cleanupusers',
count($unabletoarchive)
) . "\n" . $unabletoarchivemessages
. "\r\n\r\n" . get_string(
'e-mail-problematic_reactivate',
'tool_cleanupusers',
count($unabletoactivate)
) . "\n" . $unabletoactivatemessages;
}

// Email is send from the do not reply user.
Expand Down Expand Up @@ -148,6 +153,8 @@ private function change_user_deprovisionstatus($userarray, $intention) {
// Array of users who could not be changed.
$failures = [];

$messages = "";

// Alternatively one could have written different function for each intention.
// However, this would have produced duplicated code.
// Therefore, checking the intention parameter repeatedly was preferred.
Expand Down Expand Up @@ -176,12 +183,14 @@ private function change_user_deprovisionstatus($userarray, $intention) {
$countersuccess++;
} catch (\Throwable $e) {
$failures[$key] = $user->id;
$messages .= "\n Could not " . $intention . " " . $user->username;
}
}
}
$result = [];
$result['countersuccess'] = $countersuccess;
$result['failures'] = $failures;
$result['messages'] = $messages;
return $result;
}
}

0 comments on commit 076da42

Please sign in to comment.