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

Update PhrictionSearchEngine, implement Projects

Summary: Implements new search engine, projects into Phriction.

Test Plan: Test new search choices, add project to Phriction page. Verify hierarchy still works, setting policy works, etc.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Luke081515.2, Korvin

Maniphest Tasks: T9622

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

+86 -125
+2 -1
src/__phutil_library_map__.php
··· 9359 9359 'PhabricatorFlaggableInterface', 9360 9360 'PhabricatorTokenReceiverInterface', 9361 9361 'PhabricatorDestructibleInterface', 9362 + 'PhabricatorFulltextInterface', 9363 + 'PhabricatorProjectInterface', 9362 9364 'PhabricatorApplicationTransactionInterface', 9363 - 'PhabricatorFulltextInterface', 9364 9365 ), 9365 9366 'PhrictionDocumentAuthorHeraldField' => 'PhrictionDocumentHeraldField', 9366 9367 'PhrictionDocumentContentHeraldField' => 'PhrictionDocumentHeraldField',
+27 -6
src/applications/phriction/controller/PhrictionEditController.php
··· 9 9 10 10 $current_version = null; 11 11 if ($id) { 12 + $is_new = false; 12 13 $document = id(new PhrictionDocumentQuery()) 13 14 ->setViewer($viewer) 14 15 ->withIDs(array($id)) ··· 54 55 if ($document) { 55 56 $content = $document->getContent(); 56 57 $current_version = $content->getVersion(); 58 + $is_new = false; 57 59 } else { 58 60 $document = PhrictionDocument::initializeNewDocument($viewer, $slug); 59 61 $content = $document->getContent(); 62 + $is_new = true; 60 63 } 61 64 } 62 65 ··· 91 94 $draft_note->setSeverity(PHUIInfoView::SEVERITY_NOTICE); 92 95 $draft_note->setTitle(pht('Recovered Draft')); 93 96 $draft_note->appendChild( 94 - hsprintf( 95 - '<p>%s</p>', 96 - pht( 97 - 'Showing a saved draft of your edits, you can %s.', 98 - $discard))); 97 + pht('Showing a saved draft of your edits, you can %s.', $discard)); 99 98 } else { 100 99 $content_text = $content->getContent(); 101 100 $draft_note = null; ··· 112 111 $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID( 113 112 $document->getPHID()); 114 113 114 + if ($is_new) { 115 + $v_projects = array(); 116 + } else { 117 + $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( 118 + $document->getPHID(), 119 + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 120 + $v_projects = array_reverse($v_projects); 121 + } 122 + 115 123 if ($request->isFormPost()) { 116 124 117 125 $title = $request->getStr('title'); ··· 120 128 $current_version = $request->getInt('contentVersion'); 121 129 $v_view = $request->getStr('viewPolicy'); 122 130 $v_edit = $request->getStr('editPolicy'); 123 - $v_cc = $request->getArr('cc'); 131 + $v_cc = $request->getArr('cc'); 132 + $v_projects = $request->getArr('projects'); 124 133 125 134 $xactions = array(); 126 135 $xactions[] = id(new PhrictionTransaction()) ··· 138 147 $xactions[] = id(new PhrictionTransaction()) 139 148 ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) 140 149 ->setNewValue(array('=' => $v_cc)); 150 + 151 + $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 152 + $xactions[] = id(new PhrictionTransaction()) 153 + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 154 + ->setMetadataValue('edge:type', $proj_edge_type) 155 + ->setNewValue(array('=' => array_fuse($v_projects))); 141 156 142 157 $editor = id(new PhrictionTransactionEditor()) 143 158 ->setActor($viewer) ··· 230 245 ->setName('content') 231 246 ->setID('document-textarea') 232 247 ->setUser($viewer)) 248 + ->appendControl( 249 + id(new AphrontFormTokenizerControl()) 250 + ->setLabel(pht('Projects')) 251 + ->setName('projects') 252 + ->setValue($v_projects) 253 + ->setDatasource(new PhabricatorProjectDatasource())) 233 254 ->appendControl( 234 255 id(new AphrontFormTokenizerControl()) 235 256 ->setLabel(pht('Subscribers'))
+2 -1
src/applications/phriction/editor/PhrictionTransactionEditor.php
··· 80 80 public function getTransactionTypes() { 81 81 $types = parent::getTransactionTypes(); 82 82 83 - $types[] = PhabricatorTransactions::TYPE_COMMENT; 84 83 $types[] = PhrictionTransaction::TYPE_TITLE; 85 84 $types[] = PhrictionTransaction::TYPE_CONTENT; 86 85 $types[] = PhrictionTransaction::TYPE_DELETE; 87 86 $types[] = PhrictionTransaction::TYPE_MOVE_TO; 88 87 $types[] = PhrictionTransaction::TYPE_MOVE_AWAY; 89 88 89 + $types[] = PhabricatorTransactions::TYPE_EDGE; 90 + $types[] = PhabricatorTransactions::TYPE_COMMENT; 90 91 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 91 92 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 92 93
+33 -50
src/applications/phriction/query/PhrictionDocumentQuery.php
··· 17 17 const STATUS_OPEN = 'status-open'; 18 18 const STATUS_NONSTUB = 'status-nonstub'; 19 19 20 - const ORDER_CREATED = 'order-created'; 21 - const ORDER_UPDATED = 'order-updated'; 22 20 const ORDER_HIERARCHY = 'order-hierarchy'; 23 21 24 22 public function withIDs(array $ids) { ··· 61 59 return $this; 62 60 } 63 61 64 - public function setOrder($order) { 65 - switch ($order) { 66 - case self::ORDER_CREATED: 67 - $this->setOrderVector(array('id')); 68 - break; 69 - case self::ORDER_UPDATED: 70 - $this->setOrderVector(array('updated')); 71 - break; 72 - case self::ORDER_HIERARCHY: 73 - $this->setOrderVector(array('depth', 'title', 'updated')); 74 - break; 75 - default: 76 - throw new Exception(pht('Unknown order "%s".', $order)); 77 - } 78 - 79 - return $this; 80 - } 81 - 82 62 protected function loadPage() { 83 - $table = new PhrictionDocument(); 84 - $conn_r = $table->establishConnection('r'); 63 + return $this->loadStandardPage($this->newResultObject()); 64 + } 85 65 86 - $rows = queryfx_all( 87 - $conn_r, 88 - 'SELECT d.* FROM %T d %Q %Q %Q %Q', 89 - $table->getTableName(), 90 - $this->buildJoinClause($conn_r), 91 - $this->buildWhereClause($conn_r), 92 - $this->buildOrderClause($conn_r), 93 - $this->buildLimitClause($conn_r)); 66 + public function newResultObject() { 67 + return new PhrictionDocument(); 68 + } 94 69 95 - $documents = $table->loadAllFromArray($rows); 70 + protected function willFilterPage(array $documents) { 96 71 97 72 if ($documents) { 98 73 $ancestor_slugs = array(); ··· 104 79 } 105 80 106 81 if ($ancestor_slugs) { 82 + $table = new PhrictionDocument(); 83 + $conn_r = $table->establishConnection('r'); 107 84 $ancestors = queryfx_all( 108 85 $conn_r, 109 86 'SELECT * FROM %T WHERE slug IN (%Ls)', ··· 122 99 } 123 100 } 124 101 } 125 - 126 - return $documents; 127 - } 128 - 129 - protected function willFilterPage(array $documents) { 130 102 // To view a Phriction document, you must also be able to view all of the 131 103 // ancestor documents. Filter out documents which have ancestors that are 132 104 // not visible. ··· 190 162 return $documents; 191 163 } 192 164 193 - protected function buildJoinClause(AphrontDatabaseConnection $conn) { 194 - $join = ''; 165 + protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 166 + $joins = array(); 195 167 196 168 if ($this->getOrderVector()->containsKey('updated')) { 197 169 $content_dao = new PhrictionContent(); 198 - $join = qsprintf( 170 + $joins[] = qsprintf( 199 171 $conn, 200 172 'JOIN %T c ON d.contentID = c.id', 201 173 $content_dao->getTableName()); 202 174 } 203 175 204 - return $join; 176 + return $joins; 205 177 } 206 - protected function buildWhereClause(AphrontDatabaseConnection $conn) { 207 - $where = array(); 178 + 179 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 180 + $where = parent::buildWhereClauseParts($conn); 208 181 209 - if ($this->ids) { 182 + if ($this->ids !== null) { 210 183 $where[] = qsprintf( 211 184 $conn, 212 185 'd.id IN (%Ld)', 213 186 $this->ids); 214 187 } 215 188 216 - if ($this->phids) { 189 + if ($this->phids !== null) { 217 190 $where[] = qsprintf( 218 191 $conn, 219 192 'd.phid IN (%Ls)', 220 193 $this->phids); 221 194 } 222 195 223 - if ($this->slugs) { 196 + if ($this->slugs !== null) { 224 197 $where[] = qsprintf( 225 198 $conn, 226 199 'd.slug IN (%Ls)', 227 200 $this->slugs); 228 201 } 229 202 230 - if ($this->statuses) { 203 + if ($this->statuses !== null) { 231 204 $where[] = qsprintf( 232 205 $conn, 233 206 'd.status IN (%Ld)', 234 207 $this->statuses); 235 208 } 236 209 237 - if ($this->slugPrefix) { 210 + if ($this->slugPrefix !== null) { 238 211 $where[] = qsprintf( 239 212 $conn, 240 213 'd.slug LIKE %>', 241 214 $this->slugPrefix); 242 215 } 243 216 244 - if ($this->depths) { 217 + if ($this->depths !== null) { 245 218 $where[] = qsprintf( 246 219 $conn, 247 220 'd.depth IN (%Ld)', ··· 274 247 throw new Exception(pht("Unknown status '%s'!", $this->status)); 275 248 } 276 249 277 - $where[] = $this->buildPagingClause($conn); 250 + return $where; 251 + } 278 252 279 - return $this->formatWhereClause($where); 253 + public function getBuiltinOrders() { 254 + return array( 255 + self::ORDER_HIERARCHY => array( 256 + 'vector' => array('depth', 'title', 'updated'), 257 + 'name' => pht('Hierarchy'), 258 + ), 259 + ) + parent::getBuiltinOrders(); 280 260 } 281 261 282 262 public function getOrderableColumns() { ··· 331 311 } 332 312 } 333 313 314 + protected function getPrimaryTableAlias() { 315 + return 'd'; 316 + } 334 317 335 318 public function getQueryApplicationClass() { 336 319 return 'PhabricatorPhrictionApplication';
+19 -65
src/applications/phriction/query/PhrictionSearchEngine.php
··· 11 11 return 'PhabricatorPhrictionApplication'; 12 12 } 13 13 14 - public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 - $saved = new PhabricatorSavedQuery(); 16 - 17 - $saved->setParameter('status', $request->getStr('status')); 18 - $saved->setParameter('order', $request->getStr('order')); 19 - 20 - return $saved; 21 - } 22 - 23 - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 24 - $query = id(new PhrictionDocumentQuery()) 14 + public function newQuery() { 15 + return id(new PhrictionDocumentQuery()) 25 16 ->needContent(true) 26 17 ->withStatus(PhrictionDocumentQuery::STATUS_NONSTUB); 18 + } 27 19 28 - $status = $saved->getParameter('status'); 29 - $status = idx($this->getStatusValues(), $status); 30 - if ($status) { 31 - $query->withStatus($status); 32 - } 20 + protected function buildQueryFromParameters(array $map) { 21 + $query = $this->newQuery(); 33 22 34 - $order = $saved->getParameter('order'); 35 - $order = idx($this->getOrderValues(), $order); 36 - if ($order) { 37 - $query->setOrder($order); 23 + if ($map['status']) { 24 + $query->withStatus($map['status']); 38 25 } 39 26 40 27 return $query; 41 28 } 42 29 43 - public function buildSearchForm( 44 - AphrontFormView $form, 45 - PhabricatorSavedQuery $saved_query) { 46 - 47 - $form 48 - ->appendChild( 49 - id(new AphrontFormSelectControl()) 50 - ->setLabel(pht('Status')) 51 - ->setName('status') 52 - ->setOptions($this->getStatusOptions()) 53 - ->setValue($saved_query->getParameter('status'))) 54 - ->appendChild( 55 - id(new AphrontFormSelectControl()) 56 - ->setLabel(pht('Order')) 57 - ->setName('order') 58 - ->setOptions($this->getOrderOptions()) 59 - ->setValue($saved_query->getParameter('order'))); 30 + protected function buildCustomSearchFields() { 31 + return array( 32 + id(new PhabricatorSearchSelectField()) 33 + ->setKey('status') 34 + ->setLabel(pht('Status')) 35 + ->setOptions($this->getStatusOptions()), 36 + ); 60 37 } 61 38 62 39 protected function getURI($path) { ··· 66 43 protected function getBuiltinQueryNames() { 67 44 $names = array( 68 45 'active' => pht('Active'), 69 - 'updated' => pht('Updated'), 70 46 'all' => pht('All'), 71 47 ); 72 48 ··· 79 55 $query->setQueryKey($query_key); 80 56 81 57 switch ($query_key) { 82 - case 'active': 83 - return $query->setParameter('status', 'active'); 84 58 case 'all': 85 59 return $query; 86 - case 'updated': 87 - return $query->setParameter('order', 'updated'); 60 + case 'active': 61 + return $query->setParameter( 62 + 'status', PhrictionDocumentQuery::STATUS_OPEN); 88 63 } 89 64 90 65 return parent::buildSavedQueryFromBuiltin($query_key); ··· 92 67 93 68 private function getStatusOptions() { 94 69 return array( 95 - 'active' => pht('Show Active Documents'), 96 - 'all' => pht('Show All Documents'), 97 - ); 98 - } 99 - 100 - private function getStatusValues() { 101 - return array( 102 - 'active' => PhrictionDocumentQuery::STATUS_OPEN, 103 - 'all' => PhrictionDocumentQuery::STATUS_NONSTUB, 104 - ); 105 - } 106 - 107 - private function getOrderOptions() { 108 - return array( 109 - 'created' => pht('Date Created'), 110 - 'updated' => pht('Date Updated'), 111 - ); 112 - } 113 - 114 - private function getOrderValues() { 115 - return array( 116 - 'created' => PhrictionDocumentQuery::ORDER_CREATED, 117 - 'updated' => PhrictionDocumentQuery::ORDER_UPDATED, 70 + PhrictionDocumentQuery::STATUS_OPEN => pht('Show Active Documents'), 71 + PhrictionDocumentQuery::STATUS_NONSTUB => pht('Show All Documents'), 118 72 ); 119 73 } 120 74
+3 -2
src/applications/phriction/storage/PhrictionDocument.php
··· 7 7 PhabricatorFlaggableInterface, 8 8 PhabricatorTokenReceiverInterface, 9 9 PhabricatorDestructibleInterface, 10 - PhabricatorApplicationTransactionInterface, 11 - PhabricatorFulltextInterface { 10 + PhabricatorFulltextInterface, 11 + PhabricatorProjectInterface, 12 + PhabricatorApplicationTransactionInterface { 12 13 13 14 protected $slug; 14 15 protected $depth;