@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 159 lines 3.6 kB view raw
1<?php 2 3final class DrydockLogSearchEngine extends PhabricatorApplicationSearchEngine { 4 5 private $blueprint; 6 private $resource; 7 private $lease; 8 private $operation; 9 10 public function setBlueprint(DrydockBlueprint $blueprint) { 11 $this->blueprint = $blueprint; 12 return $this; 13 } 14 15 public function getBlueprint() { 16 return $this->blueprint; 17 } 18 19 public function setResource(DrydockResource $resource) { 20 $this->resource = $resource; 21 return $this; 22 } 23 24 public function getResource() { 25 return $this->resource; 26 } 27 28 public function setLease(DrydockLease $lease) { 29 $this->lease = $lease; 30 return $this; 31 } 32 33 public function getLease() { 34 return $this->lease; 35 } 36 37 public function setOperation(DrydockRepositoryOperation $operation) { 38 $this->operation = $operation; 39 return $this; 40 } 41 42 public function getOperation() { 43 return $this->operation; 44 } 45 46 public function canUseInPanelContext() { 47 // Prevent use on Dashboard panels since all log queries currently need a 48 // parent object and these don't seem particularly useful in any case. 49 return false; 50 } 51 52 public function getResultTypeDescription() { 53 return pht('Drydock Logs'); 54 } 55 56 public function getApplicationClassName() { 57 return PhabricatorDrydockApplication::class; 58 } 59 60 public function newQuery() { 61 $query = new DrydockLogQuery(); 62 63 $blueprint = $this->getBlueprint(); 64 if ($blueprint) { 65 $query->withBlueprintPHIDs(array($blueprint->getPHID())); 66 } 67 68 $resource = $this->getResource(); 69 if ($resource) { 70 $query->withResourcePHIDs(array($resource->getPHID())); 71 } 72 73 $lease = $this->getLease(); 74 if ($lease) { 75 $query->withLeasePHIDs(array($lease->getPHID())); 76 } 77 78 $operation = $this->getOperation(); 79 if ($operation) { 80 $query->withOperationPHIDs(array($operation->getPHID())); 81 } 82 83 return $query; 84 } 85 86 protected function buildQueryFromParameters(array $map) { 87 $query = $this->newQuery(); 88 89 return $query; 90 } 91 92 protected function buildCustomSearchFields() { 93 return array(); 94 } 95 96 protected function getURI($path) { 97 $blueprint = $this->getBlueprint(); 98 if ($blueprint) { 99 $id = $blueprint->getID(); 100 return "/drydock/blueprint/{$id}/logs/{$path}"; 101 } 102 103 $resource = $this->getResource(); 104 if ($resource) { 105 $id = $resource->getID(); 106 return "/drydock/resource/{$id}/logs/{$path}"; 107 } 108 109 $lease = $this->getLease(); 110 if ($lease) { 111 $id = $lease->getID(); 112 return "/drydock/lease/{$id}/logs/{$path}"; 113 } 114 115 $operation = $this->getOperation(); 116 if ($operation) { 117 $id = $operation->getID(); 118 return "/drydock/operation/{$id}/logs/{$path}"; 119 } 120 121 throw new Exception( 122 pht( 123 'Search engine has no blueprint, resource, lease, or operation.')); 124 } 125 126 protected function getBuiltinQueryNames() { 127 return array( 128 'all' => pht('All Logs'), 129 ); 130 } 131 132 public function buildSavedQueryFromBuiltin($query_key) { 133 $query = $this->newSavedQuery(); 134 $query->setQueryKey($query_key); 135 136 switch ($query_key) { 137 case 'all': 138 return $query; 139 } 140 141 return parent::buildSavedQueryFromBuiltin($query_key); 142 } 143 144 protected function renderResultList( 145 array $logs, 146 PhabricatorSavedQuery $query, 147 array $handles) { 148 149 $list = id(new DrydockLogListView()) 150 ->setUser($this->requireViewer()) 151 ->setLogs($logs); 152 153 $result = new PhabricatorApplicationSearchResultView(); 154 $result->setTable($list); 155 156 return $result; 157 } 158 159}