1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Partially clean up Phriction document status constants; introduce "phriction.document.search"

Summary:
Depends on D19098. Ref T13077.

Phriction status constants currently use the "bag of statuses" approach typical of older code, and store integers in the database.

This fixes the "bag of statuses" stuff; a future change will fix the integers.

Also adds a skeleton for `phriction.document.search`, but doesn't implement the Conduit interface yet.

Test Plan: Searched for documents with various status constraints. Grepped for removed status constants. Viewed document list.

Maniphest Tasks: T13077

Differential Revision: https://secure.phabricator.com/D19099
This commit is contained in:
epriestley 2018-02-15 08:35:35 -08:00
parent 48eb82f229
commit c1056f6dab
9 changed files with 114 additions and 71 deletions

View file

@ -4870,6 +4870,8 @@ phutil_register_library_map(array(
'PhrictionDocumentPHIDType' => 'applications/phriction/phid/PhrictionDocumentPHIDType.php', 'PhrictionDocumentPHIDType' => 'applications/phriction/phid/PhrictionDocumentPHIDType.php',
'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php', 'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php',
'PhrictionDocumentQuery' => 'applications/phriction/query/PhrictionDocumentQuery.php', 'PhrictionDocumentQuery' => 'applications/phriction/query/PhrictionDocumentQuery.php',
'PhrictionDocumentSearchConduitAPIMethod' => 'applications/phriction/conduit/PhrictionDocumentSearchConduitAPIMethod.php',
'PhrictionDocumentSearchEngine' => 'applications/phriction/query/PhrictionDocumentSearchEngine.php',
'PhrictionDocumentStatus' => 'applications/phriction/constants/PhrictionDocumentStatus.php', 'PhrictionDocumentStatus' => 'applications/phriction/constants/PhrictionDocumentStatus.php',
'PhrictionDocumentTitleHeraldField' => 'applications/phriction/herald/PhrictionDocumentTitleHeraldField.php', 'PhrictionDocumentTitleHeraldField' => 'applications/phriction/herald/PhrictionDocumentTitleHeraldField.php',
'PhrictionDocumentTitleTransaction' => 'applications/phriction/xaction/PhrictionDocumentTitleTransaction.php', 'PhrictionDocumentTitleTransaction' => 'applications/phriction/xaction/PhrictionDocumentTitleTransaction.php',
@ -4886,7 +4888,6 @@ phutil_register_library_map(array(
'PhrictionRemarkupRule' => 'applications/phriction/markup/PhrictionRemarkupRule.php', 'PhrictionRemarkupRule' => 'applications/phriction/markup/PhrictionRemarkupRule.php',
'PhrictionReplyHandler' => 'applications/phriction/mail/PhrictionReplyHandler.php', 'PhrictionReplyHandler' => 'applications/phriction/mail/PhrictionReplyHandler.php',
'PhrictionSchemaSpec' => 'applications/phriction/storage/PhrictionSchemaSpec.php', 'PhrictionSchemaSpec' => 'applications/phriction/storage/PhrictionSchemaSpec.php',
'PhrictionSearchEngine' => 'applications/phriction/query/PhrictionSearchEngine.php',
'PhrictionTransaction' => 'applications/phriction/storage/PhrictionTransaction.php', 'PhrictionTransaction' => 'applications/phriction/storage/PhrictionTransaction.php',
'PhrictionTransactionComment' => 'applications/phriction/storage/PhrictionTransactionComment.php', 'PhrictionTransactionComment' => 'applications/phriction/storage/PhrictionTransactionComment.php',
'PhrictionTransactionEditor' => 'applications/phriction/editor/PhrictionTransactionEditor.php', 'PhrictionTransactionEditor' => 'applications/phriction/editor/PhrictionTransactionEditor.php',
@ -10799,7 +10800,9 @@ phutil_register_library_map(array(
'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType', 'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType',
'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField',
'PhrictionDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhrictionDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhrictionDocumentStatus' => 'PhrictionConstants', 'PhrictionDocumentSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
'PhrictionDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhrictionDocumentStatus' => 'PhabricatorObjectStatus',
'PhrictionDocumentTitleHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentTitleHeraldField' => 'PhrictionDocumentHeraldField',
'PhrictionDocumentTitleTransaction' => 'PhrictionDocumentTransactionType', 'PhrictionDocumentTitleTransaction' => 'PhrictionDocumentTransactionType',
'PhrictionDocumentTransactionType' => 'PhabricatorModularTransactionType', 'PhrictionDocumentTransactionType' => 'PhabricatorModularTransactionType',
@ -10815,7 +10818,6 @@ phutil_register_library_map(array(
'PhrictionRemarkupRule' => 'PhutilRemarkupRule', 'PhrictionRemarkupRule' => 'PhutilRemarkupRule',
'PhrictionReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 'PhrictionReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
'PhrictionSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'PhrictionSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'PhrictionSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhrictionTransaction' => 'PhabricatorModularTransaction', 'PhrictionTransaction' => 'PhabricatorModularTransaction',
'PhrictionTransactionComment' => 'PhabricatorApplicationTransactionComment', 'PhrictionTransactionComment' => 'PhabricatorApplicationTransactionComment',
'PhrictionTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 'PhrictionTransactionEditor' => 'PhabricatorApplicationTransactionEditor',

View file

@ -0,0 +1,18 @@
<?php
final class PhrictionDocumentSearchConduitAPIMethod
extends PhabricatorSearchEngineAPIMethod {
public function getAPIMethodName() {
return 'phriction.document.search';
}
public function newSearchEngine() {
return new PhrictionDocumentSearchEngine();
}
public function getMethodSummary() {
return pht('Read information about Phriction documents.');
}
}

View file

@ -1,6 +1,7 @@
<?php <?php
final class PhrictionDocumentStatus extends PhrictionConstants { final class PhrictionDocumentStatus
extends PhabricatorObjectStatus {
const STATUS_EXISTS = 0; const STATUS_EXISTS = 0;
const STATUS_DELETED = 1; const STATUS_DELETED = 1;
@ -18,4 +19,45 @@ final class PhrictionDocumentStatus extends PhrictionConstants {
return idx($map, $const, 'unknown'); return idx($map, $const, 'unknown');
} }
public static function newStatusObject($key) {
return new self($key, id(new self())->getStatusSpecification($key));
}
public static function getStatusMap() {
$map = id(new self())->getStatusSpecifications();
return ipull($map, 'name', 'key');
}
public function isActive() {
return ($this->getKey() == self::STATUS_EXISTS);
}
protected function newStatusSpecifications() {
return array(
array(
'key' => self::STATUS_EXISTS,
'name' => pht('Active'),
'icon' => 'fa-file-text-o',
'color' => 'bluegrey',
),
array(
'key' => self::STATUS_DELETED,
'name' => pht('Deleted'),
'icon' => 'fa-file-text-o',
'color' => 'grey',
),
array(
'key' => self::STATUS_MOVED,
'name' => pht('Moved'),
'icon' => 'fa-arrow-right',
'color' => 'grey',
),
array(
'key' => self::STATUS_STUB,
'name' => pht('Stub'),
'icon' => 'fa-file-text-o',
'color' => 'grey',
),
);
}
} }

View file

@ -13,7 +13,7 @@ abstract class PhrictionController extends PhabricatorController {
$nav->addFilter('/phriction/', pht('Index')); $nav->addFilter('/phriction/', pht('Index'));
} }
id(new PhrictionSearchEngine()) id(new PhrictionDocumentSearchEngine())
->setViewer($user) ->setViewer($user)
->addNavigationItems($nav->getMenu()); ->addNavigationItems($nav->getMenu());

View file

@ -12,7 +12,7 @@ final class PhrictionListController
$controller = id(new PhabricatorApplicationSearchController()) $controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($querykey) ->setQueryKey($querykey)
->setSearchEngine(new PhrictionSearchEngine()) ->setSearchEngine(new PhrictionDocumentSearchEngine())
->setNavigation($this->buildSideNavView()); ->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller); return $this->delegateToController($controller);

View file

@ -12,12 +12,7 @@ final class PhrictionDocumentQuery
private $needContent; private $needContent;
private $status = 'status-any'; const ORDER_HIERARCHY = 'hierarchy';
const STATUS_ANY = 'status-any';
const STATUS_OPEN = 'status-open';
const STATUS_NONSTUB = 'status-nonstub';
const ORDER_HIERARCHY = 'order-hierarchy';
public function withIDs(array $ids) { public function withIDs(array $ids) {
$this->ids = $ids; $this->ids = $ids;
@ -49,11 +44,6 @@ final class PhrictionDocumentQuery
return $this; return $this;
} }
public function withStatus($status) {
$this->status = $status;
return $this;
}
public function needContent($need_content) { public function needContent($need_content) {
$this->needContent = $need_content; $this->needContent = $need_content;
return $this; return $this;
@ -224,42 +214,16 @@ final class PhrictionDocumentQuery
$this->depths); $this->depths);
} }
switch ($this->status) {
case self::STATUS_OPEN:
$where[] = qsprintf(
$conn,
'd.status NOT IN (%Ld)',
array(
PhrictionDocumentStatus::STATUS_DELETED,
PhrictionDocumentStatus::STATUS_MOVED,
PhrictionDocumentStatus::STATUS_STUB,
));
break;
case self::STATUS_NONSTUB:
$where[] = qsprintf(
$conn,
'd.status NOT IN (%Ld)',
array(
PhrictionDocumentStatus::STATUS_MOVED,
PhrictionDocumentStatus::STATUS_STUB,
));
break;
case self::STATUS_ANY:
break;
default:
throw new Exception(pht("Unknown status '%s'!", $this->status));
}
return $where; return $where;
} }
public function getBuiltinOrders() { public function getBuiltinOrders() {
return array( return parent::getBuiltinOrders() + array(
self::ORDER_HIERARCHY => array( self::ORDER_HIERARCHY => array(
'vector' => array('depth', 'title', 'updated'), 'vector' => array('depth', 'title', 'updated'),
'name' => pht('Hierarchy'), 'name' => pht('Hierarchy'),
), ),
) + parent::getBuiltinOrders(); );
} }
public function getOrderableColumns() { public function getOrderableColumns() {

View file

@ -1,6 +1,6 @@
<?php <?php
final class PhrictionSearchEngine final class PhrictionDocumentSearchEngine
extends PhabricatorApplicationSearchEngine { extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() { public function getResultTypeDescription() {
@ -13,15 +13,14 @@ final class PhrictionSearchEngine
public function newQuery() { public function newQuery() {
return id(new PhrictionDocumentQuery()) return id(new PhrictionDocumentQuery())
->needContent(true) ->needContent(true);
->withStatus(PhrictionDocumentQuery::STATUS_NONSTUB);
} }
protected function buildQueryFromParameters(array $map) { protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery(); $query = $this->newQuery();
if ($map['status']) { if ($map['statuses']) {
$query->withStatus($map['status']); $query->withStatuses($map['statuses']);
} }
return $query; return $query;
@ -29,10 +28,10 @@ final class PhrictionSearchEngine
protected function buildCustomSearchFields() { protected function buildCustomSearchFields() {
return array( return array(
id(new PhabricatorSearchSelectField()) id(new PhabricatorSearchCheckboxesField())
->setKey('status') ->setKey('statuses')
->setLabel(pht('Status')) ->setLabel(pht('Status'))
->setOptions($this->getStatusOptions()), ->setOptions(PhrictionDocumentStatus::getStatusMap()),
); );
} }
@ -59,19 +58,15 @@ final class PhrictionSearchEngine
return $query; return $query;
case 'active': case 'active':
return $query->setParameter( return $query->setParameter(
'status', PhrictionDocumentQuery::STATUS_OPEN); 'statuses',
array(
PhrictionDocumentStatus::STATUS_EXISTS,
));
} }
return parent::buildSavedQueryFromBuiltin($query_key); return parent::buildSavedQueryFromBuiltin($query_key);
} }
private function getStatusOptions() {
return array(
PhrictionDocumentQuery::STATUS_OPEN => pht('Show Active Documents'),
PhrictionDocumentQuery::STATUS_NONSTUB => pht('Show All Documents'),
);
}
protected function getRequiredHandlePHIDsForResultList( protected function getRequiredHandlePHIDsForResultList(
array $documents, array $documents,
PhabricatorSavedQuery $query) { PhabricatorSavedQuery $query) {
@ -118,15 +113,14 @@ final class PhrictionSearchEngine
$item->addAttribute($slug_uri); $item->addAttribute($slug_uri);
switch ($document->getStatus()) { $icon = $document->getStatusIcon();
case PhrictionDocumentStatus::STATUS_DELETED: $color = $document->getStatusColor();
$item->setDisabled(true); $label = $document->getStatusDisplayName();
$item->addIcon('delete', pht('Deleted'));
break; $item->setStatusIcon("{$icon} {$color}", $label);
case PhrictionDocumentStatus::STATUS_MOVED:
$item->setDisabled(true); if (!$document->isActive()) {
$item->addIcon('arrow-right', pht('Moved Away')); $item->setDisabled(true);
break;
} }
$list->addItem($item); $list->addItem($item);

View file

@ -12,7 +12,7 @@ final class PhrictionDocumentFerretEngine
} }
public function newSearchEngine() { public function newSearchEngine() {
return new PhrictionSearchEngine(); return new PhrictionDocumentSearchEngine();
} }
} }

View file

@ -148,6 +148,29 @@ final class PhrictionDocument extends PhrictionDAO
return $this; return $this;
} }
/* -( Status )------------------------------------------------------------- */
public function getStatusObject() {
return PhrictionDocumentStatus::newStatusObject($this->getStatus());
}
public function getStatusIcon() {
return $this->getStatusObject()->getIcon();
}
public function getStatusColor() {
return $this->getStatusObject()->getColor();
}
public function getStatusDisplayName() {
return $this->getStatusObject()->getDisplayName();
}
public function isActive() {
return $this->getStatusObject()->isActive();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */