2013-11-08 18:09:03 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class HarbormasterBuildLogQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $ids;
|
|
|
|
private $phids;
|
|
|
|
private $buildPHIDs;
|
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-12-05 12:01:12 +11:00
|
|
|
public function withBuildTargetPHIDs(array $build_target_phids) {
|
|
|
|
$this->buildTargetPHIDs = $build_target_phids;
|
2013-11-08 18:09:03 -08:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function loadPage() {
|
|
|
|
$table = new HarbormasterBuildLog();
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function willFilterPage(array $page) {
|
2013-12-05 12:01:12 +11:00
|
|
|
$build_targets = array();
|
2013-11-08 18:09:03 -08:00
|
|
|
|
2013-12-05 12:01:12 +11:00
|
|
|
$build_target_phids = array_filter(mpull($page, 'getBuildTargetPHID'));
|
|
|
|
if ($build_target_phids) {
|
|
|
|
$build_targets = id(new HarbormasterBuildTargetQuery())
|
2013-11-08 18:09:03 -08:00
|
|
|
->setViewer($this->getViewer())
|
2013-12-05 12:01:12 +11:00
|
|
|
->withPHIDs($build_target_phids)
|
2013-11-08 18:09:03 -08:00
|
|
|
->setParentQuery($this)
|
|
|
|
->execute();
|
2013-12-05 12:01:12 +11:00
|
|
|
$build_targets = mpull($build_targets, null, 'getPHID');
|
2013-11-08 18:09:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($page as $key => $build_log) {
|
2013-12-05 12:01:12 +11:00
|
|
|
$build_target_phid = $build_log->getBuildTargetPHID();
|
|
|
|
if (empty($build_targets[$build_target_phid])) {
|
2013-11-08 18:09:03 -08:00
|
|
|
unset($page[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-05 12:01:12 +11:00
|
|
|
$build_log->attachBuildTarget($build_targets[$build_target_phid]);
|
2013-11-08 18:09:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $page;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-12-05 12:01:12 +11:00
|
|
|
if ($this->buildTargetPHIDs) {
|
2013-11-08 18:09:03 -08:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2013-12-05 12:01:12 +11:00
|
|
|
'buildTargetPHID IN (%Ls)',
|
|
|
|
$this->buildTargetPHIDs);
|
2013-11-08 18:09:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getQueryApplicationClass() {
|
2014-07-23 10:03:09 +10:00
|
|
|
return 'PhabricatorHarbormasterApplication';
|
2013-11-08 18:09:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|