mirror of
https://we.phorge.it/source/phorge.git
synced 2024-09-22 18:28:47 +02:00
4f0f95f7b5
Summary: Ref T1049. Ref T2222. `DifferentialDiff` does not currently have a PHID, but we need it for Harbormaster and ApplicationTransactions. See some discussion in D7501. (I split the SQL into two sections so we can't fail in the middle. At some point, I'd like to do a pass on the migration stuff and get this happening automatically, and also simplify the PatchList.) Test Plan: - Ran `bin/storage upgrade`. - Checked for valid PHIDs in the database. - Used `phid.query` to look up a diff by PHID. - Created a new diff and verified it got a PHID. Reviewers: btrahan, hach-que Reviewed By: btrahan CC: aran, vrana Maniphest Tasks: T2222, T1049 Differential Revision: https://secure.phabricator.com/D7513
157 lines
3.6 KiB
PHP
157 lines
3.6 KiB
PHP
<?php
|
|
|
|
final class DifferentialDiffQuery
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
private $ids;
|
|
private $phids;
|
|
private $revisionIDs;
|
|
private $needChangesets = false;
|
|
private $needArcanistProjects = false;
|
|
|
|
public function withIDs(array $ids) {
|
|
$this->ids = $ids;
|
|
return $this;
|
|
}
|
|
|
|
public function withPHIDs(array $phids) {
|
|
$this->phids = $phids;
|
|
return $this;
|
|
}
|
|
|
|
public function withRevisionIDs(array $revision_ids) {
|
|
$this->revisionIDs = $revision_ids;
|
|
return $this;
|
|
}
|
|
|
|
public function needChangesets($bool) {
|
|
$this->needChangesets = $bool;
|
|
return $this;
|
|
}
|
|
|
|
public function needArcanistProjects($bool) {
|
|
$this->needArcanistProjects = $bool;
|
|
return $this;
|
|
}
|
|
|
|
public function loadPage() {
|
|
$table = new DifferentialDiff();
|
|
$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 $diffs) {
|
|
$revision_ids = array_filter(mpull($diffs, 'getRevisionID'));
|
|
|
|
$revisions = array();
|
|
if ($revision_ids) {
|
|
$revisions = id(new DifferentialRevisionQuery())
|
|
->setViewer($this->getViewer())
|
|
->withIDs($revision_ids)
|
|
->execute();
|
|
}
|
|
|
|
foreach ($diffs as $key => $diff) {
|
|
if (!$diff->getRevisionID()) {
|
|
$diff->attachRevision(null);
|
|
continue;
|
|
}
|
|
|
|
$revision = idx($revisions, $diff->getRevisionID());
|
|
if ($revision) {
|
|
$diff->attachRevision($revision);
|
|
continue;
|
|
}
|
|
|
|
unset($diffs[$key]);
|
|
}
|
|
|
|
|
|
if ($this->needChangesets) {
|
|
$this->loadChangesets($diffs);
|
|
}
|
|
|
|
if ($this->needArcanistProjects) {
|
|
$this->loadArcanistProjects($diffs);
|
|
}
|
|
|
|
return $diffs;
|
|
}
|
|
|
|
private function loadChangesets(array $diffs) {
|
|
foreach ($diffs as $diff) {
|
|
$diff->attachChangesets(
|
|
$diff->loadRelatives(new DifferentialChangeset(), 'diffID'));
|
|
foreach ($diff->getChangesets() as $changeset) {
|
|
$changeset->attachHunks(
|
|
$changeset->loadRelatives(new DifferentialHunk(), 'changesetID'));
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
$where = array();
|
|
|
|
if ($this->ids) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'id IN (%Ld)',
|
|
$this->ids);
|
|
}
|
|
|
|
if ($this->phids) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'phid IN (%Ls)',
|
|
$this->phids);
|
|
}
|
|
|
|
if ($this->revisionIDs) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'revisionID IN (%Ld)',
|
|
$this->revisionIDs);
|
|
}
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
return $this->formatWhereClause($where);
|
|
}
|
|
|
|
public function getQueryApplicationClass() {
|
|
return 'PhabricatorApplicationDifferential';
|
|
}
|
|
|
|
}
|