2016-01-28 05:21:38 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
final class PhabricatorRepositoryPullEventQuery
|
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
|
|
private $ids;
|
|
|
|
|
private $phids;
|
|
|
|
|
private $repositoryPHIDs;
|
|
|
|
|
private $pullerPHIDs;
|
2018-01-30 11:47:55 -08:00
|
|
|
private $epochMin;
|
|
|
|
|
private $epochMax;
|
2016-01-28 05:21:38 -08:00
|
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
|
$this->ids = $ids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
|
$this->phids = $phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withRepositoryPHIDs(array $repository_phids) {
|
|
|
|
|
$this->repositoryPHIDs = $repository_phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withPullerPHIDs(array $puller_phids) {
|
|
|
|
|
$this->pullerPHIDs = $puller_phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 11:47:55 -08:00
|
|
|
public function withEpochBetween($min, $max) {
|
|
|
|
|
$this->epochMin = $min;
|
|
|
|
|
$this->epochMax = $max;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:21:38 -08:00
|
|
|
public function newResultObject() {
|
|
|
|
|
return new PhabricatorRepositoryPullEvent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function loadPage() {
|
|
|
|
|
return $this->loadStandardPage($this->newResultObject());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function willFilterPage(array $events) {
|
2018-01-22 20:09:52 -08:00
|
|
|
// If a pull targets an invalid repository or fails before authenticating,
|
|
|
|
|
// it may not have an associated repository.
|
|
|
|
|
|
2016-01-28 05:21:38 -08:00
|
|
|
$repository_phids = mpull($events, 'getRepositoryPHID');
|
2018-01-22 20:09:52 -08:00
|
|
|
$repository_phids = array_filter($repository_phids);
|
|
|
|
|
|
|
|
|
|
if ($repository_phids) {
|
|
|
|
|
$repositories = id(new PhabricatorRepositoryQuery())
|
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
|
->withPHIDs($repository_phids)
|
|
|
|
|
->execute();
|
|
|
|
|
$repositories = mpull($repositories, null, 'getPHID');
|
|
|
|
|
} else {
|
|
|
|
|
$repositories = array();
|
|
|
|
|
}
|
2016-01-28 05:21:38 -08:00
|
|
|
|
|
|
|
|
foreach ($events as $key => $event) {
|
|
|
|
|
$phid = $event->getRepositoryPHID();
|
2018-01-22 20:09:52 -08:00
|
|
|
if (!$phid) {
|
|
|
|
|
$event->attachRepository(null);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:21:38 -08:00
|
|
|
if (empty($repositories[$phid])) {
|
|
|
|
|
unset($events[$key]);
|
2018-01-22 20:09:52 -08:00
|
|
|
$this->didRejectResult($event);
|
2016-01-28 05:21:38 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
2018-01-22 20:09:52 -08:00
|
|
|
|
2016-01-28 05:21:38 -08:00
|
|
|
$event->attachRepository($repositories[$phid]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $events;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
|
$where = parent::buildWhereClauseParts($conn);
|
|
|
|
|
|
|
|
|
|
if ($this->ids !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'id IN (%Ld)',
|
|
|
|
|
$this->ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->phids !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
|
$this->phids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->repositoryPHIDs !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'repositoryPHID IN (%Ls)',
|
|
|
|
|
$this->repositoryPHIDs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->pullerPHIDs !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'pullerPHID in (%Ls)',
|
|
|
|
|
$this->pullerPHIDs);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 11:47:55 -08:00
|
|
|
if ($this->epochMin !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'epoch >= %d',
|
|
|
|
|
$this->epochMin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->epochMax !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'epoch <= %d',
|
|
|
|
|
$this->epochMax);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:21:38 -08:00
|
|
|
return $where;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getQueryApplicationClass() {
|
|
|
|
|
return 'PhabricatorDiffusionApplication';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|