Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/util/AlmanacKeys.php
Show All 13 Lines | public static function getDeviceID() { | ||||
if (Filesystem::pathExists($device_id_path)) { | if (Filesystem::pathExists($device_id_path)) { | ||||
return trim(Filesystem::readFile($device_id_path)); | return trim(Filesystem::readFile($device_id_path)); | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public static function getLiveDevice() { | |||||
$device_id = self::getDeviceID(); | |||||
if (!$device_id) { | |||||
return null; | |||||
} | |||||
$cache = PhabricatorCaches::getRequestCache(); | |||||
$cache_key = 'almanac.device.id'; | |||||
$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; | |||||
} | |||||
} | } |