Commit f4da7744 authored by Nigel McNie's avatar Nigel McNie
Browse files

Prevent Mahara crashing if it can't send e-mail to new users created by CSV.

Instead, generate a list of users who we could not send e-mail to, and display this to the uploaded, with more detailed reasons in the server error log.
parent 9d946b0a
......@@ -349,10 +349,26 @@ function uploadcsv_submit(Pieform $form, $values) {
$straccountcreatedhtml = ($values['forcepasswordchange']) ? 'accountcreatedchangepasswordhtml' : 'accountcreatedhtml';
if ($values['emailusers'] && $addedusers) {
foreach ($addedusers as $user) {
email_user($user, null, get_string('accountcreated'),
get_string($straccountcreatedtext, 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('sitename')),
get_string($straccountcreatedhtml, 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('sitename'))
);
$failedusers = array();
try {
email_user($user, null, get_string('accountcreated'),
get_string($straccountcreatedtext, 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('sitename')),
get_string($straccountcreatedhtml, 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('sitename'))
);
}
catch (EmailException $e) {
log_info($e->getMessage());
$failedusers[] = $user;
}
}
if ($failedusers) {
$message = get_string('uploadcsvsomeuserscouldnotbeemailed', 'admin') . "\n<ul>\n";
foreach ($failedusers as $user) {
$message .= '<li>' . full_name($user) . ' &lt;' . hsc($user->email) . "&gt;</li>\n";
}
$message .= "</ul>\n";
$SESSION->add_info_msg($message, false);
}
}
......
......@@ -226,6 +226,7 @@ $string['uploadcsvpagedescription'] = '<p>You may use this facility to upload ne
<p>Your CSV file may include any other profile fields as you require. The full list of fields is:</p>
%s';
$string['uploadcsvsomeuserscouldnotbeemailed'] = 'Some users could not be e-mailed. Their e-mail addresses may be invalid, or the server Mahara is running on might not be configured to send e-mail properly. The server error log has more details. For now, you may want to contact these people manually:';
$string['uploadcsvusersaddedsuccessfully'] = 'The users in the file have been added successfully';
$string['uploadcsvfailedusersexceedmaxallowed'] = 'No users have been added because there are too many users in your file. The number of users in the institution would have exceeded the maximum number allowed.';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment