@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.

Introduce PhabricatorNamedQueryQuery

Summary: Adds a first-class Query object for querying NamedQueries. xzibit would be proud.

Test Plan: Updated query edit interface to use this query, verified it works correctly.

Reviewers: btrahan, blc

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2625

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

+128 -20
+7 -1
src/__phutil_library_map__.php
··· 1147 1147 'PhabricatorMySQLConfigOptions' => 'applications/config/option/PhabricatorMySQLConfigOptions.php', 1148 1148 'PhabricatorMySQLFileStorageEngine' => 'applications/files/engine/PhabricatorMySQLFileStorageEngine.php', 1149 1149 'PhabricatorNamedQuery' => 'applications/search/storage/PhabricatorNamedQuery.php', 1150 + 'PhabricatorNamedQueryQuery' => 'applications/search/query/PhabricatorNamedQueryQuery.php', 1150 1151 'PhabricatorNoteExample' => 'applications/uiexample/examples/PhabricatorNoteExample.php', 1151 1152 'PhabricatorNotificationBuilder' => 'applications/notification/builder/PhabricatorNotificationBuilder.php', 1152 1153 'PhabricatorNotificationClearController' => 'applications/notification/controller/PhabricatorNotificationClearController.php', ··· 2923 2924 'PhabricatorMustVerifyEmailController' => 'PhabricatorAuthController', 2924 2925 'PhabricatorMySQLConfigOptions' => 'PhabricatorApplicationConfigOptions', 2925 2926 'PhabricatorMySQLFileStorageEngine' => 'PhabricatorFileStorageEngine', 2926 - 'PhabricatorNamedQuery' => 'PhabricatorSearchDAO', 2927 + 'PhabricatorNamedQuery' => 2928 + array( 2929 + 0 => 'PhabricatorSearchDAO', 2930 + 1 => 'PhabricatorPolicyInterface', 2931 + ), 2932 + 'PhabricatorNamedQueryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 2927 2933 'PhabricatorNoteExample' => 'PhabricatorUIExample', 2928 2934 'PhabricatorNotificationClearController' => 'PhabricatorNotificationController', 2929 2935 'PhabricatorNotificationConfigOptions' => 'PhabricatorApplicationConfigOptions',
+14 -18
src/applications/paste/controller/PhabricatorPasteQueriesController.php
··· 10 10 $nav = $this->buildSideNavView(""); 11 11 $filter = $nav->getSelectedFilter(); 12 12 13 - $table = new PhabricatorNamedQuery(); 14 - $conn = $table->establishConnection('r'); 15 - $data = queryfx_all( 16 - $conn, 17 - 'SELECT * FROM %T WHERE userPHID=%s AND engineClassName=%s', 18 - $table->getTableName(), 19 - $user->getPHID(), 20 - 'PhabricatorPasteSearchEngine'); 13 + $named_queries = id(new PhabricatorNamedQueryQuery()) 14 + ->setViewer($user) 15 + ->withUserPHIDs(array($user->getPHID())) 16 + ->withEngineClassNames(array('PhabricatorPasteSearchEngine')) 17 + ->execute(); 21 18 22 19 $list = new PhabricatorObjectItemListView(); 23 20 $list->setUser($user); 24 21 25 - foreach ($data as $key => $saved_query) { 26 - $date_created = phabricator_datetime($saved_query["dateCreated"], $user); 22 + foreach ($named_queries as $named_query) { 23 + $date_created = phabricator_datetime( 24 + $named_query->getDateCreated(), 25 + $user); 26 + 27 27 $item = id(new PhabricatorObjectItemView()) 28 - ->setHeader($saved_query["queryName"]) 29 - ->setHref('/paste/query/'.$saved_query["queryKey"].'/') 30 - ->addByline(pht('Date Created: ').$date_created); 28 + ->setHeader($named_query->getQueryName()) 29 + ->setHref('/paste/query/'.$named_query->getQueryKey().'/') 30 + ->addIcon('none', $date_created); 31 + 31 32 $list->addItem($item); 32 33 } 33 - 34 - $pager = new AphrontCursorPagerView(); 35 - $pager->readFromRequest($request); 36 - 37 - $list->setPager($pager); 38 34 39 35 $list->setNoDataString(pht("No results found for this query.")); 40 36
+84
src/applications/search/query/PhabricatorNamedQueryQuery.php
··· 1 + <?php 2 + 3 + /** 4 + * @group search 5 + */ 6 + final class PhabricatorNamedQueryQuery 7 + extends PhabricatorCursorPagedPolicyAwareQuery { 8 + 9 + private $ids; 10 + private $engineClassNames; 11 + private $userPHIDs; 12 + private $queryKeys; 13 + 14 + public function withIDs(array $ids) { 15 + $this->ids = $ids; 16 + return $this; 17 + } 18 + 19 + public function withUserPHIDs(array $user_phids) { 20 + $this->userPHIDs = $user_phids; 21 + return $this; 22 + } 23 + 24 + public function withEngineClassNames(array $engine_class_names) { 25 + $this->engineClassNames = $engine_class_names; 26 + return $this; 27 + } 28 + 29 + public function withQueryKeys(array $query_keys) { 30 + $this->queryKeys = $query_keys; 31 + return $this; 32 + } 33 + 34 + protected function loadPage() { 35 + $table = new PhabricatorNamedQuery(); 36 + $conn_r = $table->establishConnection('r'); 37 + 38 + $data = queryfx_all( 39 + $conn_r, 40 + 'SELECT * FROM %T %Q %Q %Q', 41 + $table->getTableName(), 42 + $this->buildWhereClause($conn_r), 43 + $this->buildOrderClause($conn_r), 44 + $this->buildLimitClause($conn_r)); 45 + 46 + return $table->loadAllFromArray($data); 47 + } 48 + 49 + private function buildWhereClause($conn_r) { 50 + $where = array(); 51 + 52 + if ($this->ids) { 53 + $where[] = qsprintf( 54 + $conn_r, 55 + 'id IN (%Ld)', 56 + $this->ids); 57 + } 58 + 59 + if ($this->engineClassNames) { 60 + $where[] = qsprintf( 61 + $conn_r, 62 + 'engineClassName IN (%Ls)', 63 + $this->engineClassNames); 64 + } 65 + 66 + if ($this->userPHIDs) { 67 + $where[] = qsprintf( 68 + $conn_r, 69 + 'userPHID IN (%Ls)', 70 + $this->userPHIDs); 71 + } 72 + 73 + if ($this->queryKeys) { 74 + $where[] = qsprintf( 75 + $conn_r, 76 + 'queryKey IN (%Ls)', 77 + $this->queryKeys); 78 + } 79 + 80 + $where[] = $this->buildPagingClause($conn_r); 81 + 82 + return $this->formatWhereClause($where); 83 + } 84 + }
+23 -1
src/applications/search/storage/PhabricatorNamedQuery.php
··· 3 3 /** 4 4 * @group search 5 5 */ 6 - final class PhabricatorNamedQuery extends PhabricatorSearchDAO { 6 + final class PhabricatorNamedQuery extends PhabricatorSearchDAO 7 + implements PhabricatorPolicyInterface { 7 8 8 9 protected $queryKey = ""; 9 10 protected $queryName = ""; 10 11 protected $userPHID = ""; 11 12 protected $engineClassName = ""; 13 + 14 + 15 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 16 + 17 + 18 + public function getCapabilities() { 19 + return array( 20 + PhabricatorPolicyCapability::CAN_VIEW, 21 + ); 22 + } 23 + 24 + public function getPolicy($capability) { 25 + return PhabricatorPolicies::POLICY_NOONE; 26 + } 27 + 28 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 29 + if ($viewer->getPHID() == $this->userPHID) { 30 + return true; 31 + } 32 + return false; 33 + } 12 34 13 35 }