mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-16 11:52:40 +01:00
88 lines
2.1 KiB
PHP
88 lines
2.1 KiB
PHP
|
<?php
|
||
|
|
||
|
final class DifferentialHunkQuery
|
||
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||
|
|
||
|
private $changesets;
|
||
|
private $shouldAttachToChangesets;
|
||
|
|
||
|
public function withChangesets(array $changesets) {
|
||
|
assert_instances_of($changesets, 'DifferentialChangeset');
|
||
|
$this->changesets = $changesets;
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
public function needAttachToChangesets($attach) {
|
||
|
$this->shouldAttachToChangesets = $attach;
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
public function loadPage() {
|
||
|
$table = new DifferentialHunk();
|
||
|
$conn_r = $table->establishConnection('r');
|
||
|
|
||
|
$data = queryfx_all(
|
||
|
$conn_r,
|
||
|
'SELECT * FROM %T %Q %Q %Q',
|
||
|
$table->getTableName(),
|
||
|
$this->buildWhereClause($conn_r),
|
||
|
$this->buildOrderClause($conn_r),
|
||
|
$this->buildLimitClause($conn_r));
|
||
|
|
||
|
return $table->loadAllFromArray($data);
|
||
|
}
|
||
|
|
||
|
public function willFilterPage(array $hunks) {
|
||
|
|
||
|
$changesets = mpull($this->changesets, null, 'getID');
|
||
|
foreach ($hunks as $key => $hunk) {
|
||
|
$changeset = idx($changesets, $hunk->getChangesetID());
|
||
|
if (!$changeset) {
|
||
|
unset($hunks[$key]);
|
||
|
}
|
||
|
$hunk->attachChangeset($changeset);
|
||
|
}
|
||
|
|
||
|
return $hunks;
|
||
|
}
|
||
|
|
||
|
public function didFilterPage(array $hunks) {
|
||
|
if ($this->shouldAttachToChangesets) {
|
||
|
$hunk_groups = mgroup($hunks, 'getChangesetID');
|
||
|
foreach ($this->changesets as $changeset) {
|
||
|
$hunks = idx($hunk_groups, $changeset->getID(), array());
|
||
|
$changeset->attachHunks($hunks);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $hunks;
|
||
|
}
|
||
|
|
||
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||
|
$where = array();
|
||
|
|
||
|
if (!$this->changesets) {
|
||
|
throw new Exception(
|
||
|
pht('You must load hunks via changesets, with withChangesets()!'));
|
||
|
}
|
||
|
|
||
|
$where[] = qsprintf(
|
||
|
$conn_r,
|
||
|
'changesetID IN (%Ld)',
|
||
|
mpull($this->changesets, 'getID'));
|
||
|
|
||
|
$where[] = $this->buildPagingClause($conn_r);
|
||
|
|
||
|
return $this->formatWhereClause($where);
|
||
|
}
|
||
|
|
||
|
public function getQueryApplicationClass() {
|
||
|
return 'PhabricatorApplicationDifferential';
|
||
|
}
|
||
|
|
||
|
protected function getReversePaging() {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
}
|