Commit 7f231697 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add a maximum number of users for csv files (bug #823048)

This allows $cfg->maxusercsvlines to be specified in config.php to
stop admins and institutional admins from uploading large csv files.
This is potentially useful on large multi-user sites.

And until such time as we can reduce the amount of memory used by the
create_user function, setting this option will provide the user with
some feedback on csv upload failure (because we can't easily trap the
php out-of-memory error).

See also bug #548042.

This commit also adds a call to set_time_limit() after processing each
user, so that the script doesn't fail due to php's max. execution

Change-Id: I662231288c7d0c6e70602c548123f12c63427a97
Signed-off-by: default avatarRichard Mansfield <>
parent c7522fec
......@@ -166,6 +166,10 @@ $form = array(
if ($maxcsvlines = get_config('maxusercsvlines')) {
$form['elements']['file']['description'] .= ' ' . get_string('csvmaxusersdescription', 'admin', get_string('nusers', 'mahara', $maxcsvlines));
if (!($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride'))) {
......@@ -252,6 +256,12 @@ function uploadcsv_validate(Pieform $form, $values) {
$remoteusers = array();
$maxcsvlines = get_config('maxusercsvlines');
if ($maxcsvlines && $maxcsvlines < count($csvdata->data)) {
$form->set_error('file', get_string('uploadcsverrortoomanyusers', 'admin', get_string('nusers', 'mahara', $maxcsvlines)));
foreach ($csvdata->data as $key => $line) {
// If headers exists, increment i = key + 2 for actual line number
$i = ($csvusers->get('headerExists')) ? ($key + 2) : ($key + 1);
......@@ -543,6 +553,7 @@ function uploadcsv_submit(Pieform $form, $values) {
log_debug('updated user ' . $user->username . ' (' . implode(', ', array_keys($updated)) . ')');
......@@ -438,7 +438,8 @@ $string['forceuserstochangepassword'] = 'Force password change?';
$string['forceuserstochangepassworddescription'] = 'Whether users should be forced to change their password when they log in for the first time';
$string['uploadcsvinstitution'] = 'The institution and authentication method for the new users';
$string['configureauthplugin'] = 'You must configure an authentication plugin before you can add users';
$string['csvfiledescription'] = 'The file containing users to add';
$string['csvfiledescription'] = 'The file containing users to add.';
$string['csvmaxusersdescription'] = 'This file should not contain more than %s.';
$string['groupcsvfiledescription'] = 'The file containing groups to add';
$string['groupmemberscsvfiledescription'] = 'The file containing group members to update';
$string['csverroremptyfile'] = 'The csv file is empty.';
......@@ -481,6 +482,7 @@ $string['uploadcsvpagedescription2institutionaladmin'] = '<p>You may use this fa
<p>Your CSV file may include any other profile fields as you require. The full list of fields is:</p>
$string['uploadcsverrortoomanyusers'] = 'You have too many lines in your csv file. Your file should not contain more than %s.';
$string['uploadgroupcsverrorgroupnamealreadyexists'] = 'Error on line %s of your file: The groupname "%s" already exists';
$string['uploadgroupcsverrorinvalidshortname'] = 'Error on line %s of your file: The shortname "%s" is invalid';
$string['uploadgroupcsverrorinvalidgrouptype'] = 'Error on line %s of your file: The grouptype "%s" is invalid';
Supports Markdown
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