Page MenuHomePhabricator

D20886.id49789.diff
No OneTemporary

D20886.id49789.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -4652,6 +4652,7 @@
'PhabricatorSearchHovercardController' => 'applications/search/controller/PhabricatorSearchHovercardController.php',
'PhabricatorSearchIndexVersion' => 'applications/search/storage/PhabricatorSearchIndexVersion.php',
'PhabricatorSearchIndexVersionDestructionEngineExtension' => 'applications/search/engineextension/PhabricatorSearchIndexVersionDestructionEngineExtension.php',
+ 'PhabricatorSearchIntField' => 'applications/search/field/PhabricatorSearchIntField.php',
'PhabricatorSearchManagementIndexWorkflow' => 'applications/search/management/PhabricatorSearchManagementIndexWorkflow.php',
'PhabricatorSearchManagementInitWorkflow' => 'applications/search/management/PhabricatorSearchManagementInitWorkflow.php',
'PhabricatorSearchManagementNgramsWorkflow' => 'applications/search/management/PhabricatorSearchManagementNgramsWorkflow.php',
@@ -11273,6 +11274,7 @@
'PhabricatorSearchHovercardController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchIndexVersion' => 'PhabricatorSearchDAO',
'PhabricatorSearchIndexVersionDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
+ 'PhabricatorSearchIntField' => 'PhabricatorSearchField',
'PhabricatorSearchManagementIndexWorkflow' => 'PhabricatorSearchManagementWorkflow',
'PhabricatorSearchManagementInitWorkflow' => 'PhabricatorSearchManagementWorkflow',
'PhabricatorSearchManagementNgramsWorkflow' => 'PhabricatorSearchManagementWorkflow',
diff --git a/src/applications/project/query/PhabricatorProjectSearchEngine.php b/src/applications/project/query/PhabricatorProjectSearchEngine.php
--- a/src/applications/project/query/PhabricatorProjectSearchEngine.php
+++ b/src/applications/project/query/PhabricatorProjectSearchEngine.php
@@ -65,6 +65,35 @@
pht(
'Pass true to find only milestones, or false to omit '.
'milestones.')),
+ id(new PhabricatorSearchThreeStateField())
+ ->setLabel(pht('Root Projects'))
+ ->setKey('isRoot')
+ ->setOptions(
+ pht('(Show All)'),
+ pht('Show Only Root Projects'),
+ pht('Hide Root Projects'))
+ ->setDescription(
+ pht(
+ 'Pass true to find only root projects, or false to omit '.
+ 'root projects.')),
+ id(new PhabricatorSearchIntField())
+ ->setLabel(pht('Minimum Depth'))
+ ->setKey('minDepth')
+ ->setIsHidden(true)
+ ->setDescription(
+ pht(
+ 'Find projects with a given minimum depth. Root projects '.
+ 'have depth 0, their immediate children have depth 1, and '.
+ 'so on.')),
+ id(new PhabricatorSearchIntField())
+ ->setLabel(pht('Maximum Depth'))
+ ->setKey('maxDepth')
+ ->setIsHidden(true)
+ ->setDescription(
+ pht(
+ 'Find projects with a given maximum depth. Root projects '.
+ 'have depth 0, their immediate children have depth 1, and '.
+ 'so on.')),
id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Subtypes'))
->setKey('subtypes')
@@ -137,6 +166,42 @@
$query->withIsMilestone($map['isMilestone']);
}
+ $min_depth = $map['minDepth'];
+ $max_depth = $map['maxDepth'];
+
+ if ($min_depth !== null || $max_depth !== null) {
+ if ($min_depth !== null && $max_depth !== null) {
+ if ($min_depth > $max_depth) {
+ throw new Exception(
+ pht(
+ 'Search constraint "minDepth" must be no larger than '.
+ 'search constraint "maxDepth".'));
+ }
+ }
+ }
+
+ if ($map['isRoot'] !== null) {
+ if ($map['isRoot']) {
+ if ($max_depth === null) {
+ $max_depth = 0;
+ } else {
+ $max_depth = min(0, $max_depth);
+ }
+
+ $query->withDepthBetween(null, 0);
+ } else {
+ if ($min_depth === null) {
+ $min_depth = 1;
+ } else {
+ $min_depth = max($min_depth, 1);
+ }
+ }
+ }
+
+ if ($min_depth !== null || $max_depth !== null) {
+ $query->withDepthBetween($min_depth, $max_depth);
+ }
+
if ($map['parentPHIDs']) {
$query->withParentProjectPHIDs($map['parentPHIDs']);
}
diff --git a/src/applications/search/field/PhabricatorSearchIntField.php b/src/applications/search/field/PhabricatorSearchIntField.php
new file mode 100644
--- /dev/null
+++ b/src/applications/search/field/PhabricatorSearchIntField.php
@@ -0,0 +1,22 @@
+<?php
+
+final class PhabricatorSearchIntField
+ extends PhabricatorSearchField {
+
+ protected function getDefaultValue() {
+ return null;
+ }
+
+ protected function getValueFromRequest(AphrontRequest $request, $key) {
+ return $request->getInt($key);
+ }
+
+ protected function newControl() {
+ return new AphrontFormTextControl();
+ }
+
+ protected function newConduitParameterType() {
+ return new ConduitIntParameterType();
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Mar 17, 5:55 AM (6 d, 7 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7378091
Default Alt Text
D20886.id49789.diff (5 KB)

Event Timeline