Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/query/HarbormasterBuildableQuery.php
<?php | <?php | ||||
final class HarbormasterBuildableQuery | final class HarbormasterBuildableQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | private $ids; | ||||
private $phids; | private $phids; | ||||
private $buildablePHIDs; | private $buildablePHIDs; | ||||
private $containerPHIDs; | private $containerPHIDs; | ||||
private $manualBuildables; | private $manualBuildables; | ||||
private $needContainerObjects; | private $needContainerObjects; | ||||
private $needContainerHandles; | private $needContainerHandles; | ||||
private $needBuildableHandles; | private $needBuildableHandles; | ||||
private $needBuilds; | private $needBuilds; | ||||
private $needTargets; | |||||
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; | ||||
Show All 30 Lines | public function needBuildableHandles($need) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needBuilds($need) { | public function needBuilds($need) { | ||||
$this->needBuilds = $need; | $this->needBuilds = $need; | ||||
return $this; | return $this; | ||||
} | } | ||||
protected function loadPage() { | public function needTargets($need) { | ||||
$table = new HarbormasterBuildable(); | $this->needTargets = $need; | ||||
$conn_r = $table->establishConnection('r'); | return $this; | ||||
} | |||||
$data = queryfx_all( | public function newResultObject() { | ||||
$conn_r, | return new HarbormasterBuildable(); | ||||
'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 loadPage() { | ||||
return $this->loadStandardPage($this->newResultObject()); | |||||
} | } | ||||
protected function willFilterPage(array $page) { | protected function willFilterPage(array $page) { | ||||
$buildables = array(); | $buildables = array(); | ||||
$buildable_phids = array_filter(mpull($page, 'getBuildablePHID')); | $buildable_phids = array_filter(mpull($page, 'getBuildablePHID')); | ||||
if ($buildable_phids) { | if ($buildable_phids) { | ||||
$buildables = id(new PhabricatorObjectQuery()) | $buildables = id(new PhabricatorObjectQuery()) | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | if ($this->needBuildableHandles) { | ||||
} | } | ||||
foreach ($page as $key => $buildable) { | foreach ($page as $key => $buildable) { | ||||
$handle_phid = $buildable->getBuildablePHID(); | $handle_phid = $buildable->getBuildablePHID(); | ||||
$buildable->attachBuildableHandle(idx($handles, $handle_phid)); | $buildable->attachBuildableHandle(idx($handles, $handle_phid)); | ||||
} | } | ||||
} | } | ||||
if ($this->needBuilds) { | if ($this->needBuilds || $this->needTargets) { | ||||
$builds = id(new HarbormasterBuildQuery()) | $builds = id(new HarbormasterBuildQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->setParentQuery($this) | ->setParentQuery($this) | ||||
->withBuildablePHIDs(mpull($page, 'getPHID')) | ->withBuildablePHIDs(mpull($page, 'getPHID')) | ||||
->needBuildTargets($this->needTargets) | |||||
->execute(); | ->execute(); | ||||
$builds = mgroup($builds, 'getBuildablePHID'); | $builds = mgroup($builds, 'getBuildablePHID'); | ||||
foreach ($page as $key => $buildable) { | foreach ($page as $key => $buildable) { | ||||
$buildable->attachBuilds(idx($builds, $buildable->getPHID(), array())); | $buildable->attachBuilds(idx($builds, $buildable->getPHID(), array())); | ||||
} | } | ||||
} | } | ||||
return $page; | return $page; | ||||
} | } | ||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
$where = array(); | $where = parent::buildWhereClauseParts($conn); | ||||
if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'id IN (%Ld)', | 'id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
} | } | ||||
if ($this->phids !== null) { | if ($this->phids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'phid IN (%Ls)', | 'phid IN (%Ls)', | ||||
$this->phids); | $this->phids); | ||||
} | } | ||||
if ($this->buildablePHIDs !== null) { | if ($this->buildablePHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'buildablePHID IN (%Ls)', | 'buildablePHID IN (%Ls)', | ||||
$this->buildablePHIDs); | $this->buildablePHIDs); | ||||
} | } | ||||
if ($this->containerPHIDs !== null) { | if ($this->containerPHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'containerPHID in (%Ls)', | 'containerPHID in (%Ls)', | ||||
$this->containerPHIDs); | $this->containerPHIDs); | ||||
} | } | ||||
if ($this->manualBuildables !== null) { | if ($this->manualBuildables !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'isManualBuildable = %d', | 'isManualBuildable = %d', | ||||
(int)$this->manualBuildables); | (int)$this->manualBuildables); | ||||
} | } | ||||
$where[] = $this->buildPagingClause($conn_r); | return $where; | ||||
return $this->formatWhereClause($where); | |||||
} | } | ||||
public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
return 'PhabricatorHarbormasterApplication'; | return 'PhabricatorHarbormasterApplication'; | ||||
} | } | ||||
} | } |