Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101705909
AlmanacKeys.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
Wed, Feb 12, 22:30
Size
1 KB
Mime Type
text/x-php
Expires
Fri, Feb 14, 22:30 (2 d)
Engine
blob
Format
Raw Data
Handle
24209531
Attached To
rPH Phabricator
AlmanacKeys.php
View Options
<?php
final
class
AlmanacKeys
extends
Phobject
{
public
static
function
getKeyPath
(
$key_name
)
{
$root
=
dirname
(
phutil_get_library_root
(
'phabricator'
));
$keys
=
$root
.
'/conf/keys/'
;
return
$keys
.
ltrim
(
$key_name
,
'/'
);
}
public
static
function
getDeviceID
()
{
$device_id_path
=
self
::
getKeyPath
(
'device.id'
);
if
(
Filesystem
::
pathExists
(
$device_id_path
))
{
return
trim
(
Filesystem
::
readFile
(
$device_id_path
));
}
return
null
;
}
public
static
function
getLiveDevice
()
{
$device_id
=
self
::
getDeviceID
();
if
(!
$device_id
)
{
return
null
;
}
$cache
=
PhabricatorCaches
::
getRequestCache
();
$cache_key
=
'almanac.device.self'
;
$device
=
$cache
->
getKey
(
$cache_key
);
if
(!
$device
)
{
$viewer
=
PhabricatorUser
::
getOmnipotentUser
();
$device
=
id
(
new
AlmanacDeviceQuery
())
->
setViewer
(
$viewer
)
->
withNames
(
array
(
$device_id
))
->
executeOne
();
if
(!
$device
)
{
throw
new
Exception
(
pht
(
'This host has device ID "%s", but there is no corresponding '
.
'device record in Almanac.'
,
$device_id
));
}
$cache
->
setKey
(
$cache_key
,
$device
);
}
return
$device
;
}
}
Event Timeline
Log In to Comment