Commit 9dc7cbc6 authored by Lisa Seeto's avatar Lisa Seeto Committed by Robert Lyon

Bug 1843149: Bulk import doesn't retain user details correctly

This change does the following:
- Gets rid of the static cache that was created during run
of the first record which would only save the first user's info.
- when username is taken, append numbers and not underscores
- get rid of the warning using count on globals var that were not
previously set to array()s.
- respects the email users about their accounts option

behatnotneeded

Change-Id: I57b1c5e4d401028defda0c35bfc8347149094eb2
Signed-off-by: default avatarLisa Seeto <lisaseeto@catalyst.net.nz>
parent 73ee0b00
......@@ -18,6 +18,9 @@ safe_require('artefact', 'internal');
safe_require('artefact', 'file');
define('TITLE', get_string('bulkleap2aimport', 'admin'));
$FAILEDUSERS = array();
$ADDEDUSERS = array();
$EMAILUSERS = false;
// Turn on autodetecting of line endings, so mac newlines (\r) will work
ini_set('auto_detect_line_endings', 1);
......@@ -144,7 +147,11 @@ function bulkimport_validate(Pieform $form, $values) {
* Add the users to the system.
*/
function bulkimport_submit(Pieform $form, $values) {
global $SESSION, $LEAP2AFILES;
global $SESSION, $LEAP2AFILES, $EMAILUSERS;
if (!empty($values['emailusers'])) {
$EMAILUSERS = true;
}
require_once('file.php');
require_once(get_config('docroot') . 'import/lib.php');
......@@ -205,10 +212,7 @@ function import_next_user($filename, $username, $authinstance) {
return;
}
// If the username is already taken, append something to the end
while (get_record('usr', 'username', $username)) {
$username .= "_";
}
$username = get_new_username($username, 200);
$user = (object)array(
'authinstance' => $authinstance,
......@@ -251,7 +255,7 @@ function import_next_user($filename, $username, $authinstance) {
unset($record, $tr);
try {
$importer->process();
log_info("Imported user account $user->id from Leap2A file, see" . $importer->get('logfile') . 'for a full log');
log_info("Imported user account $user->id from Leap2A file, see " . $importer->get('logfile') . ' for a full log');
}
catch (ImportException $e) {
log_info("Leap2A import failed: " . $e->getMessage());
......@@ -288,14 +292,19 @@ function finish_import() {
if ($EMAILUSERS && $ADDEDUSERS) {
foreach ($ADDEDUSERS as $user) {
$noemailusers = array();
try {
email_user($user, null, get_string('accountcreated', 'mahara', get_config('sitename')),
get_string('accountcreatedchangepasswordtext', 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->clearpasswd, get_config('wwwroot'), get_config('sitename')),
get_string('accountcreatedchangepasswordhtml', 'mahara', $user->firstname, get_config('wwwroot'), get_config('sitename'), $user->username, $user->clearpasswd, get_config('wwwroot'), get_config('wwwroot'), get_config('sitename'))
);
if ($user->email) {
try {
email_user($user, null, get_string('accountcreated', 'mahara', get_config('sitename')),
get_string('accountcreatedchangepasswordtext', 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->clearpasswd, get_config('wwwroot'), get_config('sitename')),
get_string('accountcreatedchangepasswordhtml', 'mahara', $user->firstname, get_config('wwwroot'), get_config('sitename'), $user->username, $user->clearpasswd, get_config('wwwroot'), get_config('wwwroot'), get_config('sitename'))
);
}
catch (EmailException $e) {
log_info($e->getMessage());
$noemailusers[] = $user;
}
}
catch (EmailException $e) {
log_info($e->getMessage());
else {
$noemailusers[] = $user;
}
}
......
......@@ -533,6 +533,7 @@ class LeapImportInternal extends LeapImportArtefactPlugin {
/**
* Find and update duplicates with imported persondata
* TODO: Refactor this to combine it with import_persondata()
* NB: This function should only be called when importing one single Leap2A file
*/
private static function add_import_entry_request_persondata(PluginImportLeap $importer, $persondataid, SimpleXMLElement $item, array $leapattributes) {
$field = $leapattributes['field'];
......
......@@ -1739,10 +1739,6 @@ class PluginImportLeap extends PluginImport {
}
public function get_entry_by_id($entryid) {
static $cache = array();
if (isset($cache[$entryid])) {
return $cache[$entryid];
}
// TODO: entryid injection? Probably not worth worrying about
$matches = $this->xml->xpath("//a:feed/a:entry/a:id[.='$entryid']/..");
// TODO: there had better be only one...
......
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