mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Use ApplicationSearch in Diviner
Summary: Ref T988. Ref T2625. Rough cut of ApplicationSearch in Diviner, for detailed Atom queries. This isn't useful yet, and isn't linked in the UI. Test Plan: {F44836} Reviewers: btrahan, chad Reviewed By: btrahan CC: aran Maniphest Tasks: T988, T2625 Differential Revision: https://secure.phabricator.com/D6094
This commit is contained in:
parent
87bc6eb28c
commit
06c94b8515
10 changed files with 316 additions and 8 deletions
|
@ -503,15 +503,20 @@ phutil_register_library_map(array(
|
|||
'DivinerArticleAtomizer' => 'applications/diviner/atomizer/DivinerArticleAtomizer.php',
|
||||
'DivinerAtom' => 'applications/diviner/atom/DivinerAtom.php',
|
||||
'DivinerAtomCache' => 'applications/diviner/cache/DivinerAtomCache.php',
|
||||
'DivinerAtomListController' => 'applications/diviner/controller/DivinerAtomListController.php',
|
||||
'DivinerAtomQuery' => 'applications/diviner/query/DivinerAtomQuery.php',
|
||||
'DivinerAtomRef' => 'applications/diviner/atom/DivinerAtomRef.php',
|
||||
'DivinerAtomSearchEngine' => 'applications/diviner/query/DivinerAtomSearchEngine.php',
|
||||
'DivinerAtomizeWorkflow' => 'applications/diviner/workflow/DivinerAtomizeWorkflow.php',
|
||||
'DivinerAtomizer' => 'applications/diviner/atomizer/DivinerAtomizer.php',
|
||||
'DivinerBookQuery' => 'applications/diviner/query/DivinerBookQuery.php',
|
||||
'DivinerController' => 'applications/diviner/controller/DivinerController.php',
|
||||
'DivinerDAO' => 'applications/diviner/storage/DivinerDAO.php',
|
||||
'DivinerDefaultRenderer' => 'applications/diviner/renderer/DivinerDefaultRenderer.php',
|
||||
'DivinerDiskCache' => 'applications/diviner/cache/DivinerDiskCache.php',
|
||||
'DivinerFileAtomizer' => 'applications/diviner/atomizer/DivinerFileAtomizer.php',
|
||||
'DivinerGenerateWorkflow' => 'applications/diviner/workflow/DivinerGenerateWorkflow.php',
|
||||
'DivinerListController' => 'applications/diviner/controller/DivinerListController.php',
|
||||
'DivinerLegacyController' => 'applications/diviner/controller/DivinerLegacyController.php',
|
||||
'DivinerLiveAtom' => 'applications/diviner/storage/DivinerLiveAtom.php',
|
||||
'DivinerLiveBook' => 'applications/diviner/storage/DivinerLiveBook.php',
|
||||
'DivinerLivePublisher' => 'applications/diviner/publisher/DivinerLivePublisher.php',
|
||||
|
@ -2316,12 +2321,21 @@ phutil_register_library_map(array(
|
|||
'DiffusionView' => 'AphrontView',
|
||||
'DivinerArticleAtomizer' => 'DivinerAtomizer',
|
||||
'DivinerAtomCache' => 'DivinerDiskCache',
|
||||
'DivinerAtomListController' =>
|
||||
array(
|
||||
0 => 'DivinerController',
|
||||
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
||||
),
|
||||
'DivinerAtomQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'DivinerAtomSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'DivinerAtomizeWorkflow' => 'DivinerWorkflow',
|
||||
'DivinerBookQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'DivinerController' => 'PhabricatorController',
|
||||
'DivinerDAO' => 'PhabricatorLiskDAO',
|
||||
'DivinerDefaultRenderer' => 'DivinerRenderer',
|
||||
'DivinerFileAtomizer' => 'DivinerAtomizer',
|
||||
'DivinerGenerateWorkflow' => 'DivinerWorkflow',
|
||||
'DivinerListController' => 'PhabricatorController',
|
||||
'DivinerLegacyController' => 'DivinerController',
|
||||
'DivinerLiveAtom' => 'DivinerDAO',
|
||||
'DivinerLiveBook' =>
|
||||
array(
|
||||
|
@ -2329,7 +2343,11 @@ phutil_register_library_map(array(
|
|||
1 => 'PhabricatorPolicyInterface',
|
||||
),
|
||||
'DivinerLivePublisher' => 'DivinerPublisher',
|
||||
'DivinerLiveSymbol' => 'DivinerDAO',
|
||||
'DivinerLiveSymbol' =>
|
||||
array(
|
||||
0 => 'DivinerDAO',
|
||||
1 => 'PhabricatorPolicyInterface',
|
||||
),
|
||||
'DivinerPublishCache' => 'DivinerDiskCache',
|
||||
'DivinerRemarkupRuleSymbol' => 'PhutilRemarkupRule',
|
||||
'DivinerStaticPublisher' => 'DivinerPublisher',
|
||||
|
|
|
@ -20,7 +20,10 @@ final class PhabricatorApplicationDiviner extends PhabricatorApplication {
|
|||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
'/diviner/' => 'DivinerListController',
|
||||
'/diviner/' => array(
|
||||
'' => 'DivinerLegacyController',
|
||||
'query/((?<key>[^/]+)/)?' => 'DivinerAtomListController',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
final class DivinerAtomListController extends DivinerController
|
||||
implements PhabricatorApplicationSearchResultsControllerInterface {
|
||||
|
||||
private $key;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->key = idx($data, 'key', 'all');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$controller = id(new PhabricatorApplicationSearchController($request))
|
||||
->setQueryKey($this->key)
|
||||
->setSearchEngine(new DivinerAtomSearchEngine())
|
||||
->setNavigation($this->buildSideNavView());
|
||||
|
||||
return $this->delegateToController($controller);
|
||||
}
|
||||
|
||||
public function renderResultsList(array $symbols) {
|
||||
assert_instances_of($symbols, 'DivinerLiveSymbol');
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$list = id(new PhabricatorObjectItemListView())
|
||||
->setUser($user);
|
||||
|
||||
foreach ($symbols as $symbol) {
|
||||
$item = id(new PhabricatorObjectItemView())
|
||||
->setHeader($symbol->getName())
|
||||
->addIcon('none', $symbol->getType());
|
||||
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
24
src/applications/diviner/controller/DivinerController.php
Normal file
24
src/applications/diviner/controller/DivinerController.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
abstract class DivinerController extends PhabricatorController {
|
||||
|
||||
protected function buildSideNavView() {
|
||||
$menu = $this->buildMenu();
|
||||
return AphrontSideNavFilterView::newFromMenu($menu);
|
||||
}
|
||||
|
||||
protected function buildApplicationMenu() {
|
||||
return $this->buildMenu();
|
||||
}
|
||||
|
||||
private function buildMenu() {
|
||||
$menu = new PhabricatorMenuView();
|
||||
|
||||
id(new DivinerAtomSearchEngine())
|
||||
->setViewer($this->getRequest()->getUser())
|
||||
->addNavigationItems($menu);
|
||||
|
||||
return $menu;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class DivinerListController extends PhabricatorController {
|
||||
final class DivinerLegacyController extends DivinerController {
|
||||
|
||||
public function processRequest() {
|
||||
|
|
@ -104,9 +104,9 @@ final class DivinerLivePublisher extends DivinerPublisher {
|
|||
if ($this->shouldGenerateDocumentForAtom($atom)) {
|
||||
$content = $this->getRenderer()->renderAtom($atom);
|
||||
|
||||
$this->loadAtomStorageForSymbol($symbol)
|
||||
$storage = $this->loadAtomStorageForSymbol($symbol)
|
||||
->setAtomData($atom->toDictionary())
|
||||
->setContent(phutil_safe_html($content))
|
||||
->setContent((string)phutil_safe_html($content))
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
|
81
src/applications/diviner/query/DivinerAtomQuery.php
Normal file
81
src/applications/diviner/query/DivinerAtomQuery.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
final class DivinerAtomQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
private $ids;
|
||||
private $phids;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withPHIDs(array $phids) {
|
||||
$this->phids = $phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$table = new DivinerLiveSymbol();
|
||||
$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);
|
||||
}
|
||||
|
||||
protected function willFilterPage(array $atoms) {
|
||||
if (!$atoms) {
|
||||
return $atoms;
|
||||
}
|
||||
|
||||
$books = array_unique(mpull($atoms, 'getBookPHID'));
|
||||
|
||||
$books = id(new DivinerBookQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->withPHIDs($books)
|
||||
->execute();
|
||||
$books = mpull($books, null, 'getPHID');
|
||||
|
||||
foreach ($atoms as $key => $atom) {
|
||||
$book = idx($books, $atom->getBookPHID());
|
||||
if (!$book) {
|
||||
unset($atoms[$key]);
|
||||
continue;
|
||||
}
|
||||
$atom->attachBook($book);
|
||||
}
|
||||
|
||||
return $atoms;
|
||||
}
|
||||
|
||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
|
||||
if ($this->ids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
}
|
49
src/applications/diviner/query/DivinerAtomSearchEngine.php
Normal file
49
src/applications/diviner/query/DivinerAtomSearchEngine.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
final class DivinerAtomSearchEngine
|
||||
extends PhabricatorApplicationSearchEngine {
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$saved = new PhabricatorSavedQuery();
|
||||
|
||||
return $saved;
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new DivinerAtomQuery());
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function buildSearchForm(
|
||||
AphrontFormView $form,
|
||||
PhabricatorSavedQuery $saved_query) {
|
||||
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
return '/diviner/'.$path;
|
||||
}
|
||||
|
||||
public function getBuiltinQueryNames() {
|
||||
$names = array(
|
||||
'all' => pht('All'),
|
||||
);
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
public function buildSavedQueryFromBuiltin($query_key) {
|
||||
|
||||
$query = $this->newSavedQuery();
|
||||
$query->setQueryKey($query_key);
|
||||
|
||||
switch ($query_key) {
|
||||
case 'all':
|
||||
return $query;
|
||||
}
|
||||
|
||||
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||
}
|
||||
|
||||
}
|
56
src/applications/diviner/query/DivinerBookQuery.php
Normal file
56
src/applications/diviner/query/DivinerBookQuery.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
final class DivinerBookQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
private $ids;
|
||||
private $phids;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withPHIDs(array $phids) {
|
||||
$this->phids = $phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$table = new DivinerLiveBook();
|
||||
$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(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
|
||||
if ($this->ids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class DivinerLiveSymbol extends DivinerDAO {
|
||||
final class DivinerLiveSymbol extends DivinerDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
|
||||
protected $phid;
|
||||
protected $bookPHID;
|
||||
|
@ -11,6 +12,8 @@ final class DivinerLiveSymbol extends DivinerDAO {
|
|||
protected $graphHash;
|
||||
protected $identityHash;
|
||||
|
||||
private $book;
|
||||
|
||||
public function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_AUX_PHID => true,
|
||||
|
@ -23,6 +26,18 @@ final class DivinerLiveSymbol extends DivinerDAO {
|
|||
PhabricatorPHIDConstants::PHID_TYPE_ATOM);
|
||||
}
|
||||
|
||||
public function getBook() {
|
||||
if ($this->book === null) {
|
||||
throw new Exception("Call attachBook() before getBook()!");
|
||||
}
|
||||
return $this->book;
|
||||
}
|
||||
|
||||
public function attachBook(DivinerLiveBook $book) {
|
||||
$this->book = $book;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function save() {
|
||||
|
||||
// NOTE: The identity hash is just a sanity check because the unique tuple
|
||||
|
@ -45,4 +60,20 @@ final class DivinerLiveSymbol extends DivinerDAO {
|
|||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
public function getCapabilities() {
|
||||
return $this->getBook()->getCapabilities();
|
||||
}
|
||||
|
||||
|
||||
public function getPolicy($capability) {
|
||||
return $this->getBook()->getPolicy($capability);
|
||||
}
|
||||
|
||||
|
||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
||||
return $this->getBook()->hasAutomaticCapability($capability, $viewer);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue