mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
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
This commit is contained in:
parent
6551ea8245
commit
12e9350efb
4 changed files with 128 additions and 20 deletions
|
@ -1147,6 +1147,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorMySQLConfigOptions' => 'applications/config/option/PhabricatorMySQLConfigOptions.php',
|
'PhabricatorMySQLConfigOptions' => 'applications/config/option/PhabricatorMySQLConfigOptions.php',
|
||||||
'PhabricatorMySQLFileStorageEngine' => 'applications/files/engine/PhabricatorMySQLFileStorageEngine.php',
|
'PhabricatorMySQLFileStorageEngine' => 'applications/files/engine/PhabricatorMySQLFileStorageEngine.php',
|
||||||
'PhabricatorNamedQuery' => 'applications/search/storage/PhabricatorNamedQuery.php',
|
'PhabricatorNamedQuery' => 'applications/search/storage/PhabricatorNamedQuery.php',
|
||||||
|
'PhabricatorNamedQueryQuery' => 'applications/search/query/PhabricatorNamedQueryQuery.php',
|
||||||
'PhabricatorNoteExample' => 'applications/uiexample/examples/PhabricatorNoteExample.php',
|
'PhabricatorNoteExample' => 'applications/uiexample/examples/PhabricatorNoteExample.php',
|
||||||
'PhabricatorNotificationBuilder' => 'applications/notification/builder/PhabricatorNotificationBuilder.php',
|
'PhabricatorNotificationBuilder' => 'applications/notification/builder/PhabricatorNotificationBuilder.php',
|
||||||
'PhabricatorNotificationClearController' => 'applications/notification/controller/PhabricatorNotificationClearController.php',
|
'PhabricatorNotificationClearController' => 'applications/notification/controller/PhabricatorNotificationClearController.php',
|
||||||
|
@ -2923,7 +2924,12 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorMustVerifyEmailController' => 'PhabricatorAuthController',
|
'PhabricatorMustVerifyEmailController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorMySQLConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
'PhabricatorMySQLConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
'PhabricatorMySQLFileStorageEngine' => 'PhabricatorFileStorageEngine',
|
'PhabricatorMySQLFileStorageEngine' => 'PhabricatorFileStorageEngine',
|
||||||
'PhabricatorNamedQuery' => 'PhabricatorSearchDAO',
|
'PhabricatorNamedQuery' =>
|
||||||
|
array(
|
||||||
|
0 => 'PhabricatorSearchDAO',
|
||||||
|
1 => 'PhabricatorPolicyInterface',
|
||||||
|
),
|
||||||
|
'PhabricatorNamedQueryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhabricatorNoteExample' => 'PhabricatorUIExample',
|
'PhabricatorNoteExample' => 'PhabricatorUIExample',
|
||||||
'PhabricatorNotificationClearController' => 'PhabricatorNotificationController',
|
'PhabricatorNotificationClearController' => 'PhabricatorNotificationController',
|
||||||
'PhabricatorNotificationConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
'PhabricatorNotificationConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
|
|
|
@ -10,32 +10,28 @@ final class PhabricatorPasteQueriesController
|
||||||
$nav = $this->buildSideNavView("");
|
$nav = $this->buildSideNavView("");
|
||||||
$filter = $nav->getSelectedFilter();
|
$filter = $nav->getSelectedFilter();
|
||||||
|
|
||||||
$table = new PhabricatorNamedQuery();
|
$named_queries = id(new PhabricatorNamedQueryQuery())
|
||||||
$conn = $table->establishConnection('r');
|
->setViewer($user)
|
||||||
$data = queryfx_all(
|
->withUserPHIDs(array($user->getPHID()))
|
||||||
$conn,
|
->withEngineClassNames(array('PhabricatorPasteSearchEngine'))
|
||||||
'SELECT * FROM %T WHERE userPHID=%s AND engineClassName=%s',
|
->execute();
|
||||||
$table->getTableName(),
|
|
||||||
$user->getPHID(),
|
|
||||||
'PhabricatorPasteSearchEngine');
|
|
||||||
|
|
||||||
$list = new PhabricatorObjectItemListView();
|
$list = new PhabricatorObjectItemListView();
|
||||||
$list->setUser($user);
|
$list->setUser($user);
|
||||||
|
|
||||||
foreach ($data as $key => $saved_query) {
|
foreach ($named_queries as $named_query) {
|
||||||
$date_created = phabricator_datetime($saved_query["dateCreated"], $user);
|
$date_created = phabricator_datetime(
|
||||||
|
$named_query->getDateCreated(),
|
||||||
|
$user);
|
||||||
|
|
||||||
$item = id(new PhabricatorObjectItemView())
|
$item = id(new PhabricatorObjectItemView())
|
||||||
->setHeader($saved_query["queryName"])
|
->setHeader($named_query->getQueryName())
|
||||||
->setHref('/paste/query/'.$saved_query["queryKey"].'/')
|
->setHref('/paste/query/'.$named_query->getQueryKey().'/')
|
||||||
->addByline(pht('Date Created: ').$date_created);
|
->addIcon('none', $date_created);
|
||||||
|
|
||||||
$list->addItem($item);
|
$list->addItem($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pager = new AphrontCursorPagerView();
|
|
||||||
$pager->readFromRequest($request);
|
|
||||||
|
|
||||||
$list->setPager($pager);
|
|
||||||
|
|
||||||
$list->setNoDataString(pht("No results found for this query."));
|
$list->setNoDataString(pht("No results found for this query."));
|
||||||
|
|
||||||
$nav->appendChild(
|
$nav->appendChild(
|
||||||
|
|
84
src/applications/search/query/PhabricatorNamedQueryQuery.php
Normal file
84
src/applications/search/query/PhabricatorNamedQueryQuery.php
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group search
|
||||||
|
*/
|
||||||
|
final class PhabricatorNamedQueryQuery
|
||||||
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||||
|
|
||||||
|
private $ids;
|
||||||
|
private $engineClassNames;
|
||||||
|
private $userPHIDs;
|
||||||
|
private $queryKeys;
|
||||||
|
|
||||||
|
public function withIDs(array $ids) {
|
||||||
|
$this->ids = $ids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withUserPHIDs(array $user_phids) {
|
||||||
|
$this->userPHIDs = $user_phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withEngineClassNames(array $engine_class_names) {
|
||||||
|
$this->engineClassNames = $engine_class_names;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withQueryKeys(array $query_keys) {
|
||||||
|
$this->queryKeys = $query_keys;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function loadPage() {
|
||||||
|
$table = new PhabricatorNamedQuery();
|
||||||
|
$conn_r = $table->establishConnection('r');
|
||||||
|
|
||||||
|
$data = queryfx_all(
|
||||||
|
$conn_r,
|
||||||
|
'SELECT * FROM %T %Q %Q %Q',
|
||||||
|
$table->getTableName(),
|
||||||
|
$this->buildWhereClause($conn_r),
|
||||||
|
$this->buildOrderClause($conn_r),
|
||||||
|
$this->buildLimitClause($conn_r));
|
||||||
|
|
||||||
|
return $table->loadAllFromArray($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildWhereClause($conn_r) {
|
||||||
|
$where = array();
|
||||||
|
|
||||||
|
if ($this->ids) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'id IN (%Ld)',
|
||||||
|
$this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->engineClassNames) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'engineClassName IN (%Ls)',
|
||||||
|
$this->engineClassNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->userPHIDs) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'userPHID IN (%Ls)',
|
||||||
|
$this->userPHIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->queryKeys) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'queryKey IN (%Ls)',
|
||||||
|
$this->queryKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
$where[] = $this->buildPagingClause($conn_r);
|
||||||
|
|
||||||
|
return $this->formatWhereClause($where);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,11 +3,33 @@
|
||||||
/**
|
/**
|
||||||
* @group search
|
* @group search
|
||||||
*/
|
*/
|
||||||
final class PhabricatorNamedQuery extends PhabricatorSearchDAO {
|
final class PhabricatorNamedQuery extends PhabricatorSearchDAO
|
||||||
|
implements PhabricatorPolicyInterface {
|
||||||
|
|
||||||
protected $queryKey = "";
|
protected $queryKey = "";
|
||||||
protected $queryName = "";
|
protected $queryName = "";
|
||||||
protected $userPHID = "";
|
protected $userPHID = "";
|
||||||
protected $engineClassName = "";
|
protected $engineClassName = "";
|
||||||
|
|
||||||
|
|
||||||
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
public function getCapabilities() {
|
||||||
|
return array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPolicy($capability) {
|
||||||
|
return PhabricatorPolicies::POLICY_NOONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
||||||
|
if ($viewer->getPHID() == $this->userPHID) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue