diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 954bb2fe79..b513a618f0 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -677,6 +677,7 @@ phutil_register_library_map(array( 'PhabricatorOAuthClientAuthorizationDeleteController' => 'applications/oauthserver/controller/clientauthorization/delete', 'PhabricatorOAuthClientAuthorizationEditController' => 'applications/oauthserver/controller/clientauthorization/edit', 'PhabricatorOAuthClientAuthorizationListController' => 'applications/oauthserver/controller/clientauthorization/list', + 'PhabricatorOAuthClientAuthorizationQuery' => 'applications/oauthserver/query/clientauthorization', 'PhabricatorOAuthClientBaseController' => 'applications/oauthserver/controller/client/base', 'PhabricatorOAuthClientDeleteController' => 'applications/oauthserver/controller/client/delete', 'PhabricatorOAuthClientEditController' => 'applications/oauthserver/controller/client/edit', @@ -698,6 +699,7 @@ phutil_register_library_map(array( 'PhabricatorOAuthServerAuthController' => 'applications/oauthserver/controller/auth', 'PhabricatorOAuthServerAuthorizationCode' => 'applications/oauthserver/storage/authorizationcode', 'PhabricatorOAuthServerClient' => 'applications/oauthserver/storage/client', + 'PhabricatorOAuthServerClientQuery' => 'applications/oauthserver/query/client', 'PhabricatorOAuthServerController' => 'applications/oauthserver/controller/base', 'PhabricatorOAuthServerDAO' => 'applications/oauthserver/storage/base', 'PhabricatorOAuthServerScope' => 'applications/oauthserver/scope', @@ -1510,6 +1512,7 @@ phutil_register_library_map(array( 'PhabricatorOAuthClientAuthorizationDeleteController' => 'PhabricatorOAuthClientAuthorizationBaseController', 'PhabricatorOAuthClientAuthorizationEditController' => 'PhabricatorOAuthClientAuthorizationBaseController', 'PhabricatorOAuthClientAuthorizationListController' => 'PhabricatorOAuthClientAuthorizationBaseController', + 'PhabricatorOAuthClientAuthorizationQuery' => 'PhabricatorOffsetPagedQuery', 'PhabricatorOAuthClientBaseController' => 'PhabricatorOAuthServerController', 'PhabricatorOAuthClientDeleteController' => 'PhabricatorOAuthClientBaseController', 'PhabricatorOAuthClientEditController' => 'PhabricatorOAuthClientBaseController', @@ -1529,6 +1532,7 @@ phutil_register_library_map(array( 'PhabricatorOAuthServerAuthController' => 'PhabricatorAuthController', 'PhabricatorOAuthServerAuthorizationCode' => 'PhabricatorOAuthServerDAO', 'PhabricatorOAuthServerClient' => 'PhabricatorOAuthServerDAO', + 'PhabricatorOAuthServerClientQuery' => 'PhabricatorOffsetPagedQuery', 'PhabricatorOAuthServerController' => 'PhabricatorController', 'PhabricatorOAuthServerDAO' => 'PhabricatorLiskDAO', 'PhabricatorOAuthServerTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/chatlog/query/PhabricatorChatLogQuery.php b/src/applications/chatlog/query/PhabricatorChatLogQuery.php index 9a52e37ee1..2ebba619f6 100644 --- a/src/applications/chatlog/query/PhabricatorChatLogQuery.php +++ b/src/applications/chatlog/query/PhabricatorChatLogQuery.php @@ -53,12 +53,6 @@ final class PhabricatorChatLogQuery extends PhabricatorOffsetPagedQuery { $this->channels); } - if ($where) { - $where = 'WHERE ('.implode(') AND (', $where).')'; - } else { - $where = ''; - } - - return $where; + return $this->formatWhereClause($where); } } diff --git a/src/applications/oauthserver/controller/client/list/PhabricatorOAuthClientListController.php b/src/applications/oauthserver/controller/client/list/PhabricatorOAuthClientListController.php index 43b389f51d..7eae98caf6 100644 --- a/src/applications/oauthserver/controller/client/list/PhabricatorOAuthClientListController.php +++ b/src/applications/oauthserver/controller/client/list/PhabricatorOAuthClientListController.php @@ -30,9 +30,17 @@ extends PhabricatorOAuthClientBaseController { $title = 'OAuth Clients'; $request = $this->getRequest(); $current_user = $request->getUser(); - $clients = id(new PhabricatorOAuthServerClient()) - ->loadAllWhere('creatorPHID = %s', - $current_user->getPHID()); + $offset = $request->getInt('offset', 0); + $page_size = 100; + $pager = new AphrontPagerView(); + $request_uri = $request->getRequestURI(); + $pager->setURI($request_uri, 'offset'); + $pager->setPageSize($page_size); + $pager->setOffset($offset); + + $query = new PhabricatorOAuthServerClientQuery(); + $query->withCreatorPHIDs(array($current_user->getPHID())); + $clients = $query->executeWithPager($pager); $rows = array(); $rowc = array(); @@ -76,8 +84,10 @@ extends PhabricatorOAuthClientBaseController { $panel = $this->buildClientList($rows, $rowc, $title); return $this->buildStandardPageResponse( - array($this->getNoticeView(), - $panel), + array( + $this->getNoticeView(), + $panel->appendChild($pager) + ), array('title' => $title) ); } diff --git a/src/applications/oauthserver/controller/client/list/__init__.php b/src/applications/oauthserver/controller/client/list/__init__.php index f33786da85..e98d1b01fb 100644 --- a/src/applications/oauthserver/controller/client/list/__init__.php +++ b/src/applications/oauthserver/controller/client/list/__init__.php @@ -7,13 +7,13 @@ phutil_require_module('phabricator', 'applications/oauthserver/controller/client/base'); -phutil_require_module('phabricator', 'applications/oauthserver/storage/client'); +phutil_require_module('phabricator', 'applications/oauthserver/query/client'); +phutil_require_module('phabricator', 'view/control/pager'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/form/error'); phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phutil', 'markup'); -phutil_require_module('phutil', 'utils'); phutil_require_source('PhabricatorOAuthClientListController.php'); diff --git a/src/applications/oauthserver/controller/clientauthorization/list/PhabricatorOAuthClientAuthorizationListController.php b/src/applications/oauthserver/controller/clientauthorization/list/PhabricatorOAuthClientAuthorizationListController.php index 5cd83547e3..40db526f23 100644 --- a/src/applications/oauthserver/controller/clientauthorization/list/PhabricatorOAuthClientAuthorizationListController.php +++ b/src/applications/oauthserver/controller/clientauthorization/list/PhabricatorOAuthClientAuthorizationListController.php @@ -27,12 +27,20 @@ extends PhabricatorOAuthClientAuthorizationBaseController { } public function processRequest() { - $title = 'OAuth Client Authorizations'; - $request = $this->getRequest(); - $current_user = $request->getUser(); - $authorizations = id(new PhabricatorOAuthClientAuthorization()) - ->loadAllWhere('userPHID = %s', - $current_user->getPHID()); + $title = 'OAuth Client Authorizations'; + $request = $this->getRequest(); + $current_user = $request->getUser(); + $offset = $request->getInt('offset', 0); + $page_size = 100; + $pager = new AphrontPagerView(); + $request_uri = $request->getRequestURI(); + $pager->setURI($request_uri, 'offset'); + $pager->setPageSize($page_size); + $pager->setOffset($offset); + + $query = new PhabricatorOAuthClientAuthorizationQuery(); + $query->withUserPHIDs(array($current_user->getPHID())); + $authorizations = $query->executeWithPager($pager); $client_authorizations = mpull($authorizations, null, 'getClientPHID'); $client_phids = array_keys($client_authorizations); @@ -101,8 +109,10 @@ extends PhabricatorOAuthClientAuthorizationBaseController { $panel = $this->buildClientAuthorizationList($rows, $rowc, $title); return $this->buildStandardPageResponse( - array($this->getNoticeView(), - $panel), + array( + $this->getNoticeView(), + $panel->appendChild($pager), + ), array('title' => $title) ); } diff --git a/src/applications/oauthserver/controller/clientauthorization/list/__init__.php b/src/applications/oauthserver/controller/clientauthorization/list/__init__.php index ede9a9b918..b5c0194a0c 100644 --- a/src/applications/oauthserver/controller/clientauthorization/list/__init__.php +++ b/src/applications/oauthserver/controller/clientauthorization/list/__init__.php @@ -7,9 +7,10 @@ phutil_require_module('phabricator', 'applications/oauthserver/controller/clientauthorization/base'); +phutil_require_module('phabricator', 'applications/oauthserver/query/clientauthorization'); phutil_require_module('phabricator', 'applications/oauthserver/storage/client'); -phutil_require_module('phabricator', 'applications/oauthserver/storage/clientauthorization'); phutil_require_module('phabricator', 'infrastructure/env'); +phutil_require_module('phabricator', 'view/control/pager'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/form/error'); phutil_require_module('phabricator', 'view/layout/panel'); diff --git a/src/applications/oauthserver/query/client/PhabricatorOAuthServerClientQuery.php b/src/applications/oauthserver/query/client/PhabricatorOAuthServerClientQuery.php new file mode 100644 index 0000000000..cb6bc4733d --- /dev/null +++ b/src/applications/oauthserver/query/client/PhabricatorOAuthServerClientQuery.php @@ -0,0 +1,60 @@ +creatorPHIDs = $phids; + return $this; + } + private function getCreatorPHIDs() { + return $this->creatorPHIDs; + } + + public function execute() { + $table = new PhabricatorOAuthServerClient(); + $conn_r = $table->establishConnection('r'); + + $where_clause = $this->buildWhereClause($conn_r); + $limit_clause = $this->buildLimitClause($conn_r); + + $data = queryfx_all( + $conn_r, + 'SELECT * FROM %T client %Q %Q', + $table->getTableName(), + $where_clause, + $limit_clause); + + return $table->loadAllFromArray($data); + } + + private function buildWhereClause($conn_r) { + $where = array(); + + if ($this->getCreatorPHIDs()) { + $where[] = qsprintf( + $conn_r, + 'creatorPHID IN (%Ls)', + $this->getCreatorPHIDs()); + } + + return $this->formatWhereClause($where); + } +} diff --git a/src/applications/oauthserver/query/client/__init__.php b/src/applications/oauthserver/query/client/__init__.php new file mode 100644 index 0000000000..50f65182b1 --- /dev/null +++ b/src/applications/oauthserver/query/client/__init__.php @@ -0,0 +1,15 @@ +userPHIDs = $phids; + return $this; + } + private function getUserPHIDs() { + return $this->userPHIDs; + } + + public function execute() { + $table = new PhabricatorOAuthClientAuthorization(); + $conn_r = $table->establishConnection('r'); + + $where_clause = $this->buildWhereClause($conn_r); + $limit_clause = $this->buildLimitClause($conn_r); + + $data = queryfx_all( + $conn_r, + 'SELECT * FROM %T auth %Q %Q', + $table->getTableName(), + $where_clause, + $limit_clause); + + return $table->loadAllFromArray($data); + } + + private function buildWhereClause($conn_r) { + $where = array(); + + if ($this->getUserPHIDs()) { + $where[] = qsprintf( + $conn_r, + 'userPHID IN (%Ls)', + $this->getUserPHIDs()); + } + + return $this->formatWhereClause($where); + } +} diff --git a/src/applications/oauthserver/query/clientauthorization/__init__.php b/src/applications/oauthserver/query/clientauthorization/__init__.php new file mode 100644 index 0000000000..8fcd798b79 --- /dev/null +++ b/src/applications/oauthserver/query/clientauthorization/__init__.php @@ -0,0 +1,15 @@ +