Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/query/DifferentialDiffQuery.php
<?php | <?php | ||||
final class DifferentialDiffQuery | final class DifferentialDiffQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | private $ids; | ||||
private $phids; | private $phids; | ||||
private $revisionIDs; | private $revisionIDs; | ||||
private $needChangesets = false; | private $needChangesets = false; | ||||
private $needArcanistProjects = false; | |||||
public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
$this->ids = $ids; | $this->ids = $ids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
$this->phids = $phids; | $this->phids = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withRevisionIDs(array $revision_ids) { | public function withRevisionIDs(array $revision_ids) { | ||||
$this->revisionIDs = $revision_ids; | $this->revisionIDs = $revision_ids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needChangesets($bool) { | public function needChangesets($bool) { | ||||
$this->needChangesets = $bool; | $this->needChangesets = $bool; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needArcanistProjects($bool) { | |||||
$this->needArcanistProjects = $bool; | |||||
return $this; | |||||
} | |||||
protected function loadPage() { | protected function loadPage() { | ||||
$table = new DifferentialDiff(); | $table = new DifferentialDiff(); | ||||
$conn_r = $table->establishConnection('r'); | $conn_r = $table->establishConnection('r'); | ||||
$data = queryfx_all( | $data = queryfx_all( | ||||
$conn_r, | $conn_r, | ||||
'SELECT * FROM %T %Q %Q %Q', | 'SELECT * FROM %T %Q %Q %Q', | ||||
$table->getTableName(), | $table->getTableName(), | ||||
Show All 29 Lines | foreach ($diffs as $key => $diff) { | ||||
unset($diffs[$key]); | unset($diffs[$key]); | ||||
} | } | ||||
if ($diffs && $this->needChangesets) { | if ($diffs && $this->needChangesets) { | ||||
$diffs = $this->loadChangesets($diffs); | $diffs = $this->loadChangesets($diffs); | ||||
} | } | ||||
if ($diffs && $this->needArcanistProjects) { | |||||
$diffs = $this->loadArcanistProjects($diffs); | |||||
} | |||||
return $diffs; | return $diffs; | ||||
} | } | ||||
private function loadChangesets(array $diffs) { | private function loadChangesets(array $diffs) { | ||||
id(new DifferentialChangesetQuery()) | id(new DifferentialChangesetQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->setParentQuery($this) | ->setParentQuery($this) | ||||
->withDiffs($diffs) | ->withDiffs($diffs) | ||||
->needAttachToDiffs(true) | ->needAttachToDiffs(true) | ||||
->needHunks(true) | ->needHunks(true) | ||||
->execute(); | ->execute(); | ||||
return $diffs; | return $diffs; | ||||
} | } | ||||
private function loadArcanistProjects(array $diffs) { | |||||
$phids = array_filter(mpull($diffs, 'getArcanistProjectPHID')); | |||||
$projects = array(); | |||||
$project_map = array(); | |||||
if ($phids) { | |||||
$projects = id(new PhabricatorRepositoryArcanistProject()) | |||||
->loadAllWhere( | |||||
'phid IN (%Ls)', | |||||
$phids); | |||||
$project_map = mpull($projects, null, 'getPHID'); | |||||
} | |||||
foreach ($diffs as $diff) { | |||||
$project = null; | |||||
if ($diff->getArcanistProjectPHID()) { | |||||
$project = idx($project_map, $diff->getArcanistProjectPHID()); | |||||
} | |||||
$diff->attachArcanistProject($project); | |||||
} | |||||
return $diffs; | |||||
} | |||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | ||||
$where = array(); | $where = array(); | ||||
if ($this->ids) { | if ($this->ids) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn_r, | ||||
'id IN (%Ld)', | 'id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
Show All 25 Lines |