Path: blob/master/src/applications/drydock/query/DrydockRepositoryOperationQuery.php
12256 views
<?php12final class DrydockRepositoryOperationQuery extends DrydockQuery {34private $ids;5private $phids;6private $objectPHIDs;7private $repositoryPHIDs;8private $operationStates;9private $operationTypes;10private $isDismissed;11private $authorPHIDs;1213public function withIDs(array $ids) {14$this->ids = $ids;15return $this;16}1718public function withPHIDs(array $phids) {19$this->phids = $phids;20return $this;21}2223public function withObjectPHIDs(array $object_phids) {24$this->objectPHIDs = $object_phids;25return $this;26}2728public function withRepositoryPHIDs(array $repository_phids) {29$this->repositoryPHIDs = $repository_phids;30return $this;31}3233public function withOperationStates(array $states) {34$this->operationStates = $states;35return $this;36}3738public function withOperationTypes(array $types) {39$this->operationTypes = $types;40return $this;41}4243public function withIsDismissed($dismissed) {44$this->isDismissed = $dismissed;45return $this;46}4748public function withAuthorPHIDs(array $phids) {49$this->authorPHIDs = $phids;50return $this;51}5253public function newResultObject() {54return new DrydockRepositoryOperation();55}5657protected function willFilterPage(array $operations) {58$implementations = DrydockRepositoryOperationType::getAllOperationTypes();5960$viewer = $this->getViewer();6162foreach ($operations as $key => $operation) {63$impl = idx($implementations, $operation->getOperationType());64if (!$impl) {65$this->didRejectResult($operation);66unset($operations[$key]);67continue;68}69$impl = id(clone $impl)70->setViewer($viewer)71->setOperation($operation);7273$operation->attachImplementation($impl);74}7576$repository_phids = mpull($operations, 'getRepositoryPHID');77if ($repository_phids) {78$repositories = id(new PhabricatorRepositoryQuery())79->setViewer($this->getViewer())80->setParentQuery($this)81->withPHIDs($repository_phids)82->execute();83$repositories = mpull($repositories, null, 'getPHID');84} else {85$repositories = array();86}8788foreach ($operations as $key => $operation) {89$repository = idx($repositories, $operation->getRepositoryPHID());90if (!$repository) {91$this->didRejectResult($operation);92unset($operations[$key]);93continue;94}95$operation->attachRepository($repository);96}9798return $operations;99}100101protected function didFilterPage(array $operations) {102$object_phids = mpull($operations, 'getObjectPHID');103if ($object_phids) {104$objects = id(new PhabricatorObjectQuery())105->setViewer($this->getViewer())106->setParentQuery($this)107->withPHIDs($object_phids)108->execute();109$objects = mpull($objects, null, 'getPHID');110} else {111$objects = array();112}113114foreach ($operations as $key => $operation) {115$object = idx($objects, $operation->getObjectPHID());116$operation->attachObject($object);117}118119return $operations;120}121122protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {123$where = parent::buildWhereClauseParts($conn);124125if ($this->ids !== null) {126$where[] = qsprintf(127$conn,128'id IN (%Ld)',129$this->ids);130}131132if ($this->phids !== null) {133$where[] = qsprintf(134$conn,135'phid IN (%Ls)',136$this->phids);137}138139if ($this->objectPHIDs !== null) {140$where[] = qsprintf(141$conn,142'objectPHID IN (%Ls)',143$this->objectPHIDs);144}145146if ($this->repositoryPHIDs !== null) {147$where[] = qsprintf(148$conn,149'repositoryPHID IN (%Ls)',150$this->repositoryPHIDs);151}152153if ($this->operationStates !== null) {154$where[] = qsprintf(155$conn,156'operationState IN (%Ls)',157$this->operationStates);158}159160if ($this->operationTypes !== null) {161$where[] = qsprintf(162$conn,163'operationType IN (%Ls)',164$this->operationTypes);165}166167if ($this->isDismissed !== null) {168$where[] = qsprintf(169$conn,170'isDismissed = %d',171(int)$this->isDismissed);172}173174if ($this->authorPHIDs !== null) {175$where[] = qsprintf(176$conn,177'authorPHID IN (%Ls)',178$this->authorPHIDs);179}180181return $where;182}183184}185186187