@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class ProjectQueryConduitAPIMethod extends ProjectConduitAPIMethod {
4
5 public function getAPIMethodName() {
6 return 'project.query';
7 }
8
9 public function getMethodDescription() {
10 return pht('Execute searches for Projects.');
11 }
12
13 public function getMethodStatus() {
14 return self::METHOD_STATUS_FROZEN;
15 }
16
17 public function getMethodStatusDescription() {
18 return pht(
19 'This method is frozen and will eventually be deprecated. New code '.
20 'should use "project.search" instead.');
21 }
22
23 protected function defineParamTypes() {
24
25 $statuses = array(
26 PhabricatorProjectQuery::STATUS_ANY,
27 PhabricatorProjectQuery::STATUS_OPEN,
28 PhabricatorProjectQuery::STATUS_CLOSED,
29 PhabricatorProjectQuery::STATUS_ACTIVE,
30 PhabricatorProjectQuery::STATUS_ARCHIVED,
31 );
32
33 $status_const = $this->formatStringConstants($statuses);
34
35 return array(
36 'ids' => 'optional list<int>',
37 'names' => 'optional list<string>',
38 'phids' => 'optional list<phid>',
39 'slugs' => 'optional list<string>',
40 'icons' => 'optional list<string>',
41 'colors' => 'optional list<string>',
42 'status' => 'optional '.$status_const,
43
44 'members' => 'optional list<phid>',
45
46 'limit' => 'optional int',
47 'offset' => 'optional int',
48 );
49 }
50
51 protected function defineReturnType() {
52 return 'list';
53 }
54
55 protected function execute(ConduitAPIRequest $request) {
56 $query = new PhabricatorProjectQuery();
57 $query->setViewer($request->getUser());
58 $query->needMembers(true);
59 $query->needSlugs(true);
60
61 $ids = $request->getValue('ids');
62 if ($ids) {
63 $query->withIDs($ids);
64 }
65
66 $names = $request->getValue('names');
67 if ($names) {
68 $query->withNames($names);
69 }
70
71 $status = $request->getValue('status');
72 if ($status) {
73 $query->withStatus($status);
74 }
75
76 $phids = $request->getValue('phids');
77 if ($phids) {
78 $query->withPHIDs($phids);
79 }
80
81 $slugs = $request->getValue('slugs');
82 if ($slugs) {
83 $query->withSlugs($slugs);
84 }
85
86 $request->getValue('icons');
87 if ($request->getValue('icons')) {
88 $icons = array();
89 $query->withIcons($icons);
90 }
91
92 $colors = $request->getValue('colors');
93 if ($colors) {
94 $query->withColors($colors);
95 }
96
97 $members = $request->getValue('members');
98 if ($members) {
99 $query->withMemberPHIDs($members);
100 }
101
102 $limit = $request->getValue('limit');
103 if ($limit) {
104 $query->setLimit($limit);
105 }
106
107 $offset = $request->getValue('offset');
108 if ($offset) {
109 $query->setOffset($offset);
110 }
111
112 $pager = $this->newPager($request);
113 $results = $query->executeWithCursorPager($pager);
114 $projects = $this->buildProjectInfoDictionaries($results);
115
116 // TODO: This is pretty hideous.
117 $slug_map = array();
118 if ($slugs) {
119 foreach ($slugs as $slug) {
120 $normal = PhabricatorSlug::normalizeProjectSlug($slug);
121 foreach ($projects as $project) {
122 if (in_array($normal, $project['slugs'])) {
123 $slug_map[$slug] = $project['phid'];
124 }
125 }
126 }
127 }
128
129 $result = array(
130 'data' => $projects,
131 'slugMap' => $slug_map,
132 );
133
134 return $this->addPagerResults($result, $pager);
135 }
136
137}