Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/query/HarbormasterBuildQuery.php
| <?php | <?php | ||||
| final class HarbormasterBuildQuery | final class HarbormasterBuildQuery | ||||
| extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| private $ids; | private $ids; | ||||
| private $phids; | private $phids; | ||||
| private $buildStatuses; | private $buildStatuses; | ||||
| private $buildablePHIDs; | private $buildablePHIDs; | ||||
| private $buildPlanPHIDs; | private $buildPlanPHIDs; | ||||
| private $initiatorPHIDs; | private $initiatorPHIDs; | ||||
| private $needBuildTargets; | private $needBuildTargets; | ||||
| private $autobuilds; | |||||
| 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 15 Lines | public function withBuildPlanPHIDs(array $build_plan_phids) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withInitiatorPHIDs(array $initiator_phids) { | public function withInitiatorPHIDs(array $initiator_phids) { | ||||
| $this->initiatorPHIDs = $initiator_phids; | $this->initiatorPHIDs = $initiator_phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withAutobuilds($with_autobuilds) { | |||||
| $this->autobuilds = $with_autobuilds; | |||||
| return $this; | |||||
| } | |||||
| public function needBuildTargets($need_targets) { | public function needBuildTargets($need_targets) { | ||||
| $this->needBuildTargets = $need_targets; | $this->needBuildTargets = $need_targets; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function newResultObject() { | public function newResultObject() { | ||||
| return new HarbormasterBuild(); | return new HarbormasterBuild(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | final class HarbormasterBuildQuery | ||||
| } | } | ||||
| protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
| if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'id IN (%Ld)', | 'b.id IN (%Ld)', | ||||
| $this->ids); | $this->ids); | ||||
| } | } | ||||
| if ($this->phids !== null) { | if ($this->phids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'phid in (%Ls)', | 'b.phid in (%Ls)', | ||||
| $this->phids); | $this->phids); | ||||
| } | } | ||||
| if ($this->buildStatuses !== null) { | if ($this->buildStatuses !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'buildStatus in (%Ls)', | 'b.buildStatus in (%Ls)', | ||||
| $this->buildStatuses); | $this->buildStatuses); | ||||
| } | } | ||||
| if ($this->buildablePHIDs !== null) { | if ($this->buildablePHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'buildablePHID IN (%Ls)', | 'b.buildablePHID IN (%Ls)', | ||||
| $this->buildablePHIDs); | $this->buildablePHIDs); | ||||
| } | } | ||||
| if ($this->buildPlanPHIDs !== null) { | if ($this->buildPlanPHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'buildPlanPHID IN (%Ls)', | 'b.buildPlanPHID IN (%Ls)', | ||||
| $this->buildPlanPHIDs); | $this->buildPlanPHIDs); | ||||
| } | } | ||||
| if ($this->initiatorPHIDs !== null) { | if ($this->initiatorPHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'initiatorPHID IN (%Ls)', | 'b.initiatorPHID IN (%Ls)', | ||||
| $this->initiatorPHIDs); | $this->initiatorPHIDs); | ||||
| } | } | ||||
| if ($this->autobuilds !== null) { | |||||
| if ($this->autobuilds) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'p.planAutoKey IS NOT NULL'); | |||||
| } else { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'p.planAutoKey IS NULL'); | |||||
| } | |||||
| } | |||||
| return $where; | return $where; | ||||
| } | } | ||||
| protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | |||||
| $joins = parent::buildJoinClauseParts($conn); | |||||
| if ($this->shouldJoinPlanTable()) { | |||||
| $joins[] = qsprintf( | |||||
| $conn, | |||||
| 'JOIN %T p ON b.buildPlanPHID = p.phid', | |||||
| id(new HarbormasterBuildPlan())->getTableName()); | |||||
| } | |||||
| return $joins; | |||||
| } | |||||
| private function shouldJoinPlanTable() { | |||||
| if ($this->autobuilds !== null) { | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
| return 'PhabricatorHarbormasterApplication'; | return 'PhabricatorHarbormasterApplication'; | ||||
| } | } | ||||
| protected function getPrimaryTableAlias() { | |||||
| return 'b'; | |||||
| } | |||||
| } | } | ||||