Path: blob/master/src/applications/drydock/query/DrydockLogQuery.php
12256 views
<?php12final class DrydockLogQuery extends DrydockQuery {34private $ids;5private $blueprintPHIDs;6private $resourcePHIDs;7private $leasePHIDs;8private $operationPHIDs;910public function withIDs(array $ids) {11$this->ids = $ids;12return $this;13}1415public function withBlueprintPHIDs(array $phids) {16$this->blueprintPHIDs = $phids;17return $this;18}1920public function withResourcePHIDs(array $phids) {21$this->resourcePHIDs = $phids;22return $this;23}2425public function withLeasePHIDs(array $phids) {26$this->leasePHIDs = $phids;27return $this;28}2930public function withOperationPHIDs(array $phids) {31$this->operationPHIDs = $phids;32return $this;33}3435public function newResultObject() {36return new DrydockLog();37}3839protected function didFilterPage(array $logs) {40$blueprint_phids = array_filter(mpull($logs, 'getBlueprintPHID'));41if ($blueprint_phids) {42$blueprints = id(new DrydockBlueprintQuery())43->setParentQuery($this)44->setViewer($this->getViewer())45->withPHIDs($blueprint_phids)46->execute();47$blueprints = mpull($blueprints, null, 'getPHID');48} else {49$blueprints = array();50}5152foreach ($logs as $key => $log) {53$blueprint = null;54$blueprint_phid = $log->getBlueprintPHID();55if ($blueprint_phid) {56$blueprint = idx($blueprints, $blueprint_phid);57}58$log->attachBlueprint($blueprint);59}6061$resource_phids = array_filter(mpull($logs, 'getResourcePHID'));62if ($resource_phids) {63$resources = id(new DrydockResourceQuery())64->setParentQuery($this)65->setViewer($this->getViewer())66->withPHIDs($resource_phids)67->execute();68$resources = mpull($resources, null, 'getPHID');69} else {70$resources = array();71}7273foreach ($logs as $key => $log) {74$resource = null;75$resource_phid = $log->getResourcePHID();76if ($resource_phid) {77$resource = idx($resources, $resource_phid);78}79$log->attachResource($resource);80}8182$lease_phids = array_filter(mpull($logs, 'getLeasePHID'));83if ($lease_phids) {84$leases = id(new DrydockLeaseQuery())85->setParentQuery($this)86->setViewer($this->getViewer())87->withPHIDs($lease_phids)88->execute();89$leases = mpull($leases, null, 'getPHID');90} else {91$leases = array();92}9394foreach ($logs as $key => $log) {95$lease = null;96$lease_phid = $log->getLeasePHID();97if ($lease_phid) {98$lease = idx($leases, $lease_phid);99}100$log->attachLease($lease);101}102103$operation_phids = array_filter(mpull($logs, 'getOperationPHID'));104if ($operation_phids) {105$operations = id(new DrydockRepositoryOperationQuery())106->setParentQuery($this)107->setViewer($this->getViewer())108->withPHIDs($operation_phids)109->execute();110$operations = mpull($operations, null, 'getPHID');111} else {112$operations = array();113}114115foreach ($logs as $key => $log) {116$operation = null;117$operation_phid = $log->getOperationPHID();118if ($operation_phid) {119$operation = idx($operations, $operation_phid);120}121$log->attachOperation($operation);122}123124return $logs;125}126127protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {128$where = parent::buildWhereClauseParts($conn);129130if ($this->ids !== null) {131$where[] = qsprintf(132$conn,133'id IN (%Ls)',134$this->ids);135}136137if ($this->blueprintPHIDs !== null) {138$where[] = qsprintf(139$conn,140'blueprintPHID IN (%Ls)',141$this->blueprintPHIDs);142}143144if ($this->resourcePHIDs !== null) {145$where[] = qsprintf(146$conn,147'resourcePHID IN (%Ls)',148$this->resourcePHIDs);149}150151if ($this->leasePHIDs !== null) {152$where[] = qsprintf(153$conn,154'leasePHID IN (%Ls)',155$this->leasePHIDs);156}157158if ($this->operationPHIDs !== null) {159$where[] = qsprintf(160$conn,161'operationPHID IN (%Ls)',162$this->operationPHIDs);163}164165return $where;166}167168}169170171