mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 02:02:41 +01:00
86c399b657
Summary: Ref T5655. Some discussion in D9839. Generally speaking, `Phabricator{$name}Application` is clearer than `PhabricatorApplication{$name}`. Test Plan: # Pinned and uninstalled some applications. # Applied patch and performed migrations. # Verified that the pinned applications were still pinned and that the uninstalled applications were still uninstalled. # Performed a sanity check on the database contents. Reviewers: btrahan, epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: hach-que, epriestley, Korvin Maniphest Tasks: T5655 Differential Revision: https://secure.phabricator.com/D9982
86 lines
2 KiB
PHP
86 lines
2 KiB
PHP
<?php
|
|
|
|
final class PhabricatorOwnersPackageQuery
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
private $phids;
|
|
private $ownerPHIDs;
|
|
|
|
/**
|
|
* Owners are direct owners, and members of owning projects.
|
|
*/
|
|
public function withOwnerPHIDs(array $phids) {
|
|
$this->ownerPHIDs = $phids;
|
|
return $this;
|
|
}
|
|
|
|
public function withPHIDs(array $phids) {
|
|
$this->phids = $phids;
|
|
return $this;
|
|
}
|
|
|
|
protected function loadPage() {
|
|
$table = new PhabricatorOwnersPackage();
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
$data = queryfx_all(
|
|
$conn_r,
|
|
'SELECT p.* FROM %T p %Q %Q %Q %Q',
|
|
$table->getTableName(),
|
|
$this->buildJoinClause($conn_r),
|
|
$this->buildWhereClause($conn_r),
|
|
$this->buildOrderClause($conn_r),
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
return $table->loadAllFromArray($data);
|
|
}
|
|
|
|
private function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
|
$joins = array();
|
|
|
|
if ($this->ownerPHIDs) {
|
|
$joins[] = qsprintf(
|
|
$conn_r,
|
|
'JOIN %T o ON o.packageID = p.id',
|
|
id(new PhabricatorOwnersOwner())->getTableName());
|
|
}
|
|
|
|
return implode(' ', $joins);
|
|
}
|
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
$where = array();
|
|
|
|
if ($this->phids) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'p.phid IN (%Ls)',
|
|
$this->phids);
|
|
}
|
|
|
|
if ($this->ownerPHIDs) {
|
|
$base_phids = $this->ownerPHIDs;
|
|
|
|
$query = new PhabricatorProjectQuery();
|
|
$query->setViewer($this->getViewer());
|
|
$query->withMemberPHIDs($base_phids);
|
|
$projects = $query->execute();
|
|
$project_phids = mpull($projects, 'getPHID');
|
|
|
|
$all_phids = array_merge($base_phids, $project_phids);
|
|
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'o.userPHID IN (%Ls)',
|
|
$all_phids);
|
|
}
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
return $this->formatWhereClause($where);
|
|
}
|
|
|
|
public function getQueryApplicationClass() {
|
|
return 'PhabricatorOwnersApplication';
|
|
}
|
|
|
|
}
|