Path: blob/master/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php
12256 views
<?php12final class HarbormasterBuildTargetQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45private $ids;6private $phids;7private $buildPHIDs;8private $buildGenerations;9private $dateCreatedMin;10private $dateCreatedMax;11private $dateStartedMin;12private $dateStartedMax;13private $dateCompletedMin;14private $dateCompletedMax;15private $statuses;1617private $needBuildSteps;1819public function withIDs(array $ids) {20$this->ids = $ids;21return $this;22}2324public function withPHIDs(array $phids) {25$this->phids = $phids;26return $this;27}2829public function withBuildPHIDs(array $build_phids) {30$this->buildPHIDs = $build_phids;31return $this;32}3334public function withBuildGenerations(array $build_generations) {35$this->buildGenerations = $build_generations;36return $this;37}3839public function withDateCreatedBetween($min, $max) {40$this->dateCreatedMin = $min;41$this->dateCreatedMax = $max;42return $this;43}4445public function withDateStartedBetween($min, $max) {46$this->dateStartedMin = $min;47$this->dateStartedMax = $max;48return $this;49}5051public function withDateCompletedBetween($min, $max) {52$this->dateCompletedMin = $min;53$this->dateCompletedMax = $max;54return $this;55}5657public function withTargetStatuses(array $statuses) {58$this->statuses = $statuses;59return $this;60}6162public function needBuildSteps($need_build_steps) {63$this->needBuildSteps = $need_build_steps;64return $this;65}6667public function newResultObject() {68return new HarbormasterBuildTarget();69}7071protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {72$where = parent::buildWhereClauseParts($conn);7374if ($this->ids !== null) {75$where[] = qsprintf(76$conn,77'id IN (%Ld)',78$this->ids);79}8081if ($this->phids !== null) {82$where[] = qsprintf(83$conn,84'phid in (%Ls)',85$this->phids);86}8788if ($this->buildPHIDs !== null) {89$where[] = qsprintf(90$conn,91'buildPHID in (%Ls)',92$this->buildPHIDs);93}9495if ($this->buildGenerations !== null) {96$where[] = qsprintf(97$conn,98'buildGeneration in (%Ld)',99$this->buildGenerations);100}101102if ($this->dateCreatedMin !== null) {103$where[] = qsprintf(104$conn,105'dateCreated >= %d',106$this->dateCreatedMin);107}108109if ($this->dateCreatedMax !== null) {110$where[] = qsprintf(111$conn,112'dateCreated <= %d',113$this->dateCreatedMax);114}115116if ($this->dateStartedMin !== null) {117$where[] = qsprintf(118$conn,119'dateStarted >= %d',120$this->dateStartedMin);121}122123if ($this->dateStartedMax !== null) {124$where[] = qsprintf(125$conn,126'dateStarted <= %d',127$this->dateStartedMax);128}129130if ($this->dateCompletedMin !== null) {131$where[] = qsprintf(132$conn,133'dateCompleted >= %d',134$this->dateCompletedMin);135}136137if ($this->dateCompletedMax !== null) {138$where[] = qsprintf(139$conn,140'dateCompleted <= %d',141$this->dateCompletedMax);142}143144if ($this->statuses !== null) {145$where[] = qsprintf(146$conn,147'targetStatus IN (%Ls)',148$this->statuses);149}150151return $where;152}153154protected function didFilterPage(array $page) {155if ($this->needBuildSteps) {156$step_phids = array();157158foreach ($page as $target) {159$step_phids[] = $target->getBuildStepPHID();160}161162$steps = id(new HarbormasterBuildStepQuery())163->setViewer($this->getViewer())164->setParentQuery($this)165->withPHIDs($step_phids)166->execute();167168$steps = mpull($steps, null, 'getPHID');169170foreach ($page as $target) {171$target->attachBuildStep(172idx($steps, $target->getBuildStepPHID()));173}174}175176return $page;177}178179protected function willFilterPage(array $page) {180$builds = array();181182$build_phids = array_filter(mpull($page, 'getBuildPHID'));183if ($build_phids) {184$builds = id(new PhabricatorObjectQuery())185->setViewer($this->getViewer())186->withPHIDs($build_phids)187->setParentQuery($this)188->execute();189$builds = mpull($builds, null, 'getPHID');190}191192foreach ($page as $key => $build_target) {193$build_phid = $build_target->getBuildPHID();194if (empty($builds[$build_phid])) {195unset($page[$key]);196continue;197}198$build_target->attachBuild($builds[$build_phid]);199}200201return $page;202}203204public function getQueryApplicationClass() {205return 'PhabricatorHarbormasterApplication';206}207208}209210211