Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F903143
import_from_csv.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
epriestley
Oct 22 2015, 12:52 AM
2015-10-22 00:52:32 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
import_from_csv.php
View Options
$ 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
Details
Attached
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)
Attached To
Mode
P1872 import_from_csv.php
Attached
Detach File
Event Timeline
Log In to Comment