Page MenuHomePhabricator

import_from_csv.php

Authored By
epriestley
Oct 22 2015, 12:52 AM
Size
1 KB
Referenced Files
None
Subscribers
None

import_from_csv.php

$ cat import.php
#!/usr/bin/env php
<?php
$root = '/Users/epriestley/dev/phabricator/';
require_once $root.'/scripts/__init_script__.php';
if ($argc !== 2) {
echo "usage: import.php <file>\n";
exit(1);
}
$lines = Filesystem::readFile($argv[1]);
$lines = trim($lines);
$lines = phutil_split_lines($lines, false);
foreach ($lines as $line) {
$parts = explode(',', $line);
if (count($parts) != 4) {
throw new Exception(
pht(
'Expected 4 parts: %s.',
$line));
}
list($realname, $email, $username, $avatar) = $parts;
$existing_user = id(new PhabricatorUser())->loadOneWhere(
'username = %s',
$username);
if ($existing_user) {
echo pht('Skipping existing user "%s".', $username)."\n";
continue;
}
$existing_email = id(new PhabricatorUserEmail())->loadOneWhere(
'address = %s',
$email);
if ($existing_email) {
echo pht('Skipping existing email "%s".', $email)."\n";
continue;
}
$user = id(new PhabricatorUser())
->setUsername($username)
->setRealname($realname)
->setIsApproved(1);
$email_object = id(new PhabricatorUserEmail())
->setAddress($email)
->setIsVerified(1);
id(new PhabricatorUserEditor())
->setActor($user)
->createNewUser($user, $email_object);
echo pht(
'Created user (username="%s", realname="%s", email="%s").',
$username,
$realname,
$email)."\n";
}

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/eb/5x/5u6khzz6msxe2y56
Default Alt Text
import_from_csv.php (1 KB)

Event Timeline