Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / phragment / conduit / PhragmentQueryFragmentsConduitAPIMethod.php
blob08a1bcba490dae50c51381fb3ddb47a8754a82f3
1 <?php
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 protected function defineParamTypes() {
19 return array(
20 'paths' => 'required list<string>',
24 protected function defineReturnType() {
25 return 'nonempty dict';
28 protected function defineErrorTypes() {
29 return array(
30 'ERR_BAD_FRAGMENT' => pht('No such fragment exists.'),
34 protected function execute(ConduitAPIRequest $request) {
35 $paths = $request->getValue('paths');
37 $fragments = id(new PhragmentFragmentQuery())
38 ->setViewer($request->getUser())
39 ->withPaths($paths)
40 ->execute();
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');
48 $results = array();
49 foreach ($fragments as $path => $fragment) {
50 $mappings = $fragment->getFragmentMappings(
51 $request->getUser(),
52 $fragment->getPath());
54 $file_phids = mpull(mpull($mappings, 'getLatestVersion'), 'getFilePHID');
55 $files = id(new PhabricatorFileQuery())
56 ->setViewer($request->getUser())
57 ->withPHIDs($file_phids)
58 ->execute();
59 $files = mpull($files, null, 'getPHID');
61 $result = array();
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.
66 continue;
69 $file = $files[$file_phid];
70 $cpath = substr($child->getPath(), strlen($fragment->getPath()) + 1);
71 $result[] = array(
72 'phid' => $child->getPHID(),
73 'phidVersion' => $child->getLatestVersionPHID(),
74 'path' => $cpath,
75 'hash' => $file->getContentHash(),
76 'version' => $child->getLatestVersion()->getSequence(),
77 'uri' => $file->getViewURI(),
80 $results[$path] = $result;
82 return $results;