Skip to content
Snippets Groups Projects
Commit e9c99e7f authored by Jared Hancock's avatar Jared Hancock
Browse files

user: Import CSV in a single transaction (with auto rollback)

parent b8381709
No related branches found
No related tags found
No related merge requests found
...@@ -457,14 +457,22 @@ class User extends UserModel { ...@@ -457,14 +457,22 @@ class User extends UserModel {
$users[] = $data; $users[] = $data;
} }
db_autocommit(false);
$error = false;
foreach ($users as $u) { foreach ($users as $u) {
$vars = array_combine($keys, $u); $vars = array_combine($keys, $u);
if (!static::fromVars($vars)) if (!static::fromVars($vars)) {
return sprintf(__('Unable to import user: %s'), $error = sprintf(__('Unable to import user: %s'),
print_r($vars, true)); print_r($vars, true));
break;
}
} }
if ($error)
db_rollback();
db_autocommit(true);
return count($users); return $error ?: count($users);
} }
function importFromPost($stuff, $extra=array()) { function importFromPost($stuff, $extra=array()) {
......
...@@ -90,6 +90,12 @@ function db_autocommit($enable=true) { ...@@ -90,6 +90,12 @@ function db_autocommit($enable=true) {
return $__db->autocommit($enable); return $__db->autocommit($enable);
} }
function db_rollback() {
global $__db;
return $__db->rollback();
}
function db_close() { function db_close() {
global $__db; global $__db;
return @$__db->close(); return @$__db->close();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment