Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98198341
PhortuneController.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jan 10, 23:27
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Jan 12, 23:27 (2 d)
Engine
blob
Format
Raw Data
Handle
23529916
Attached To
rPH Phabricator
PhortuneController.php
View Options
<?php
abstract
class
PhortuneController
extends
PhabricatorController
{
protected
function
loadActiveAccount
(
PhabricatorUser
$user
)
{
$accounts
=
id
(
new
PhortuneAccountQuery
())
->
setViewer
(
$user
)
->
withMemberPHIDs
(
array
(
$user
->
getPHID
()))
->
execute
();
if
(!
$accounts
)
{
return
$this
->
createUserAccount
(
$user
);
}
else
if
(
count
(
$accounts
)
==
1
)
{
return
head
(
$accounts
);
}
else
{
throw
new
Exception
(
"TODO: No account selection yet."
);
}
}
protected
function
createUserAccount
(
PhabricatorUser
$user
)
{
$request
=
$this
->
getRequest
();
$xactions
=
array
();
$xactions
[]
=
id
(
new
PhortuneAccountTransaction
())
->
setTransactionType
(
PhortuneAccountTransaction
::
TYPE_NAME
)
->
setNewValue
(
pht
(
'Account (%s)'
,
$user
->
getUserName
()));
$xactions
[]
=
id
(
new
PhortuneAccountTransaction
())
->
setTransactionType
(
PhabricatorTransactions
::
TYPE_EDGE
)
->
setMetadataValue
(
'edge:type'
,
PhabricatorEdgeConfig
::
TYPE_ACCOUNT_HAS_MEMBER
)
->
setNewValue
(
array
(
'='
=>
array
(
$user
->
getPHID
()
=>
$user
->
getPHID
()),
));
$account
=
id
(
new
PhortuneAccount
())
->
attachMemberPHIDs
(
array
());
$editor
=
id
(
new
PhortuneAccountEditor
())
->
setActor
(
$user
)
->
setContentSourceFromRequest
(
$request
);
// We create an account for you the first time you visit Phortune.
$unguarded
=
AphrontWriteGuard
::
beginScopedUnguardedWrites
();
$editor
->
applyTransactions
(
$account
,
$xactions
);
unset
(
$unguarded
);
return
$account
;
}
}
Event Timeline
Log In to Comment