@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

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

+114 -71
+5 -3
src/__phutil_library_map__.php
··· 4870 4870 'PhrictionDocumentPHIDType' => 'applications/phriction/phid/PhrictionDocumentPHIDType.php', 4871 4871 'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php', 4872 4872 'PhrictionDocumentQuery' => 'applications/phriction/query/PhrictionDocumentQuery.php', 4873 + 'PhrictionDocumentSearchConduitAPIMethod' => 'applications/phriction/conduit/PhrictionDocumentSearchConduitAPIMethod.php', 4874 + 'PhrictionDocumentSearchEngine' => 'applications/phriction/query/PhrictionDocumentSearchEngine.php', 4873 4875 'PhrictionDocumentStatus' => 'applications/phriction/constants/PhrictionDocumentStatus.php', 4874 4876 'PhrictionDocumentTitleHeraldField' => 'applications/phriction/herald/PhrictionDocumentTitleHeraldField.php', 4875 4877 'PhrictionDocumentTitleTransaction' => 'applications/phriction/xaction/PhrictionDocumentTitleTransaction.php', ··· 4886 4888 'PhrictionRemarkupRule' => 'applications/phriction/markup/PhrictionRemarkupRule.php', 4887 4889 'PhrictionReplyHandler' => 'applications/phriction/mail/PhrictionReplyHandler.php', 4888 4890 'PhrictionSchemaSpec' => 'applications/phriction/storage/PhrictionSchemaSpec.php', 4889 - 'PhrictionSearchEngine' => 'applications/phriction/query/PhrictionSearchEngine.php', 4890 4891 'PhrictionTransaction' => 'applications/phriction/storage/PhrictionTransaction.php', 4891 4892 'PhrictionTransactionComment' => 'applications/phriction/storage/PhrictionTransactionComment.php', 4892 4893 'PhrictionTransactionEditor' => 'applications/phriction/editor/PhrictionTransactionEditor.php', ··· 10799 10800 'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType', 10800 10801 'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField', 10801 10802 'PhrictionDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 10802 - 'PhrictionDocumentStatus' => 'PhrictionConstants', 10803 + 'PhrictionDocumentSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 10804 + 'PhrictionDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine', 10805 + 'PhrictionDocumentStatus' => 'PhabricatorObjectStatus', 10803 10806 'PhrictionDocumentTitleHeraldField' => 'PhrictionDocumentHeraldField', 10804 10807 'PhrictionDocumentTitleTransaction' => 'PhrictionDocumentTransactionType', 10805 10808 'PhrictionDocumentTransactionType' => 'PhabricatorModularTransactionType', ··· 10815 10818 'PhrictionRemarkupRule' => 'PhutilRemarkupRule', 10816 10819 'PhrictionReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 10817 10820 'PhrictionSchemaSpec' => 'PhabricatorConfigSchemaSpec', 10818 - 'PhrictionSearchEngine' => 'PhabricatorApplicationSearchEngine', 10819 10821 'PhrictionTransaction' => 'PhabricatorModularTransaction', 10820 10822 'PhrictionTransactionComment' => 'PhabricatorApplicationTransactionComment', 10821 10823 'PhrictionTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
+18
src/applications/phriction/conduit/PhrictionDocumentSearchConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class PhrictionDocumentSearchConduitAPIMethod 4 + extends PhabricatorSearchEngineAPIMethod { 5 + 6 + public function getAPIMethodName() { 7 + return 'phriction.document.search'; 8 + } 9 + 10 + public function newSearchEngine() { 11 + return new PhrictionDocumentSearchEngine(); 12 + } 13 + 14 + public function getMethodSummary() { 15 + return pht('Read information about Phriction documents.'); 16 + } 17 + 18 + }
+43 -1
src/applications/phriction/constants/PhrictionDocumentStatus.php
··· 1 1 <?php 2 2 3 - final class PhrictionDocumentStatus extends PhrictionConstants { 3 + final class PhrictionDocumentStatus 4 + extends PhabricatorObjectStatus { 4 5 5 6 const STATUS_EXISTS = 0; 6 7 const STATUS_DELETED = 1; ··· 18 19 return idx($map, $const, 'unknown'); 19 20 } 20 21 22 + public static function newStatusObject($key) { 23 + return new self($key, id(new self())->getStatusSpecification($key)); 24 + } 25 + 26 + public static function getStatusMap() { 27 + $map = id(new self())->getStatusSpecifications(); 28 + return ipull($map, 'name', 'key'); 29 + } 30 + 31 + public function isActive() { 32 + return ($this->getKey() == self::STATUS_EXISTS); 33 + } 34 + 35 + protected function newStatusSpecifications() { 36 + return array( 37 + array( 38 + 'key' => self::STATUS_EXISTS, 39 + 'name' => pht('Active'), 40 + 'icon' => 'fa-file-text-o', 41 + 'color' => 'bluegrey', 42 + ), 43 + array( 44 + 'key' => self::STATUS_DELETED, 45 + 'name' => pht('Deleted'), 46 + 'icon' => 'fa-file-text-o', 47 + 'color' => 'grey', 48 + ), 49 + array( 50 + 'key' => self::STATUS_MOVED, 51 + 'name' => pht('Moved'), 52 + 'icon' => 'fa-arrow-right', 53 + 'color' => 'grey', 54 + ), 55 + array( 56 + 'key' => self::STATUS_STUB, 57 + 'name' => pht('Stub'), 58 + 'icon' => 'fa-file-text-o', 59 + 'color' => 'grey', 60 + ), 61 + ); 62 + } 21 63 }
+1 -1
src/applications/phriction/controller/PhrictionController.php
··· 13 13 $nav->addFilter('/phriction/', pht('Index')); 14 14 } 15 15 16 - id(new PhrictionSearchEngine()) 16 + id(new PhrictionDocumentSearchEngine()) 17 17 ->setViewer($user) 18 18 ->addNavigationItems($nav->getMenu()); 19 19
+1 -1
src/applications/phriction/controller/PhrictionListController.php
··· 12 12 13 13 $controller = id(new PhabricatorApplicationSearchController()) 14 14 ->setQueryKey($querykey) 15 - ->setSearchEngine(new PhrictionSearchEngine()) 15 + ->setSearchEngine(new PhrictionDocumentSearchEngine()) 16 16 ->setNavigation($this->buildSideNavView()); 17 17 18 18 return $this->delegateToController($controller);
+3 -39
src/applications/phriction/query/PhrictionDocumentQuery.php
··· 12 12 13 13 private $needContent; 14 14 15 - private $status = 'status-any'; 16 - const STATUS_ANY = 'status-any'; 17 - const STATUS_OPEN = 'status-open'; 18 - const STATUS_NONSTUB = 'status-nonstub'; 19 - 20 - const ORDER_HIERARCHY = 'order-hierarchy'; 15 + const ORDER_HIERARCHY = 'hierarchy'; 21 16 22 17 public function withIDs(array $ids) { 23 18 $this->ids = $ids; ··· 46 41 47 42 public function withStatuses(array $statuses) { 48 43 $this->statuses = $statuses; 49 - return $this; 50 - } 51 - 52 - public function withStatus($status) { 53 - $this->status = $status; 54 44 return $this; 55 45 } 56 46 ··· 224 214 $this->depths); 225 215 } 226 216 227 - switch ($this->status) { 228 - case self::STATUS_OPEN: 229 - $where[] = qsprintf( 230 - $conn, 231 - 'd.status NOT IN (%Ld)', 232 - array( 233 - PhrictionDocumentStatus::STATUS_DELETED, 234 - PhrictionDocumentStatus::STATUS_MOVED, 235 - PhrictionDocumentStatus::STATUS_STUB, 236 - )); 237 - break; 238 - case self::STATUS_NONSTUB: 239 - $where[] = qsprintf( 240 - $conn, 241 - 'd.status NOT IN (%Ld)', 242 - array( 243 - PhrictionDocumentStatus::STATUS_MOVED, 244 - PhrictionDocumentStatus::STATUS_STUB, 245 - )); 246 - break; 247 - case self::STATUS_ANY: 248 - break; 249 - default: 250 - throw new Exception(pht("Unknown status '%s'!", $this->status)); 251 - } 252 - 253 217 return $where; 254 218 } 255 219 256 220 public function getBuiltinOrders() { 257 - return array( 221 + return parent::getBuiltinOrders() + array( 258 222 self::ORDER_HIERARCHY => array( 259 223 'vector' => array('depth', 'title', 'updated'), 260 224 'name' => pht('Hierarchy'), 261 225 ), 262 - ) + parent::getBuiltinOrders(); 226 + ); 263 227 } 264 228 265 229 public function getOrderableColumns() {
+19 -25
src/applications/phriction/query/PhrictionSearchEngine.php src/applications/phriction/query/PhrictionDocumentSearchEngine.php
··· 1 1 <?php 2 2 3 - final class PhrictionSearchEngine 3 + final class PhrictionDocumentSearchEngine 4 4 extends PhabricatorApplicationSearchEngine { 5 5 6 6 public function getResultTypeDescription() { ··· 13 13 14 14 public function newQuery() { 15 15 return id(new PhrictionDocumentQuery()) 16 - ->needContent(true) 17 - ->withStatus(PhrictionDocumentQuery::STATUS_NONSTUB); 16 + ->needContent(true); 18 17 } 19 18 20 19 protected function buildQueryFromParameters(array $map) { 21 20 $query = $this->newQuery(); 22 21 23 - if ($map['status']) { 24 - $query->withStatus($map['status']); 22 + if ($map['statuses']) { 23 + $query->withStatuses($map['statuses']); 25 24 } 26 25 27 26 return $query; ··· 29 28 30 29 protected function buildCustomSearchFields() { 31 30 return array( 32 - id(new PhabricatorSearchSelectField()) 33 - ->setKey('status') 31 + id(new PhabricatorSearchCheckboxesField()) 32 + ->setKey('statuses') 34 33 ->setLabel(pht('Status')) 35 - ->setOptions($this->getStatusOptions()), 34 + ->setOptions(PhrictionDocumentStatus::getStatusMap()), 36 35 ); 37 36 } 38 37 ··· 59 58 return $query; 60 59 case 'active': 61 60 return $query->setParameter( 62 - 'status', PhrictionDocumentQuery::STATUS_OPEN); 61 + 'statuses', 62 + array( 63 + PhrictionDocumentStatus::STATUS_EXISTS, 64 + )); 63 65 } 64 66 65 67 return parent::buildSavedQueryFromBuiltin($query_key); 66 68 } 67 69 68 - private function getStatusOptions() { 69 - return array( 70 - PhrictionDocumentQuery::STATUS_OPEN => pht('Show Active Documents'), 71 - PhrictionDocumentQuery::STATUS_NONSTUB => pht('Show All Documents'), 72 - ); 73 - } 74 - 75 70 protected function getRequiredHandlePHIDsForResultList( 76 71 array $documents, 77 72 PhabricatorSavedQuery $query) { ··· 118 113 119 114 $item->addAttribute($slug_uri); 120 115 121 - switch ($document->getStatus()) { 122 - case PhrictionDocumentStatus::STATUS_DELETED: 123 - $item->setDisabled(true); 124 - $item->addIcon('delete', pht('Deleted')); 125 - break; 126 - case PhrictionDocumentStatus::STATUS_MOVED: 127 - $item->setDisabled(true); 128 - $item->addIcon('arrow-right', pht('Moved Away')); 129 - break; 116 + $icon = $document->getStatusIcon(); 117 + $color = $document->getStatusColor(); 118 + $label = $document->getStatusDisplayName(); 119 + 120 + $item->setStatusIcon("{$icon} {$color}", $label); 121 + 122 + if (!$document->isActive()) { 123 + $item->setDisabled(true); 130 124 } 131 125 132 126 $list->addItem($item);
+1 -1
src/applications/phriction/search/PhrictionDocumentFerretEngine.php
··· 12 12 } 13 13 14 14 public function newSearchEngine() { 15 - return new PhrictionSearchEngine(); 15 + return new PhrictionDocumentSearchEngine(); 16 16 } 17 17 18 18 }
+23
src/applications/phriction/storage/PhrictionDocument.php
··· 148 148 return $this; 149 149 } 150 150 151 + /* -( Status )------------------------------------------------------------- */ 152 + 153 + 154 + public function getStatusObject() { 155 + return PhrictionDocumentStatus::newStatusObject($this->getStatus()); 156 + } 157 + 158 + public function getStatusIcon() { 159 + return $this->getStatusObject()->getIcon(); 160 + } 161 + 162 + public function getStatusColor() { 163 + return $this->getStatusObject()->getColor(); 164 + } 165 + 166 + public function getStatusDisplayName() { 167 + return $this->getStatusObject()->getDisplayName(); 168 + } 169 + 170 + public function isActive() { 171 + return $this->getStatusObject()->isActive(); 172 + } 173 + 151 174 152 175 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 153 176