3 final class DifferentialDiffQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery
{
9 private $revisionPHIDs;
13 private $needChangesets = false;
14 private $needProperties;
16 public function withIDs(array $ids) {
21 public function withPHIDs(array $phids) {
22 $this->phids
= $phids;
26 public function withRevisionIDs(array $revision_ids) {
27 $this->revisionIDs
= $revision_ids;
31 public function withRevisionPHIDs(array $revision_phids) {
32 $this->revisionPHIDs
= $revision_phids;
36 public function withCommitPHIDs(array $phids) {
37 $this->commitPHIDs
= $phids;
41 public function withHasRevision($has_revision) {
42 $this->hasRevision
= $has_revision;
46 public function needChangesets($bool) {
47 $this->needChangesets
= $bool;
51 public function needProperties($need_properties) {
52 $this->needProperties
= $need_properties;
56 public function newResultObject() {
57 return new DifferentialDiff();
60 protected function willFilterPage(array $diffs) {
61 $revision_ids = array_filter(mpull($diffs, 'getRevisionID'));
65 $revisions = id(new DifferentialRevisionQuery())
66 ->setViewer($this->getViewer())
67 ->withIDs($revision_ids)
71 foreach ($diffs as $key => $diff) {
72 if (!$diff->getRevisionID()) {
76 $revision = idx($revisions, $diff->getRevisionID());
78 $diff->attachRevision($revision);
86 if ($diffs && $this->needChangesets
) {
87 $diffs = $this->loadChangesets($diffs);
93 protected function didFilterPage(array $diffs) {
94 if ($this->needProperties
) {
95 $properties = id(new DifferentialDiffProperty())->loadAllWhere(
97 mpull($diffs, 'getID'));
99 $properties = mgroup($properties, 'getDiffID');
100 foreach ($diffs as $diff) {
101 $map = idx($properties, $diff->getID(), array());
102 $map = mpull($map, 'getData', 'getName');
103 $diff->attachDiffProperties($map);
110 private function loadChangesets(array $diffs) {
111 id(new DifferentialChangesetQuery())
112 ->setViewer($this->getViewer())
113 ->setParentQuery($this)
115 ->needAttachToDiffs(true)
122 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
123 $where = parent
::buildWhereClauseParts($conn);
125 if ($this->ids
!== null) {
132 if ($this->phids
!== null) {
139 if ($this->revisionIDs
!== null) {
142 'revisionID IN (%Ld)',
146 if ($this->commitPHIDs
!== null) {
149 'commitPHID IN (%Ls)',
153 if ($this->hasRevision
!== null) {
154 if ($this->hasRevision
) {
157 'revisionID IS NOT NULL');
161 'revisionID IS NULL');
165 if ($this->revisionPHIDs
!== null) {
166 $viewer = $this->getViewer();
168 $revisions = id(new DifferentialRevisionQuery())
170 ->setParentQuery($this)
171 ->withPHIDs($this->revisionPHIDs
)
173 $revision_ids = mpull($revisions, 'getID');
174 if (!$revision_ids) {
175 throw new PhabricatorEmptyQueryException();
180 'revisionID IN (%Ls)',
187 public function getQueryApplicationClass() {
188 return 'PhabricatorDifferentialApplication';