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

Summary: Same as D6051, but for SavedQueries instead of NamedQueries. These are POLICY_PUBLIC because you need to know the hash to access them, and because we want to let users copy/paste query URLs. Ref T2625.

Test Plan: Saved a query, reused a saved query.

Reviewers: btrahan, blc

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2625

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

+106 -12
+7 -1
src/__phutil_library_map__.php
··· 1354 1354 'PhabricatorSQLPatchList' => 'infrastructure/storage/patch/PhabricatorSQLPatchList.php', 1355 1355 'PhabricatorSSHWorkflow' => 'infrastructure/ssh/PhabricatorSSHWorkflow.php', 1356 1356 'PhabricatorSavedQuery' => 'applications/search/storage/PhabricatorSavedQuery.php', 1357 + 'PhabricatorSavedQueryQuery' => 'applications/search/query/PhabricatorSavedQueryQuery.php', 1357 1358 'PhabricatorScopedEnv' => 'infrastructure/env/PhabricatorScopedEnv.php', 1358 1359 'PhabricatorSearchAbstractDocument' => 'applications/search/index/PhabricatorSearchAbstractDocument.php', 1359 1360 'PhabricatorSearchAttachController' => 'applications/search/controller/PhabricatorSearchAttachController.php', ··· 3135 3136 'PhabricatorRepositoryTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 3136 3137 'PhabricatorS3FileStorageEngine' => 'PhabricatorFileStorageEngine', 3137 3138 'PhabricatorSSHWorkflow' => 'PhutilArgumentWorkflow', 3138 - 'PhabricatorSavedQuery' => 'PhabricatorSearchDAO', 3139 + 'PhabricatorSavedQuery' => 3140 + array( 3141 + 0 => 'PhabricatorSearchDAO', 3142 + 1 => 'PhabricatorPolicyInterface', 3143 + ), 3144 + 'PhabricatorSavedQueryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 3139 3145 'PhabricatorSearchAttachController' => 'PhabricatorSearchBaseController', 3140 3146 'PhabricatorSearchBaseController' => 'PhabricatorController', 3141 3147 'PhabricatorSearchConfigOptions' => 'PhabricatorApplicationConfigOptions',
+4 -3
src/applications/paste/controller/PhabricatorPasteListController.php
··· 34 34 ->setPasteSearchUser($request->getUser()); 35 35 36 36 if ($this->queryKey !== null) { 37 - $saved_query = id(new PhabricatorSavedQuery())->loadOneWhere( 38 - 'queryKey = %s', 39 - $this->queryKey); 37 + $saved_query = id(new PhabricatorSavedQueryQuery()) 38 + ->setViewer($user) 39 + ->withQueryKeys(array($this->queryKey)) 40 + ->executeOne(); 40 41 41 42 if (!$saved_query) { 42 43 return new Aphront404Response();
+6 -7
src/applications/search/controller/PhabricatorSearchNameController.php
··· 17 17 $user = $request->getUser(); 18 18 19 19 if ($this->queryKey) { 20 - $saved_query = id(new PhabricatorSavedQuery())->loadOneWhere( 21 - 'queryKey = %s', 22 - $this->queryKey); 20 + $saved_query = id(new PhabricatorSavedQueryQuery()) 21 + ->setViewer($user) 22 + ->withQueryKeys(array($this->queryKey)) 23 + ->executeOne(); 23 24 if (!$saved_query) { 24 25 return new Aphront404Response(); 25 26 } ··· 28 29 } 29 30 30 31 if ($request->isFormPost()) { 31 - $request_data = $request->getRequestData(); 32 - 33 32 $named_query = id(new PhabricatorNamedQuery()) 34 33 ->setUserPHID($user->getPHID()) 35 34 ->setQueryKey($saved_query->getQueryKey()) 36 - ->setQueryName($request_data["set_name"]) 35 + ->setQueryName($request->getStr('name')) 37 36 ->setEngineClassName($saved_query->getEngineClassName()); 38 37 39 38 try { ··· 51 50 52 51 $form->appendChild( 53 52 id(new AphrontFormTextControl()) 54 - ->setName('set_name') 53 + ->setName('name') 55 54 ->setLabel(pht('Query Name'))); 56 55 57 56 $form->appendChild(
+68
src/applications/search/query/PhabricatorSavedQueryQuery.php
··· 1 + <?php 2 + 3 + final class PhabricatorSavedQueryQuery 4 + extends PhabricatorCursorPagedPolicyAwareQuery { 5 + 6 + private $ids; 7 + private $engineClassNames; 8 + private $queryKeys; 9 + 10 + public function withIDs(array $ids) { 11 + $this->ids = $ids; 12 + return $this; 13 + } 14 + 15 + public function withEngineClassNames(array $engine_class_names) { 16 + $this->engineClassNames = $engine_class_names; 17 + return $this; 18 + } 19 + 20 + public function withQueryKeys(array $query_keys) { 21 + $this->queryKeys = $query_keys; 22 + return $this; 23 + } 24 + 25 + protected function loadPage() { 26 + $table = new PhabricatorSavedQuery(); 27 + $conn_r = $table->establishConnection('r'); 28 + 29 + $data = queryfx_all( 30 + $conn_r, 31 + 'SELECT * FROM %T %Q %Q %Q', 32 + $table->getTableName(), 33 + $this->buildWhereClause($conn_r), 34 + $this->buildOrderClause($conn_r), 35 + $this->buildLimitClause($conn_r)); 36 + 37 + return $table->loadAllFromArray($data); 38 + } 39 + 40 + private function buildWhereClause($conn_r) { 41 + $where = array(); 42 + 43 + if ($this->ids) { 44 + $where[] = qsprintf( 45 + $conn_r, 46 + 'id IN (%Ld)', 47 + $this->ids); 48 + } 49 + 50 + if ($this->engineClassNames) { 51 + $where[] = qsprintf( 52 + $conn_r, 53 + 'engineClassName IN (%Ls)', 54 + $this->engineClassNames); 55 + } 56 + 57 + if ($this->queryKeys) { 58 + $where[] = qsprintf( 59 + $conn_r, 60 + 'queryKey IN (%Ls)', 61 + $this->queryKeys); 62 + } 63 + 64 + $where[] = $this->buildPagingClause($conn_r); 65 + 66 + return $this->formatWhereClause($where); 67 + } 68 + }
+21 -1
src/applications/search/storage/PhabricatorSavedQuery.php
··· 3 3 /** 4 4 * @group search 5 5 */ 6 - final class PhabricatorSavedQuery extends PhabricatorSearchDAO { 6 + final class PhabricatorSavedQuery extends PhabricatorSearchDAO 7 + implements PhabricatorPolicyInterface { 7 8 8 9 protected $parameters = array(); 9 10 protected $queryKey = ""; ··· 35 36 36 37 return parent::save(); 37 38 } 39 + 40 + 41 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 42 + 43 + 44 + public function getCapabilities() { 45 + return array( 46 + PhabricatorPolicyCapability::CAN_VIEW, 47 + ); 48 + } 49 + 50 + public function getPolicy($capability) { 51 + return PhabricatorPolicies::POLICY_PUBLIC; 52 + } 53 + 54 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 55 + return false; 56 + } 57 + 38 58 }