Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / differential / query / DifferentialHunkQuery.php
blob981c2b4782f741a1616064d6724e7016655fe96c
1 <?php
3 final class DifferentialHunkQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $changesets;
7 private $shouldAttachToChangesets;
9 public function withChangesets(array $changesets) {
10 assert_instances_of($changesets, 'DifferentialChangeset');
11 $this->changesets = $changesets;
12 return $this;
15 public function needAttachToChangesets($attach) {
16 $this->shouldAttachToChangesets = $attach;
17 return $this;
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());
45 if (!$changeset) {
46 unset($hunks[$key]);
48 $hunk->attachChangeset($changeset);
51 return $hunks;
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);
63 return $hunks;
66 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
67 $where = parent::buildWhereClauseParts($conn);
69 if (!$this->changesets) {
70 throw new Exception(
71 pht(
72 'You must load hunks via changesets, with %s!',
73 'withChangesets()'));
76 $where[] = qsprintf(
77 $conn,
78 'changesetID IN (%Ld)',
79 mpull($this->changesets, 'getID'));
81 return $where;
84 public function getQueryApplicationClass() {
85 return 'PhabricatorDifferentialApplication';
88 protected function getDefaultOrderVector() {
89 // TODO: Do we need this?
90 return array('-id');