2014-05-11 00:21:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionLintCountQuery extends PhabricatorQuery {
|
|
|
|
|
|
|
|
private $branchIDs;
|
|
|
|
private $paths;
|
|
|
|
private $codes;
|
|
|
|
|
|
|
|
public function withBranchIDs(array $branch_ids) {
|
|
|
|
$this->branchIDs = $branch_ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withPaths(array $paths) {
|
|
|
|
$this->paths = $paths;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withCodes(array $codes) {
|
|
|
|
$this->codes = $codes;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
if (!$this->paths) {
|
2015-05-13 23:53:52 +02:00
|
|
|
throw new PhutilInvalidStateException('withPaths');
|
2014-05-11 00:21:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->branchIDs) {
|
2015-05-13 23:53:52 +02:00
|
|
|
throw new PhutilInvalidStateException('withBranchIDs');
|
2014-05-11 00:21:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$conn_r = id(new PhabricatorRepositoryCommit())->establishConnection('r');
|
|
|
|
|
|
|
|
$this->paths = array_unique($this->paths);
|
|
|
|
list($dirs, $paths) = $this->processPaths();
|
|
|
|
|
|
|
|
$parts = array();
|
|
|
|
foreach ($dirs as $dir) {
|
|
|
|
$parts[$dir] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'path LIKE %>',
|
|
|
|
$dir);
|
|
|
|
}
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
$parts[$path] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'path = %s',
|
|
|
|
$path);
|
|
|
|
}
|
|
|
|
|
|
|
|
$queries = array();
|
|
|
|
foreach ($parts as $key => $part) {
|
|
|
|
$queries[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT %s path_prefix, COUNT(*) N FROM %T %Q',
|
|
|
|
$key,
|
|
|
|
PhabricatorRepository::TABLE_LINTMESSAGE,
|
Make buildWhereClause() a method of AphrontCursorPagedPolicyAwareQuery
Summary:
Ref T4100. Ref T5595.
To support a unified "Projects:" query across all applications, a future diff is going to add a set of "Edge Logic" capabilities to `PolicyAwareQuery` which write the required SELECT, JOIN, WHERE, HAVING and GROUP clauses for you.
With the addition of "Edge Logic", we'll have three systems which may need to build components of query claues: ordering/paging, customfields/applicationsearch, and edge logic.
For most clauses, queries don't currently call into the parent explicitly to get default components. I want to move more query construction logic up the class tree so it can be shared.
For most methods, this isn't a problem, but many subclasses define a `buildWhereClause()`. Make all such definitions protected and consistent.
This causes no behavioral changes.
Test Plan: Ran `arc unit --everything`, which does a pretty through job of verifying this statically.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: yelirekim, hach-que, epriestley
Maniphest Tasks: T4100, T5595
Differential Revision: https://secure.phabricator.com/D12453
2015-04-18 16:08:30 +02:00
|
|
|
$this->buildCustomWhereClause($conn_r, $part));
|
2014-05-11 00:21:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$huge_union_query = '('.implode(') UNION ALL (', $queries).')';
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'%Q',
|
|
|
|
$huge_union_query);
|
|
|
|
|
|
|
|
return $this->processResults($data);
|
|
|
|
}
|
|
|
|
|
Make buildWhereClause() a method of AphrontCursorPagedPolicyAwareQuery
Summary:
Ref T4100. Ref T5595.
To support a unified "Projects:" query across all applications, a future diff is going to add a set of "Edge Logic" capabilities to `PolicyAwareQuery` which write the required SELECT, JOIN, WHERE, HAVING and GROUP clauses for you.
With the addition of "Edge Logic", we'll have three systems which may need to build components of query claues: ordering/paging, customfields/applicationsearch, and edge logic.
For most clauses, queries don't currently call into the parent explicitly to get default components. I want to move more query construction logic up the class tree so it can be shared.
For most methods, this isn't a problem, but many subclasses define a `buildWhereClause()`. Make all such definitions protected and consistent.
This causes no behavioral changes.
Test Plan: Ran `arc unit --everything`, which does a pretty through job of verifying this statically.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: yelirekim, hach-que, epriestley
Maniphest Tasks: T4100, T5595
Differential Revision: https://secure.phabricator.com/D12453
2015-04-18 16:08:30 +02:00
|
|
|
protected function buildCustomWhereClause(
|
|
|
|
AphrontDatabaseConnection $conn_r,
|
|
|
|
$part) {
|
|
|
|
|
2014-05-11 00:21:05 +02:00
|
|
|
$where = array();
|
|
|
|
|
|
|
|
$where[] = $part;
|
|
|
|
|
|
|
|
if ($this->codes !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'code IN (%Ls)',
|
|
|
|
$this->codes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->branchIDs !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'branchID IN (%Ld)',
|
|
|
|
$this->branchIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function processPaths() {
|
|
|
|
$dirs = array();
|
|
|
|
$paths = array();
|
|
|
|
foreach ($this->paths as $path) {
|
|
|
|
$path = '/'.$path;
|
|
|
|
if (substr($path, -1) == '/') {
|
|
|
|
$dirs[] = $path;
|
|
|
|
} else {
|
|
|
|
$paths[] = $path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array($dirs, $paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function processResults(array $data) {
|
|
|
|
$data = ipull($data, 'N', 'path_prefix');
|
|
|
|
|
|
|
|
// Strip the leading "/" back off each path.
|
|
|
|
$output = array();
|
|
|
|
foreach ($data as $path => $count) {
|
|
|
|
$output[substr($path, 1)] = $count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|