3
final class PhragmentQueryFragmentsConduitAPIMethod
4
extends PhragmentConduitAPIMethod {
6
public function getAPIMethodName() {
7
return 'phragment.queryfragments';
10
public function getMethodStatus() {
11
return self::METHOD_STATUS_UNSTABLE;
14
public function getMethodDescription() {
15
return pht('Query fragments based on their paths.');
18
public function defineParamTypes() {
20
'paths' => 'required list<string>',
24
public function defineReturnType() {
25
return 'nonempty dict';
28
public function defineErrorTypes() {
30
'ERR_BAD_FRAGMENT' => 'No such fragment exists',
34
protected function execute(ConduitAPIRequest $request) {
35
$paths = $request->getValue('paths');
37
$fragments = id(new PhragmentFragmentQuery())
38
->setViewer($request->getUser())
41
$fragments = mpull($fragments, null, 'getPath');
42
foreach ($paths as $path) {
43
if (!array_key_exists($path, $fragments)) {
44
throw new ConduitException('ERR_BAD_FRAGMENT');
49
foreach ($fragments as $path => $fragment) {
50
$mappings = $fragment->getFragmentMappings(
52
$fragment->getPath());
54
$file_phids = mpull(mpull($mappings, 'getLatestVersion'), 'getFilePHID');
55
$files = id(new PhabricatorFileQuery())
56
->setViewer($request->getUser())
57
->withPHIDs($file_phids)
59
$files = mpull($files, null, 'getPHID');
62
foreach ($mappings as $cpath => $child) {
63
$file_phid = $child->getLatestVersion()->getFilePHID();
64
if (!isset($files[$file_phid])) {
65
// Skip any files we don't have permission to access.
69
$file = $files[$file_phid];
70
$cpath = substr($child->getPath(), strlen($fragment->getPath()) + 1);
72
'phid' => $child->getPHID(),
73
'phidVersion' => $child->getLatestVersionPHID(),
75
'hash' => $file->getContentHash(),
76
'version' => $child->getLatestVersion()->getSequence(),
77
'uri' => $file->getViewURI(),
80
$results[$path] = $result;