mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +01:00
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
This commit is contained in:
parent
dd3f4fd267
commit
15066e4fa0
2 changed files with 47 additions and 11 deletions
|
@ -9,7 +9,7 @@ final class LegalpadDocumentQuery
|
||||||
private $ids;
|
private $ids;
|
||||||
private $phids;
|
private $phids;
|
||||||
private $creatorPHIDs;
|
private $creatorPHIDs;
|
||||||
private $contributorPHIDs; // TODO - T3479
|
private $contributorPHIDs;
|
||||||
private $dateCreatedAfter;
|
private $dateCreatedAfter;
|
||||||
private $dateCreatedBefore;
|
private $dateCreatedBefore;
|
||||||
|
|
||||||
|
@ -62,8 +62,9 @@ final class LegalpadDocumentQuery
|
||||||
|
|
||||||
$data = queryfx_all(
|
$data = queryfx_all(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'SELECT legalpad_document.* FROM %T legalpad_document %Q %Q %Q',
|
'SELECT d.* FROM %T d %Q %Q %Q %Q',
|
||||||
$table->getTableName(),
|
$table->getTableName(),
|
||||||
|
$this->buildJoinClause($conn_r),
|
||||||
$this->buildWhereClause($conn_r),
|
$this->buildWhereClause($conn_r),
|
||||||
$this->buildOrderClause($conn_r),
|
$this->buildOrderClause($conn_r),
|
||||||
$this->buildLimitClause($conn_r));
|
$this->buildLimitClause($conn_r));
|
||||||
|
@ -89,6 +90,18 @@ final class LegalpadDocumentQuery
|
||||||
return $documents;
|
return $documents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildJoinClause($conn_r) {
|
||||||
|
$joins = array();
|
||||||
|
|
||||||
|
if ($this->contributorPHIDs) {
|
||||||
|
$joins[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'JOIN edge e ON e.src = d.phid');
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(' ', $joins);
|
||||||
|
}
|
||||||
|
|
||||||
protected function buildWhereClause($conn_r) {
|
protected function buildWhereClause($conn_r) {
|
||||||
$where = array();
|
$where = array();
|
||||||
|
|
||||||
|
@ -97,38 +110,46 @@ final class LegalpadDocumentQuery
|
||||||
if ($this->ids) {
|
if ($this->ids) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'id IN (%Ld)',
|
'd.id IN (%Ld)',
|
||||||
$this->ids);
|
$this->ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->phids) {
|
if ($this->phids) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'phid IN (%Ls)',
|
'd.phid IN (%Ls)',
|
||||||
$this->phids);
|
$this->phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->creatorPHIDs) {
|
if ($this->creatorPHIDs) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'creatorPHID IN (%Ls)',
|
'd.creatorPHID IN (%Ls)',
|
||||||
$this->creatorPHIDs);
|
$this->creatorPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->dateCreatedAfter) {
|
if ($this->dateCreatedAfter) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'dateCreated >= %d',
|
'd.dateCreated >= %d',
|
||||||
$this->dateCreatedAfter);
|
$this->dateCreatedAfter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->dateCreatedBefore) {
|
if ($this->dateCreatedBefore) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'dateCreated <= %d',
|
'd.dateCreated <= %d',
|
||||||
$this->dateCreatedBefore);
|
$this->dateCreatedBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->contributorPHIDs) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'e.type = %s AND e.dst IN (%Ls)',
|
||||||
|
PhabricatorEdgeConfig::TYPE_OBJECT_HAS_CONTRIBUTOR,
|
||||||
|
$this->contributorPHIDs);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->formatWhereClause($where);
|
return $this->formatWhereClause($where);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,10 @@ final class LegalpadDocumentSearchEngine
|
||||||
'creatorPHIDs',
|
'creatorPHIDs',
|
||||||
array_values($request->getArr('creators')));
|
array_values($request->getArr('creators')));
|
||||||
|
|
||||||
|
$saved->setParameter(
|
||||||
|
'contributorPHIDs',
|
||||||
|
array_values($request->getArr('contributors')));
|
||||||
|
|
||||||
$saved->setParameter('createdStart', $request->getStr('createdStart'));
|
$saved->setParameter('createdStart', $request->getStr('createdStart'));
|
||||||
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
|
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
|
||||||
|
|
||||||
|
@ -22,7 +26,8 @@ final class LegalpadDocumentSearchEngine
|
||||||
$query = id(new LegalpadDocumentQuery())
|
$query = id(new LegalpadDocumentQuery())
|
||||||
->needDocumentBodies(true)
|
->needDocumentBodies(true)
|
||||||
->needContributors(true)
|
->needContributors(true)
|
||||||
->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array()));
|
->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array()))
|
||||||
|
->withContributorPHIDs($saved->getParameter('contributorPHIDs', array()));
|
||||||
|
|
||||||
$start = $this->parseDateTime($saved->getParameter('createdStart'));
|
$start = $this->parseDateTime($saved->getParameter('createdStart'));
|
||||||
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
|
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
|
||||||
|
@ -41,11 +46,15 @@ final class LegalpadDocumentSearchEngine
|
||||||
public function buildSearchForm(
|
public function buildSearchForm(
|
||||||
AphrontFormView $form,
|
AphrontFormView $form,
|
||||||
PhabricatorSavedQuery $saved_query) {
|
PhabricatorSavedQuery $saved_query) {
|
||||||
$phids = $saved_query->getParameter('creatorPHIDs', array());
|
|
||||||
|
$creator_phids = $saved_query->getParameter('creatorPHIDs', array());
|
||||||
|
$contributor_phids = $saved_query->getParameter(
|
||||||
|
'contributorPHIDs', array());
|
||||||
|
$phids = array_merge($creator_phids, $contributor_phids);
|
||||||
$handles = id(new PhabricatorObjectHandleData($phids))
|
$handles = id(new PhabricatorObjectHandleData($phids))
|
||||||
->setViewer($this->requireViewer())
|
->setViewer($this->requireViewer())
|
||||||
->loadHandles();
|
->loadHandles();
|
||||||
$creator_tokens = mpull($handles, 'getFullName', 'getPHID');
|
$tokens = mpull($handles, 'getFullName', 'getPHID');
|
||||||
|
|
||||||
$form
|
$form
|
||||||
->appendChild(
|
->appendChild(
|
||||||
|
@ -53,7 +62,13 @@ final class LegalpadDocumentSearchEngine
|
||||||
->setDatasource('/typeahead/common/users/')
|
->setDatasource('/typeahead/common/users/')
|
||||||
->setName('creators')
|
->setName('creators')
|
||||||
->setLabel(pht('Creators'))
|
->setLabel(pht('Creators'))
|
||||||
->setValue($creator_tokens));
|
->setValue(array_select_keys($tokens, $creator_phids)))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormTokenizerControl())
|
||||||
|
->setDatasource('/typeahead/common/users/')
|
||||||
|
->setName('contributors')
|
||||||
|
->setLabel(pht('Contributors'))
|
||||||
|
->setValue(array_select_keys($tokens, $contributor_phids)));
|
||||||
|
|
||||||
$this->buildDateRange(
|
$this->buildDateRange(
|
||||||
$form,
|
$form,
|
||||||
|
|
Loading…
Reference in a new issue