Path: blob/master/src/applications/drydock/query/DrydockLogSearchEngine.php
12256 views
<?php12final class DrydockLogSearchEngine extends PhabricatorApplicationSearchEngine {34private $blueprint;5private $resource;6private $lease;7private $operation;89public function setBlueprint(DrydockBlueprint $blueprint) {10$this->blueprint = $blueprint;11return $this;12}1314public function getBlueprint() {15return $this->blueprint;16}1718public function setResource(DrydockResource $resource) {19$this->resource = $resource;20return $this;21}2223public function getResource() {24return $this->resource;25}2627public function setLease(DrydockLease $lease) {28$this->lease = $lease;29return $this;30}3132public function getLease() {33return $this->lease;34}3536public function setOperation(DrydockRepositoryOperation $operation) {37$this->operation = $operation;38return $this;39}4041public function getOperation() {42return $this->operation;43}4445public function canUseInPanelContext() {46// Prevent use on Dashboard panels since all log queries currently need a47// parent object and these don't seem particularly useful in any case.48return false;49}5051public function getResultTypeDescription() {52return pht('Drydock Logs');53}5455public function getApplicationClassName() {56return 'PhabricatorDrydockApplication';57}5859public function newQuery() {60$query = new DrydockLogQuery();6162$blueprint = $this->getBlueprint();63if ($blueprint) {64$query->withBlueprintPHIDs(array($blueprint->getPHID()));65}6667$resource = $this->getResource();68if ($resource) {69$query->withResourcePHIDs(array($resource->getPHID()));70}7172$lease = $this->getLease();73if ($lease) {74$query->withLeasePHIDs(array($lease->getPHID()));75}7677$operation = $this->getOperation();78if ($operation) {79$query->withOperationPHIDs(array($operation->getPHID()));80}8182return $query;83}8485protected function buildQueryFromParameters(array $map) {86$query = $this->newQuery();8788return $query;89}9091protected function buildCustomSearchFields() {92return array();93}9495protected function getURI($path) {96$blueprint = $this->getBlueprint();97if ($blueprint) {98$id = $blueprint->getID();99return "/drydock/blueprint/{$id}/logs/{$path}";100}101102$resource = $this->getResource();103if ($resource) {104$id = $resource->getID();105return "/drydock/resource/{$id}/logs/{$path}";106}107108$lease = $this->getLease();109if ($lease) {110$id = $lease->getID();111return "/drydock/lease/{$id}/logs/{$path}";112}113114$operation = $this->getOperation();115if ($operation) {116$id = $operation->getID();117return "/drydock/operation/{$id}/logs/{$path}";118}119120throw new Exception(121pht(122'Search engine has no blueprint, resource, lease, or operation.'));123}124125protected function getBuiltinQueryNames() {126return array(127'all' => pht('All Logs'),128);129}130131public function buildSavedQueryFromBuiltin($query_key) {132$query = $this->newSavedQuery();133$query->setQueryKey($query_key);134135switch ($query_key) {136case 'all':137return $query;138}139140return parent::buildSavedQueryFromBuiltin($query_key);141}142143protected function renderResultList(144array $logs,145PhabricatorSavedQuery $query,146array $handles) {147148$list = id(new DrydockLogListView())149->setUser($this->requireViewer())150->setLogs($logs);151152$result = new PhabricatorApplicationSearchResultView();153$result->setTable($list);154155return $result;156}157158}159160161