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

Lightly modernize LegalpadDocumentQuery

Summary: Ref T13024. Updates LegalpadDocumentQuery to use slightly more modern constructions.

Test Plan: Queried for Legalpad documents, got the same results.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13024

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

+33 -38
+33 -38
src/applications/legalpad/query/LegalpadDocumentQuery.php
··· 77 77 return $this; 78 78 } 79 79 80 + public function newResultObject() { 81 + return new LegalpadDocument(); 82 + } 83 + 80 84 protected function loadPage() { 81 - $table = new LegalpadDocument(); 82 - $conn_r = $table->establishConnection('r'); 83 - 84 - $data = queryfx_all( 85 - $conn_r, 86 - 'SELECT d.* FROM %T d %Q %Q %Q %Q %Q', 87 - $table->getTableName(), 88 - $this->buildJoinClause($conn_r), 89 - $this->buildWhereClause($conn_r), 90 - $this->buildGroupClause($conn_r), 91 - $this->buildOrderClause($conn_r), 92 - $this->buildLimitClause($conn_r)); 93 - 94 - $documents = $table->loadAllFromArray($data); 95 - 96 - return $documents; 85 + return $this->loadStandardPage($this->newResultObject()); 97 86 } 98 87 99 88 protected function willFilterPage(array $documents) { ··· 134 123 return $documents; 135 124 } 136 125 137 - protected function buildJoinClause(AphrontDatabaseConnection $conn_r) { 138 - $joins = array(); 126 + protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 127 + $joins = parent::buildJoinClauseParts($conn); 139 128 140 129 if ($this->contributorPHIDs !== null) { 141 130 $joins[] = qsprintf( 142 - $conn_r, 131 + $conn, 143 132 'JOIN edge contributor ON contributor.src = d.phid 144 133 AND contributor.type = %d', 145 134 PhabricatorObjectHasContributorEdgeType::EDGECONST); ··· 147 136 148 137 if ($this->signerPHIDs !== null) { 149 138 $joins[] = qsprintf( 150 - $conn_r, 139 + $conn, 151 140 'JOIN %T signer ON signer.documentPHID = d.phid 152 141 AND signer.signerPHID IN (%Ls)', 153 142 id(new LegalpadDocumentSignature())->getTableName(), 154 143 $this->signerPHIDs); 155 144 } 156 145 157 - return implode(' ', $joins); 146 + return $joins; 158 147 } 159 148 160 - protected function buildGroupClause(AphrontDatabaseConnection $conn_r) { 161 - if ($this->contributorPHIDs || $this->signerPHIDs) { 162 - return 'GROUP BY d.id'; 163 - } else { 164 - return ''; 149 + protected function shouldGroupQueryResultRows() { 150 + if ($this->contributorPHIDs) { 151 + return true; 152 + } 153 + 154 + if ($this->signerPHIDs) { 155 + return true; 165 156 } 157 + 158 + return parent::shouldGroupQueryResultRows(); 166 159 } 167 160 168 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 169 - $where = array(); 161 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 162 + $where = parent::buildWhereClauseParts($conn); 170 163 171 164 if ($this->ids !== null) { 172 165 $where[] = qsprintf( 173 - $conn_r, 166 + $conn, 174 167 'd.id IN (%Ld)', 175 168 $this->ids); 176 169 } 177 170 178 171 if ($this->phids !== null) { 179 172 $where[] = qsprintf( 180 - $conn_r, 173 + $conn, 181 174 'd.phid IN (%Ls)', 182 175 $this->phids); 183 176 } 184 177 185 178 if ($this->creatorPHIDs !== null) { 186 179 $where[] = qsprintf( 187 - $conn_r, 180 + $conn, 188 181 'd.creatorPHID IN (%Ls)', 189 182 $this->creatorPHIDs); 190 183 } 191 184 192 185 if ($this->dateCreatedAfter !== null) { 193 186 $where[] = qsprintf( 194 - $conn_r, 187 + $conn, 195 188 'd.dateCreated >= %d', 196 189 $this->dateCreatedAfter); 197 190 } 198 191 199 192 if ($this->dateCreatedBefore !== null) { 200 193 $where[] = qsprintf( 201 - $conn_r, 194 + $conn, 202 195 'd.dateCreated <= %d', 203 196 $this->dateCreatedBefore); 204 197 } 205 198 206 199 if ($this->contributorPHIDs !== null) { 207 200 $where[] = qsprintf( 208 - $conn_r, 201 + $conn, 209 202 'contributor.dst IN (%Ls)', 210 203 $this->contributorPHIDs); 211 204 } 212 205 213 206 if ($this->signatureRequired !== null) { 214 207 $where[] = qsprintf( 215 - $conn_r, 208 + $conn, 216 209 'd.requireSignature = %d', 217 210 $this->signatureRequired); 218 211 } 219 212 220 - $where[] = $this->buildPagingClause($conn_r); 221 - 222 - return $this->formatWhereClause($where); 213 + return $where; 223 214 } 224 215 225 216 private function loadDocumentBodies(array $documents) { ··· 273 264 274 265 public function getQueryApplicationClass() { 275 266 return 'PhabricatorLegalpadApplication'; 267 + } 268 + 269 + protected function getPrimaryTableAlias() { 270 + return 'd'; 276 271 } 277 272 278 273 }