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 @@ -477,6 +477,7 @@ 'DifferentialChangesetParserTestCase' => 'applications/differential/parser/__tests__/DifferentialChangesetParserTestCase.php', 'DifferentialChangesetQuery' => 'applications/differential/query/DifferentialChangesetQuery.php', 'DifferentialChangesetRenderer' => 'applications/differential/render/DifferentialChangesetRenderer.php', + 'DifferentialChangesetSearchConduitAPIMethod' => 'applications/differential/conduit/DifferentialChangesetSearchConduitAPIMethod.php', 'DifferentialChangesetSearchEngine' => 'applications/differential/query/DifferentialChangesetSearchEngine.php', 'DifferentialChangesetTestRenderer' => 'applications/differential/render/DifferentialChangesetTestRenderer.php', 'DifferentialChangesetTwoUpRenderer' => 'applications/differential/render/DifferentialChangesetTwoUpRenderer.php', @@ -6533,6 +6534,7 @@ 'DifferentialDAO', 'PhabricatorPolicyInterface', 'PhabricatorDestructibleInterface', + 'PhabricatorConduitResultInterface', ), 'DifferentialChangesetDetailView' => 'AphrontView', 'DifferentialChangesetEngine' => 'Phobject', @@ -6547,6 +6549,7 @@ 'DifferentialChangesetParserTestCase' => 'PhabricatorTestCase', 'DifferentialChangesetQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'DifferentialChangesetRenderer' => 'Phobject', + 'DifferentialChangesetSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'DifferentialChangesetSearchEngine' => 'PhabricatorApplicationSearchEngine', 'DifferentialChangesetTestRenderer' => 'DifferentialChangesetRenderer', 'DifferentialChangesetTwoUpRenderer' => 'DifferentialChangesetHTMLRenderer', diff --git a/src/applications/differential/conduit/DifferentialChangesetSearchConduitAPIMethod.php b/src/applications/differential/conduit/DifferentialChangesetSearchConduitAPIMethod.php new file mode 100644 --- /dev/null +++ b/src/applications/differential/conduit/DifferentialChangesetSearchConduitAPIMethod.php @@ -0,0 +1,18 @@ +phids = $phids; + return $this; + } + public function withDiffs(array $diffs) { assert_instances_of($diffs, 'DifferentialDiff'); $this->diffs = $diffs; return $this; } + public function withDiffPHIDs(array $phids) { + $this->diffPHIDs = $phids; + return $this; + } + public function needAttachToDiffs($attach) { $this->needAttachToDiffs = $attach; return $this; @@ -134,6 +147,31 @@ $this->ids); } + if ($this->phids !== null) { + $where[] = qsprintf( + $conn, + 'phid IN (%Ls)', + $this->phids); + } + + if ($this->diffPHIDs !== null) { + $diff_ids = queryfx_all( + $conn, + 'SELECT id FROM %R WHERE phid IN (%Ls)', + new DifferentialDiff(), + $this->diffPHIDs); + $diff_ids = ipull($diff_ids, 'id', null); + + if (!$diff_ids) { + throw new PhabricatorEmptyQueryException(); + } + + $where[] = qsprintf( + $conn, + 'diffID IN (%Ld)', + $diff_ids); + } + return $where; } diff --git a/src/applications/differential/query/DifferentialChangesetSearchEngine.php b/src/applications/differential/query/DifferentialChangesetSearchEngine.php --- a/src/applications/differential/query/DifferentialChangesetSearchEngine.php +++ b/src/applications/differential/query/DifferentialChangesetSearchEngine.php @@ -38,11 +38,23 @@ protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); + + if ($map['diffPHIDs']) { + $query->withDiffPHIDs($map['diffPHIDs']); + } + return $query; } protected function buildCustomSearchFields() { - return array(); + return array( + id(new PhabricatorPHIDsSearchField()) + ->setLabel(pht('Diffs')) + ->setKey('diffPHIDs') + ->setAliases(array('diff', 'diffs', 'diffPHID')) + ->setDescription( + pht('Find changesets attached to a particular diff.')), + ); } protected function getURI($path) { diff --git a/src/applications/differential/storage/DifferentialChangeset.php b/src/applications/differential/storage/DifferentialChangeset.php --- a/src/applications/differential/storage/DifferentialChangeset.php +++ b/src/applications/differential/storage/DifferentialChangeset.php @@ -4,7 +4,8 @@ extends DifferentialDAO implements PhabricatorPolicyInterface, - PhabricatorDestructibleInterface { + PhabricatorDestructibleInterface, + PhabricatorConduitResultInterface { protected $diffID; protected $oldFile; @@ -735,5 +736,49 @@ $this->saveTransaction(); } +/* -( PhabricatorConduitResultInterface )---------------------------------- */ + + public function getFieldSpecificationsForConduit() { + return array( + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('diffPHID') + ->setType('phid') + ->setDescription(pht('The diff the changeset is attached to.')), + ); + } + + public function getFieldValuesForConduit() { + $diff = $this->getDiff(); + + $repository = null; + if ($diff) { + $revision = $diff->getRevision(); + if ($revision) { + $repository = $revision->getRepository(); + } + } + + $absolute_path = $this->getAbsoluteRepositoryPath($repository, $diff); + if (strlen($absolute_path)) { + $absolute_path = base64_encode($absolute_path); + } else { + $absolute_path = null; + } + + $display_path = $this->getDisplayFilename(); + + return array( + 'diffPHID' => $diff->getPHID(), + 'path' => array( + 'displayPath' => $display_path, + 'absolutePath.base64' => $absolute_path, + ), + ); + } + + public function getConduitSearchAttachments() { + return array(); + } + }