Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P1948
SwitchUserWorkflow.php
Active
Public
Actions
Authored by
michaeljs1990
on Feb 26 2016, 12:02 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F1130465: SwitchUserWorkflow.php
Feb 26 2016, 12:02 AM
2016-02-26 00:02:17 (UTC+0)
Subscribers
None
<?php
class
SwitchUserWorkflow
extends
IntegratorWorkflow
{
protected
function
didConstruct
()
{
$this
->
setName
(
'migrate-external-account'
)
->
setExamples
(
'**migrate-external-account** --username-old __olduser__ '
.
'--username-new __newuser__'
)
->
setSynopsis
(
pht
(
'Associate a new user account with an old one so history is not lost. '
.
'Only for external accounts.'
))
->
setArguments
([
[
'name'
=>
'username-old'
,
'param'
=>
'string'
,
'help'
=>
pht
(
'Old username that is no longer active.'
),
],
[
'name'
=>
'username-new'
,
'param'
=>
'string'
,
'help'
=>
pht
(
'New username for the user to use.'
),
],
]);
}
public
function
execute
(
PhutilArgumentParser
$args
)
{
$old_user
=
$this
->
requireArgument
(
$args
,
'username-old'
);
$new_user
=
$this
->
requireArgument
(
$args
,
'username-new'
);
$old_user_acct
=
id
(
new
PhabricatorExternalAccount
())
->
loadOneWhere
(
'accountId = %s'
,
$old_user
);
$new_user_acct
=
id
(
new
PhabricatorExternalAccount
())
->
loadOneWhere
(
'accountID = %s'
,
$new_user
);
$console
=
PhutilConsole
::
getConsole
();
if
(!
$old_user_acct
)
{
throw
$this
->
argumentUsageException
(
'%s does not exist.'
,
$old_user
);
}
if
(!
$new_user_acct
)
{
throw
$this
->
argumentUsageException
(
'%s does not exist.'
,
$new_user
);
}
// set the new user account to point to the old user account id
$old_user_phid
=
$old_user_acct
->
getUserPHID
();
$new_user_acct
->
setUserPHID
(
$old_user_phid
)
->
save
();
$console
->
writeOut
(
pht
(
"%s has been migrated to %s
\n
"
,
$old_user
,
$new_user
));
}
}
Event Timeline
michaeljs1990
created this paste.
Feb 26 2016, 12:02 AM
2016-02-26 00:02:17 (UTC+0)
michaeljs1990
mentioned this in
T10452: Provide more flexible management over disabling/changing ldap user accounts
.
Feb 26 2016, 12:04 AM
2016-02-26 00:04:57 (UTC+0)
Log In to Comment