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

Legalpad - add support for querying by contributors

Summary: Fixes T3479

Test Plan: queried for contributors and got good results. tried a complex query with all possible values specified and got results when appropos.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T3479

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

+47 -11
+28 -7
src/applications/legalpad/query/LegalpadDocumentQuery.php
··· 9 9 private $ids; 10 10 private $phids; 11 11 private $creatorPHIDs; 12 - private $contributorPHIDs; // TODO - T3479 12 + private $contributorPHIDs; 13 13 private $dateCreatedAfter; 14 14 private $dateCreatedBefore; 15 15 ··· 62 62 63 63 $data = queryfx_all( 64 64 $conn_r, 65 - 'SELECT legalpad_document.* FROM %T legalpad_document %Q %Q %Q', 65 + 'SELECT d.* FROM %T d %Q %Q %Q %Q', 66 66 $table->getTableName(), 67 + $this->buildJoinClause($conn_r), 67 68 $this->buildWhereClause($conn_r), 68 69 $this->buildOrderClause($conn_r), 69 70 $this->buildLimitClause($conn_r)); ··· 89 90 return $documents; 90 91 } 91 92 93 + private function buildJoinClause($conn_r) { 94 + $joins = array(); 95 + 96 + if ($this->contributorPHIDs) { 97 + $joins[] = qsprintf( 98 + $conn_r, 99 + 'JOIN edge e ON e.src = d.phid'); 100 + } 101 + 102 + return implode(' ', $joins); 103 + } 104 + 92 105 protected function buildWhereClause($conn_r) { 93 106 $where = array(); 94 107 ··· 97 110 if ($this->ids) { 98 111 $where[] = qsprintf( 99 112 $conn_r, 100 - 'id IN (%Ld)', 113 + 'd.id IN (%Ld)', 101 114 $this->ids); 102 115 } 103 116 104 117 if ($this->phids) { 105 118 $where[] = qsprintf( 106 119 $conn_r, 107 - 'phid IN (%Ls)', 120 + 'd.phid IN (%Ls)', 108 121 $this->phids); 109 122 } 110 123 111 124 if ($this->creatorPHIDs) { 112 125 $where[] = qsprintf( 113 126 $conn_r, 114 - 'creatorPHID IN (%Ls)', 127 + 'd.creatorPHID IN (%Ls)', 115 128 $this->creatorPHIDs); 116 129 } 117 130 118 131 if ($this->dateCreatedAfter) { 119 132 $where[] = qsprintf( 120 133 $conn_r, 121 - 'dateCreated >= %d', 134 + 'd.dateCreated >= %d', 122 135 $this->dateCreatedAfter); 123 136 } 124 137 125 138 if ($this->dateCreatedBefore) { 126 139 $where[] = qsprintf( 127 140 $conn_r, 128 - 'dateCreated <= %d', 141 + 'd.dateCreated <= %d', 129 142 $this->dateCreatedBefore); 143 + } 144 + 145 + if ($this->contributorPHIDs) { 146 + $where[] = qsprintf( 147 + $conn_r, 148 + 'e.type = %s AND e.dst IN (%Ls)', 149 + PhabricatorEdgeConfig::TYPE_OBJECT_HAS_CONTRIBUTOR, 150 + $this->contributorPHIDs); 130 151 } 131 152 132 153 return $this->formatWhereClause($where);
+19 -4
src/applications/legalpad/query/LegalpadDocumentSearchEngine.php
··· 12 12 'creatorPHIDs', 13 13 array_values($request->getArr('creators'))); 14 14 15 + $saved->setParameter( 16 + 'contributorPHIDs', 17 + array_values($request->getArr('contributors'))); 18 + 15 19 $saved->setParameter('createdStart', $request->getStr('createdStart')); 16 20 $saved->setParameter('createdEnd', $request->getStr('createdEnd')); 17 21 ··· 22 26 $query = id(new LegalpadDocumentQuery()) 23 27 ->needDocumentBodies(true) 24 28 ->needContributors(true) 25 - ->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array())); 29 + ->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array())) 30 + ->withContributorPHIDs($saved->getParameter('contributorPHIDs', array())); 26 31 27 32 $start = $this->parseDateTime($saved->getParameter('createdStart')); 28 33 $end = $this->parseDateTime($saved->getParameter('createdEnd')); ··· 41 46 public function buildSearchForm( 42 47 AphrontFormView $form, 43 48 PhabricatorSavedQuery $saved_query) { 44 - $phids = $saved_query->getParameter('creatorPHIDs', array()); 49 + 50 + $creator_phids = $saved_query->getParameter('creatorPHIDs', array()); 51 + $contributor_phids = $saved_query->getParameter( 52 + 'contributorPHIDs', array()); 53 + $phids = array_merge($creator_phids, $contributor_phids); 45 54 $handles = id(new PhabricatorObjectHandleData($phids)) 46 55 ->setViewer($this->requireViewer()) 47 56 ->loadHandles(); 48 - $creator_tokens = mpull($handles, 'getFullName', 'getPHID'); 57 + $tokens = mpull($handles, 'getFullName', 'getPHID'); 49 58 50 59 $form 51 60 ->appendChild( ··· 53 62 ->setDatasource('/typeahead/common/users/') 54 63 ->setName('creators') 55 64 ->setLabel(pht('Creators')) 56 - ->setValue($creator_tokens)); 65 + ->setValue(array_select_keys($tokens, $creator_phids))) 66 + ->appendChild( 67 + id(new AphrontFormTokenizerControl()) 68 + ->setDatasource('/typeahead/common/users/') 69 + ->setName('contributors') 70 + ->setLabel(pht('Contributors')) 71 + ->setValue(array_select_keys($tokens, $contributor_phids))); 57 72 58 73 $this->buildDateRange( 59 74 $form,