@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Rough skeleton of a "Query" dashboard panel

Summary: Ref T4986. This isn't pretty/usable yet (I need to move rendering out of ListController classes and into SearchEngine classes, I think) but does pull the correct results.

Test Plan: {F151537}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4986

Differential Revision: https://secure.phabricator.com/D9007

+132 -9
+2
src/__phutil_library_map__.php
··· 1463 1463 'PhabricatorDashboardPanelTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php', 1464 1464 'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php', 1465 1465 'PhabricatorDashboardPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelType.php', 1466 + 'PhabricatorDashboardPanelTypeQuery' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php', 1466 1467 'PhabricatorDashboardPanelTypeText' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php', 1467 1468 'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/PhabricatorDashboardPanelViewController.php', 1468 1469 'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php', ··· 4306 4307 'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 4307 4308 'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 4308 4309 'PhabricatorDashboardPanelType' => 'Phobject', 4310 + 'PhabricatorDashboardPanelTypeQuery' => 'PhabricatorDashboardPanelType', 4309 4311 'PhabricatorDashboardPanelTypeText' => 'PhabricatorDashboardPanelType', 4310 4312 'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController', 4311 4313 'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+10 -2
src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
··· 50 50 } 51 51 } 52 52 53 - 54 - return $panel_type->renderPanel($viewer, $panel); 53 + try { 54 + return $panel_type->renderPanel($viewer, $panel); 55 + } catch (Exception $ex) { 56 + return $this->renderErrorPanel( 57 + $panel->getName(), 58 + pht( 59 + '%s: %s', 60 + phutil_tag('strong', array(), get_class($ex)), 61 + $ex->getMessage())); 62 + } 55 63 } 56 64 57 65 private function renderErrorPanel($title, $body) {
+82
src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php
··· 1 + <?php 2 + 3 + final class PhabricatorDashboardPanelTypeQuery 4 + extends PhabricatorDashboardPanelType { 5 + 6 + public function getPanelTypeKey() { 7 + return 'query'; 8 + } 9 + 10 + public function getPanelTypeName() { 11 + return pht('Query Panel'); 12 + } 13 + 14 + public function getPanelTypeDescription() { 15 + return pht( 16 + 'Show results of a search query, like the most recently filed tasks or '. 17 + 'revisions you need to review.'); 18 + } 19 + 20 + public function getFieldSpecifications() { 21 + return array( 22 + 'class' => array( 23 + 'name' => pht('ApplicationSearch Class'), 24 + 'type' => 'text', 25 + ), 26 + 'key' => array( 27 + 'name' => pht('ApplicationSearch Key'), 28 + 'type' => 'text', 29 + ), 30 + ); 31 + } 32 + 33 + protected function renderPanelContent( 34 + PhabricatorUser $viewer, 35 + PhabricatorDashboardPanel $panel) { 36 + 37 + $class = $panel->getProperty('class'); 38 + 39 + $engine = PhabricatorApplicationSearchEngine::getEngineByClassName($class); 40 + if (!$engine) { 41 + throw new Exception( 42 + pht( 43 + 'The application search engine "%s" is not known to Phabricator!', 44 + $class)); 45 + } 46 + 47 + $engine->setViewer($viewer); 48 + 49 + $key = $panel->getProperty('key'); 50 + if ($engine->isBuiltinQuery($key)) { 51 + $saved = $engine->buildSavedQueryFromBuiltin($key); 52 + } else { 53 + $saved = id(new PhabricatorSavedQueryQuery()) 54 + ->setViewer($viewer) 55 + ->withEngineClassNames(array($class)) 56 + ->withQueryKeys(array($key)) 57 + ->executeOne(); 58 + } 59 + 60 + if (!$saved) { 61 + throw new Exception( 62 + pht( 63 + 'Query "%s" is unknown to application search engine "%s"!', 64 + $key, 65 + $class)); 66 + } 67 + 68 + $query = $engine->buildQueryFromSavedQuery($saved); 69 + 70 + $results = $query 71 + ->setViewer($viewer) 72 + ->execute(); 73 + 74 + $out = array(); 75 + foreach ($results as $result) { 76 + $out[] = phutil_tag('div', array(), $result->getPHID()); 77 + } 78 + 79 + return $out; 80 + } 81 + 82 + }
+35 -4
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
··· 4 4 * Represents an abstract search engine for an application. It supports 5 5 * creating and storing saved queries. 6 6 * 7 - * @task builtin Builtin Queries 8 - * @task uri Query URIs 9 - * @task dates Date Filters 10 - * @task read Reading Utilities 7 + * @task construct Constructing Engines 8 + * @task builtin Builtin Queries 9 + * @task uri Query URIs 10 + * @task dates Date Filters 11 + * @task read Reading Utilities 11 12 * 12 13 * @group search 13 14 */ ··· 171 172 } 172 173 } 173 174 return $named_queries; 175 + } 176 + 177 + 178 + /* -( Constructing Engines )----------------------------------------------- */ 179 + 180 + 181 + /** 182 + * Load all available application search engines. 183 + * 184 + * @return list<PhabricatorApplicationSearchEngine> All available engines. 185 + * @task construct 186 + */ 187 + public static function getAllEngines() { 188 + $engines = id(new PhutilSymbolLoader()) 189 + ->setAncestorClass(__CLASS__) 190 + ->loadObjects(); 191 + 192 + return $engines; 193 + } 194 + 195 + 196 + /** 197 + * Get an engine by class name, if it exists. 198 + * 199 + * @return PhabricatorApplicationSearchEngine|null Engine, or null if it does 200 + * not exist. 201 + * @task construct 202 + */ 203 + public static function getEngineByClassName($class_name) { 204 + return idx(self::getAllEngines(), $class_name); 174 205 } 175 206 176 207
+3 -3
src/applications/search/query/PhabricatorSavedQueryQuery.php
··· 40 40 private function buildWhereClause($conn_r) { 41 41 $where = array(); 42 42 43 - if ($this->ids) { 43 + if ($this->ids !== null) { 44 44 $where[] = qsprintf( 45 45 $conn_r, 46 46 'id IN (%Ld)', 47 47 $this->ids); 48 48 } 49 49 50 - if ($this->engineClassNames) { 50 + if ($this->engineClassNames !== null) { 51 51 $where[] = qsprintf( 52 52 $conn_r, 53 53 'engineClassName IN (%Ls)', 54 54 $this->engineClassNames); 55 55 } 56 56 57 - if ($this->queryKeys) { 57 + if ($this->queryKeys !== null) { 58 58 $where[] = qsprintf( 59 59 $conn_r, 60 60 'queryKey IN (%Ls)',