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

PhameBlogSearchEngine

Summary: Modernize PhameBlogQuery, create a skeleton Search Engine.

Test Plan: Built a dashboard for testing, verify view pages still work.

Reviewers: btrahan, epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T6269

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

+96 -29
+2
src/__phutil_library_map__.php
··· 3014 3014 'PhameBlogLiveController' => 'applications/phame/controller/blog/PhameBlogLiveController.php', 3015 3015 'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php', 3016 3016 'PhameBlogResourceSite' => 'applications/phame/site/PhameBlogResourceSite.php', 3017 + 'PhameBlogSearchEngine' => 'applications/phame/query/PhameBlogSearchEngine.php', 3017 3018 'PhameBlogSite' => 'applications/phame/site/PhameBlogSite.php', 3018 3019 'PhameBlogSkin' => 'applications/phame/skins/PhameBlogSkin.php', 3019 3020 'PhameBlogTransaction' => 'applications/phame/storage/PhameBlogTransaction.php', ··· 6979 6980 'PhameBlogLiveController' => 'PhameController', 6980 6981 'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6981 6982 'PhameBlogResourceSite' => 'PhameSite', 6983 + 'PhameBlogSearchEngine' => 'PhabricatorApplicationSearchEngine', 6982 6984 'PhameBlogSite' => 'PhameSite', 6983 6985 'PhameBlogSkin' => 'PhabricatorController', 6984 6986 'PhameBlogTransaction' => 'PhabricatorApplicationTransaction',
+14 -29
src/applications/phame/query/PhameBlogQuery.php
··· 22 22 return $this; 23 23 } 24 24 25 - protected function loadPage() { 26 - $table = new PhameBlog(); 27 - $conn_r = $table->establishConnection('r'); 28 - 29 - $where_clause = $this->buildWhereClause($conn_r); 30 - $order_clause = $this->buildOrderClause($conn_r); 31 - $limit_clause = $this->buildLimitClause($conn_r); 32 - 33 - $data = queryfx_all( 34 - $conn_r, 35 - 'SELECT * FROM %T b %Q %Q %Q', 36 - $table->getTableName(), 37 - $where_clause, 38 - $order_clause, 39 - $limit_clause); 25 + public function newResultObject() { 26 + return new PhameBlog(); 27 + } 40 28 41 - $blogs = $table->loadAllFromArray($data); 42 - 43 - return $blogs; 29 + protected function loadPage() { 30 + return $this->loadStandardPage($this->newResultObject()); 44 31 } 45 32 46 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 47 - $where = array(); 33 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 34 + $where = parent::buildWhereClauseParts($conn); 48 35 49 - if ($this->ids) { 36 + if ($this->ids !== null) { 50 37 $where[] = qsprintf( 51 - $conn_r, 38 + $conn, 52 39 'id IN (%Ls)', 53 40 $this->ids); 54 41 } 55 42 56 - if ($this->phids) { 43 + if ($this->phids !== null) { 57 44 $where[] = qsprintf( 58 - $conn_r, 45 + $conn, 59 46 'phid IN (%Ls)', 60 47 $this->phids); 61 48 } 62 49 63 - if ($this->domain) { 50 + if ($this->domain !== null) { 64 51 $where[] = qsprintf( 65 - $conn_r, 52 + $conn, 66 53 'domain = %s', 67 54 $this->domain); 68 55 } 69 56 70 - $where[] = $this->buildPagingClause($conn_r); 71 - 72 - return $this->formatWhereClause($where); 57 + return $where; 73 58 } 74 59 75 60 public function getQueryApplicationClass() {
+80
src/applications/phame/query/PhameBlogSearchEngine.php
··· 1 + <?php 2 + 3 + final class PhameBlogSearchEngine 4 + extends PhabricatorApplicationSearchEngine { 5 + 6 + public function getResultTypeDescription() { 7 + return pht('Phame Blogs'); 8 + } 9 + 10 + public function getApplicationClassName() { 11 + return 'PhabricatorPhameApplication'; 12 + } 13 + 14 + public function newQuery() { 15 + return new PhameBlogQuery(); 16 + } 17 + 18 + protected function buildQueryFromParameters(array $map) { 19 + $query = $this->newQuery(); 20 + return $query; 21 + } 22 + 23 + protected function buildCustomSearchFields() { 24 + return array(); 25 + } 26 + 27 + protected function getURI($path) { 28 + return '/phame/blog/'.$path; 29 + } 30 + 31 + protected function getBuiltinQueryNames() { 32 + $names = array( 33 + 'all' => pht('All'), 34 + ); 35 + return $names; 36 + } 37 + 38 + public function buildSavedQueryFromBuiltin($query_key) { 39 + $query = $this->newSavedQuery(); 40 + $query->setQueryKey($query_key); 41 + 42 + switch ($query_key) { 43 + case 'all': 44 + return $query; 45 + } 46 + 47 + return parent::buildSavedQueryFromBuiltin($query_key); 48 + } 49 + protected function renderResultList( 50 + array $blogs, 51 + PhabricatorSavedQuery $query, 52 + array $handles) { 53 + 54 + assert_instances_of($blogs, 'PhameBlog'); 55 + $viewer = $this->requireViewer(); 56 + 57 + $list = new PHUIObjectItemListView(); 58 + $list->setUser($viewer); 59 + 60 + foreach ($blogs as $blog) { 61 + $id = $blog->getID(); 62 + $item = id(new PHUIObjectItemView()) 63 + ->setUser($viewer) 64 + ->setObject($blog) 65 + ->setHeader($blog->getName()) 66 + ->setStatusIcon('fa-star') 67 + ->setHref($this->getApplicationURI("/blog/view/{$id}/")) 68 + ->addAttribute($blog->getSkin()) 69 + ->addAttribute($blog->getDomain()); 70 + $list->addItem($item); 71 + } 72 + 73 + $result = new PhabricatorApplicationSearchResultView(); 74 + $result->setObjectList($list); 75 + $result->setNoDataString(pht('No blogs found.')); 76 + 77 + return $result; 78 + } 79 + 80 + }