1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-19 11:11:10 +01:00

Invert include/exclude logic on DivinerAtomQuery

Summary: Fixes T8401. Change `withIncludeGhosts()` to `withExcludeGhosts()` and `withIncludeUndocumentable()` to `withExcludeDocumentable()`. In particular, this allows querying for atoms by PHID to work as expected.

Test Plan: I got confused with double negatives so I might have gotten some of these wrong... I poked around Diviner and re-generated documentation to verify that this is working as expected.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T8401

Differential Revision: https://secure.phabricator.com/D13157
This commit is contained in:
Joshua Spence 2015-06-05 07:00:41 +10:00
parent 0fc0af6443
commit 32f669d566
6 changed files with 27 additions and 22 deletions

View file

@ -47,6 +47,8 @@ final class DivinerAtomController extends DivinerController {
->withNames(array($this->atomName)) ->withNames(array($this->atomName))
->withContexts(array($this->atomContext)) ->withContexts(array($this->atomContext))
->withIndexes(array($this->atomIndex)) ->withIndexes(array($this->atomIndex))
->withGhosts(false)
->withIsDocumentable(true)
->needAtoms(true) ->needAtoms(true)
->needExtends(true) ->needExtends(true)
->needChildren(true) ->needChildren(true)

View file

@ -46,6 +46,8 @@ final class DivinerBookController extends DivinerController {
$atoms = id(new DivinerAtomQuery()) $atoms = id(new DivinerAtomQuery())
->setViewer($viewer) ->setViewer($viewer)
->withBookPHIDs(array($book->getPHID())) ->withBookPHIDs(array($book->getPHID()))
->withGhosts(false)
->withIsDocumentable(true)
->execute(); ->execute();
$atoms = msort($atoms, 'getSortKey'); $atoms = msort($atoms, 'getSortKey');

View file

@ -41,6 +41,9 @@ final class DivinerFindController extends DivinerController {
$query->withTypes(array($type)); $query->withTypes(array($type));
} }
$query->withGhosts(false);
$query->withIsDocumentable(true);
$name_query = clone $query; $name_query = clone $query;
$name_query->withNames( $name_query->withNames(

View file

@ -64,7 +64,7 @@ final class DivinerLivePublisher extends DivinerPublisher {
$symbols = id(new DivinerAtomQuery()) $symbols = id(new DivinerAtomQuery())
->setViewer(PhabricatorUser::getOmnipotentUser()) ->setViewer(PhabricatorUser::getOmnipotentUser())
->withBookPHIDs(array($this->loadBook()->getPHID())) ->withBookPHIDs(array($this->loadBook()->getPHID()))
->withIncludeUndocumentable(true) ->withGhosts(false)
->execute(); ->execute();
return mpull($symbols, 'getGraphHash'); return mpull($symbols, 'getGraphHash');

View file

@ -9,8 +9,8 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
private $types; private $types;
private $contexts; private $contexts;
private $indexes; private $indexes;
private $includeUndocumentable; private $isDocumentable;
private $includeGhosts; private $isGhost;
private $nodeHashes; private $nodeHashes;
private $titles; private $titles;
private $nameContains; private $nameContains;
@ -81,9 +81,9 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
/** /**
* Include "ghosts", which are symbols which used to exist but do not exist * Include or exclude "ghosts", which are symbols which used to exist but do
* currently (for example, a function which existed in an older version of * not exist currently (for example, a function which existed in an older
* the codebase but was deleted). * version of the codebase but was deleted).
* *
* These symbols had PHIDs assigned to them, and may have other sorts of * These symbols had PHIDs assigned to them, and may have other sorts of
* metadata that we don't want to lose (like comments or flags), so we don't * metadata that we don't want to lose (like comments or flags), so we don't
@ -92,14 +92,11 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
* have been generated incorrectly by accident. In these cases, we can * have been generated incorrectly by accident. In these cases, we can
* restore the original data. * restore the original data.
* *
* However, most callers are not interested in these symbols, so they are * @param bool
* excluded by default. You can use this method to include them in results.
*
* @param bool True to include ghosts.
* @return this * @return this
*/ */
public function withIncludeGhosts($include) { public function withGhosts($ghosts) {
$this->includeGhosts = $include; $this->isGhost = $ghosts;
return $this; return $this;
} }
@ -108,8 +105,8 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
return $this; return $this;
} }
public function withIncludeUndocumentable($include) { public function withIsDocumentable($documentable) {
$this->includeUndocumentable = $include; $this->isDocumentable = $documentable;
return $this; return $this;
} }
@ -346,16 +343,19 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
$this->indexes); $this->indexes);
} }
if (!$this->includeUndocumentable) { if ($this->isDocumentable !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'isDocumentable = 1'); 'isDocumentable = %d',
(int)$this->isDocumentable);
} }
if (!$this->includeGhosts) { if ($this->isGhost !== null) {
$where[] = qsprintf( if ($this->isGhost) {
$conn_r, $where[] = qsprintf($conn_r, 'graphHash IS NULL');
'graphHash IS NOT NULL'); } else {
$where[] = qsprintf($conn_r, 'graphHash IS NOT NULL');
}
} }
if ($this->nodeHashes) { if ($this->nodeHashes) {

View file

@ -93,8 +93,6 @@ final class DivinerLiveBook extends DivinerDAO
$atoms = id(new DivinerAtomQuery()) $atoms = id(new DivinerAtomQuery())
->setViewer($engine->getViewer()) ->setViewer($engine->getViewer())
->withBookPHIDs(array($this->getPHID())) ->withBookPHIDs(array($this->getPHID()))
->withIncludeGhosts(true)
->withIncludeUndocumentable(true)
->execute(); ->execute();
foreach ($atoms as $atom) { foreach ($atoms as $atom) {