Path: blob/master/src/applications/differential/query/DifferentialHunkQuery.php
12256 views
<?php12final class DifferentialHunkQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45private $changesets;6private $shouldAttachToChangesets;78public function withChangesets(array $changesets) {9assert_instances_of($changesets, 'DifferentialChangeset');10$this->changesets = $changesets;11return $this;12}1314public function needAttachToChangesets($attach) {15$this->shouldAttachToChangesets = $attach;16return $this;17}1819protected function willExecute() {20// If we fail to load any hunks at all (for example, because all of21// the requested changesets are directories or empty files and have no22// hunks) we'll never call didFilterPage(), and thus never have an23// opportunity to attach hunks. Attach empty hunk lists now so that we24// end up with the right result.25if ($this->shouldAttachToChangesets) {26foreach ($this->changesets as $changeset) {27$changeset->attachHunks(array());28}29}30}3132public function newResultObject() {33return new DifferentialHunk();34}3536protected function willFilterPage(array $hunks) {37$changesets = mpull($this->changesets, null, 'getID');38foreach ($hunks as $key => $hunk) {39$changeset = idx($changesets, $hunk->getChangesetID());40if (!$changeset) {41unset($hunks[$key]);42}43$hunk->attachChangeset($changeset);44}4546return $hunks;47}4849protected function didFilterPage(array $hunks) {50if ($this->shouldAttachToChangesets) {51$hunk_groups = mgroup($hunks, 'getChangesetID');52foreach ($this->changesets as $changeset) {53$hunks = idx($hunk_groups, $changeset->getID(), array());54$changeset->attachHunks($hunks);55}56}5758return $hunks;59}6061protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {62$where = parent::buildWhereClauseParts($conn);6364if (!$this->changesets) {65throw new Exception(66pht(67'You must load hunks via changesets, with %s!',68'withChangesets()'));69}7071$where[] = qsprintf(72$conn,73'changesetID IN (%Ld)',74mpull($this->changesets, 'getID'));7576return $where;77}7879public function getQueryApplicationClass() {80return 'PhabricatorDifferentialApplication';81}8283protected function getDefaultOrderVector() {84// TODO: Do we need this?85return array('-id');86}8788}899091