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

Fixup user import via cli

parent 9412b6c9
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,8 @@ class UserManager extends Module {
var $options = array(
'file' => array('-f', '--file', 'metavar'=>'path',
'help' => 'File or stream to process'),
'org' => array('-O', '--org', 'metavar'=>'ORGID',
'help' => 'Set the organization ID on import'),
);
var $stream;
......@@ -34,27 +36,19 @@ class UserManager extends Module {
elseif (!($this->stream = fopen($options['file'], 'rb')))
$this->fail("Unable to open input file [{$options['file']}]");
//Read the header (if any)
if (($data = fgetcsv($this->stream, 1000, ","))) {
if (Validator::is_email($data[1]))
fseek($this->stream, 0); // We don't have an header!
else;
// TODO: process the header here to figure out the columns
// for now we're assuming Name, Email
$extras = array();
if ($options['org']) {
if (!($org = Organization::lookup($options['org'])))
$this->fail($options['org'].': Unknown organization ID');
$extras['org_id'] = $options['org'];
}
while (($data = fgetcsv($this->stream, 1000, ",")) !== FALSE) {
if (!$data[0])
$this->stderr->write('Invalid data or format: Name
required');
elseif (!Validator::is_email($data[1]))
$this->stderr->write('Invalid data or format: Valid
email required');
elseif (!User::fromVars(array('name' => $data[0], 'email' => $data[1])))
$this->stderr->write('Unable to import user: '.print_r($data, true));
}
$status = User::importCsv($this->stream, $extras);
if (is_numeric($status))
$this->stderr->write("Successfully imported $status clients\n");
else
$this->fail($status);
break;
case 'export':
$stream = $options['file'] ?: 'php://stdout';
if (!($this->stream = fopen($stream, 'c')))
......
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