3 final class DifferentialHunkQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery
{
7 private $shouldAttachToChangesets;
9 public function withChangesets(array $changesets) {
10 assert_instances_of($changesets, 'DifferentialChangeset');
11 $this->changesets
= $changesets;
15 public function needAttachToChangesets($attach) {
16 $this->shouldAttachToChangesets
= $attach;
20 protected function willExecute() {
21 // If we fail to load any hunks at all (for example, because all of
22 // the requested changesets are directories or empty files and have no
23 // hunks) we'll never call didFilterPage(), and thus never have an
24 // opportunity to attach hunks. Attach empty hunk lists now so that we
25 // end up with the right result.
26 if ($this->shouldAttachToChangesets
) {
27 foreach ($this->changesets
as $changeset) {
28 $changeset->attachHunks(array());
33 public function newResultObject() {
34 return new DifferentialHunk();
37 protected function loadPage() {
38 return $this->loadStandardPage($this->newResultObject());
41 protected function willFilterPage(array $hunks) {
42 $changesets = mpull($this->changesets
, null, 'getID');
43 foreach ($hunks as $key => $hunk) {
44 $changeset = idx($changesets, $hunk->getChangesetID());
48 $hunk->attachChangeset($changeset);
54 protected function didFilterPage(array $hunks) {
55 if ($this->shouldAttachToChangesets
) {
56 $hunk_groups = mgroup($hunks, 'getChangesetID');
57 foreach ($this->changesets
as $changeset) {
58 $hunks = idx($hunk_groups, $changeset->getID(), array());
59 $changeset->attachHunks($hunks);
66 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
67 $where = parent
::buildWhereClauseParts($conn);
69 if (!$this->changesets
) {
72 'You must load hunks via changesets, with %s!',
78 'changesetID IN (%Ld)',
79 mpull($this->changesets
, 'getID'));
84 public function getQueryApplicationClass() {
85 return 'PhabricatorDifferentialApplication';
88 protected function getDefaultOrderVector() {
89 // TODO: Do we need this?